@xynogen/pix-pretty 1.7.6 → 1.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xynogen/pix-pretty",
3
- "version": "1.7.6",
3
+ "version": "1.7.7",
4
4
  "description": "Enhanced tool output rendering with syntax highlighting, file icons, tree views, FFF search, and paste chip formatting",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -0,0 +1,23 @@
1
+ import { describe, expect, it } from "bun:test";
2
+
3
+ import { parseDiff } from "./diff.js";
4
+
5
+ const OLD = "line1\nline2\nline3";
6
+ const NEW = "line1\nCHANGED\nline3";
7
+
8
+ describe("parseDiff baseLine", () => {
9
+ it("is snippet-relative when baseLine omitted (default 0)", () => {
10
+ const { lines } = parseDiff(OLD, NEW);
11
+ const del = lines.find((l) => l.type === "del");
12
+ expect(del?.oldNum).toBe(2); // line2 is the 2nd line of the snippet
13
+ });
14
+
15
+ it("shifts gutter numbers to absolute when baseLine given", () => {
16
+ // Snippet begins at file line 84 → snippet line 2 becomes file line 85.
17
+ const { lines } = parseDiff(OLD, NEW, 3, 84);
18
+ const del = lines.find((l) => l.type === "del");
19
+ const add = lines.find((l) => l.type === "add");
20
+ expect(del?.oldNum).toBe(85);
21
+ expect(add?.newNum).toBe(85);
22
+ });
23
+ });
package/src/diff.ts CHANGED
@@ -22,6 +22,9 @@ export function parseDiff(
22
22
  oldContent: string,
23
23
  newContent: string,
24
24
  ctx = 3,
25
+ // 1-based file line where the snippet begins; shifts gutter numbers from
26
+ // snippet-relative to absolute. 0 = no shift (snippet-relative, the default).
27
+ baseLine = 0,
25
28
  ): ParsedDiff {
26
29
  const patch = Diff.structuredPatch("", "", oldContent, newContent, "", "", {
27
30
  context: ctx,
@@ -42,8 +45,9 @@ export function parseDiff(
42
45
  });
43
46
  }
44
47
  const h = patch.hunks[hi];
45
- let oL = h.oldStart;
46
- let nL = h.newStart;
48
+ const shift = baseLine > 0 ? baseLine - 1 : 0;
49
+ let oL = h.oldStart + shift;
50
+ let nL = h.newStart + shift;
47
51
  for (const raw of h.lines) {
48
52
  if (raw === "\") continue;
49
53
  const ch = raw[0];