pi-hashline-edit-pro 0.15.3 → 0.15.4
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 +1 -1
- package/src/replace-diff.ts +9 -19
- package/src/replace.ts +1 -1
package/package.json
CHANGED
package/src/replace-diff.ts
CHANGED
|
@@ -47,22 +47,16 @@ export function genDiff(
|
|
|
47
47
|
newContentHashes?: string[],
|
|
48
48
|
oldHashes?: string[],
|
|
49
49
|
): { diff: string; firstChangedLine: number | undefined } {
|
|
50
|
-
//
|
|
51
|
-
//
|
|
52
|
-
//
|
|
50
|
+
// Run Diff.diffLines on raw content only (no hash annotations) so that
|
|
51
|
+
// lines whose content is identical are never reported as changed even
|
|
52
|
+
// when their hash differs due to collision resolution or position
|
|
53
|
+
// tracking. Hashes are used purely for display via fmtDiffLine.
|
|
53
54
|
const oldLines = oldContent.split("\n");
|
|
54
|
-
const effectiveOldHashes = oldHashes ?? _lineHashesPure(oldContent);
|
|
55
|
-
const annotatedOld = oldLines
|
|
56
|
-
.map((line, i) => `${line}\0${effectiveOldHashes[i] ?? ""}`)
|
|
57
|
-
.join("\n");
|
|
58
|
-
|
|
59
55
|
const newLines = newContent.split("\n");
|
|
56
|
+
const effectiveOldHashes = oldHashes ?? _lineHashesPure(oldContent);
|
|
60
57
|
const effectiveNewHashes = newContentHashes ?? _lineHashesPure(newContent);
|
|
61
|
-
const annotatedNew = newLines
|
|
62
|
-
.map((line, i) => `${line}\0${effectiveNewHashes[i] ?? ""}`)
|
|
63
|
-
.join("\n");
|
|
64
58
|
|
|
65
|
-
const parts = Diff.diffLines(
|
|
59
|
+
const parts = Diff.diffLines(oldContent, newContent);
|
|
66
60
|
const output: string[] = [];
|
|
67
61
|
let oldLineNum = 1;
|
|
68
62
|
let newLineNum = 1;
|
|
@@ -73,11 +67,7 @@ export function genDiff(
|
|
|
73
67
|
const part = parts[i]!;
|
|
74
68
|
const raw = part.value.split("\n");
|
|
75
69
|
if (raw[raw.length - 1] === "") raw.pop();
|
|
76
|
-
|
|
77
|
-
const displayLines = raw.map((l) => {
|
|
78
|
-
const nullIdx = l.indexOf("\0");
|
|
79
|
-
return nullIdx >= 0 ? l.slice(0, nullIdx) : l;
|
|
80
|
-
});
|
|
70
|
+
const displayLines = raw;
|
|
81
71
|
|
|
82
72
|
if (part.added || part.removed) {
|
|
83
73
|
if (firstChangedLine === undefined) firstChangedLine = newLineNum;
|
|
@@ -116,13 +106,13 @@ export function genDiff(
|
|
|
116
106
|
}
|
|
117
107
|
|
|
118
108
|
if (skipStart > 0) {
|
|
119
|
-
output.push(
|
|
109
|
+
output.push(" ...");
|
|
120
110
|
oldLineNum += skipStart;
|
|
121
111
|
newLineNum += skipStart;
|
|
122
112
|
}
|
|
123
113
|
for (const line of linesToShow) {
|
|
124
114
|
if (line === "__ELLIPSIS__") {
|
|
125
|
-
output.push(
|
|
115
|
+
output.push(" ...");
|
|
126
116
|
oldLineNum += skipMiddle;
|
|
127
117
|
newLineNum += skipMiddle;
|
|
128
118
|
continue;
|
package/src/replace.ts
CHANGED
|
@@ -101,7 +101,7 @@ interface PipelineResult {
|
|
|
101
101
|
noopEdits?: { editIndex: number; loc: string; currentContent: string }[];
|
|
102
102
|
firstChangedLine?: number;
|
|
103
103
|
lastChangedLine?: number;
|
|
104
|
-
originalHashes
|
|
104
|
+
originalHashes: string[];
|
|
105
105
|
resultHashes: string[];
|
|
106
106
|
}
|
|
107
107
|
|