pi-hashline-edit-pro 0.9.0 → 0.9.1
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 +15 -7
package/package.json
CHANGED
package/src/replace-diff.ts
CHANGED
|
@@ -85,12 +85,19 @@ export function generateDiffString(
|
|
|
85
85
|
let linesToShow = raw;
|
|
86
86
|
let skipStart = 0;
|
|
87
87
|
let skipEnd = 0;
|
|
88
|
+
let skipMiddle = 0; // lines skipped between head and tail context
|
|
88
89
|
|
|
89
90
|
if (!lastWasChange) {
|
|
91
|
+
// Before a change: show last contextLines only.
|
|
90
92
|
skipStart = Math.max(0, raw.length - contextLines);
|
|
91
93
|
linesToShow = raw.slice(skipStart);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
+
} else if (nextPartIsChange && raw.length > contextLines * 2) {
|
|
95
|
+
// Between two changes: show first contextLines + last contextLines with ellipsis in between.
|
|
96
|
+
const tail = raw.slice(-contextLines);
|
|
97
|
+
linesToShow = [...raw.slice(0, contextLines), "__ELLIPSIS__", ...tail];
|
|
98
|
+
skipMiddle = raw.length - contextLines * 2;
|
|
99
|
+
} else if (linesToShow.length > contextLines) {
|
|
100
|
+
// After a change with no next change nearby: show first contextLines only.
|
|
94
101
|
skipEnd = linesToShow.length - contextLines;
|
|
95
102
|
linesToShow = linesToShow.slice(0, contextLines);
|
|
96
103
|
}
|
|
@@ -101,17 +108,18 @@ export function generateDiffString(
|
|
|
101
108
|
newLineNum += skipStart;
|
|
102
109
|
}
|
|
103
110
|
for (const line of linesToShow) {
|
|
111
|
+
if (line === "__ELLIPSIS__") {
|
|
112
|
+
output.push(` ...`);
|
|
113
|
+
oldLineNum += skipMiddle;
|
|
114
|
+
newLineNum += skipMiddle;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
104
117
|
const hash = effectiveNewHashes[newLineNum - 1];
|
|
105
118
|
output.push(formatDiffPreviewLine(" ", line, hash));
|
|
106
119
|
|
|
107
120
|
oldLineNum++;
|
|
108
121
|
newLineNum++;
|
|
109
122
|
}
|
|
110
|
-
if (skipEnd > 0) {
|
|
111
|
-
output.push(` ...`);
|
|
112
|
-
oldLineNum += skipEnd;
|
|
113
|
-
newLineNum += skipEnd;
|
|
114
|
-
}
|
|
115
123
|
} else {
|
|
116
124
|
oldLineNum += raw.length;
|
|
117
125
|
newLineNum += raw.length;
|