@pierre/diffs 1.3.3 → 1.3.5
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/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +74 -29
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +1 -1
- package/dist/editor/tokenizer.d.ts +1 -1
- package/dist/editor/tokenizer.d.ts.map +1 -1
- package/dist/editor/tokenizer.js +22 -5
- package/dist/editor/tokenizer.js.map +1 -1
- package/dist/editor/utils.d.ts +2 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +11 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/react/EditContext.d.ts.map +1 -1
- package/dist/react/EditContext.js +9 -2
- package/dist/react/EditContext.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +3 -2
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +36 -12
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/editSessionHunks.d.ts.map +1 -1
- package/dist/utils/editSessionHunks.js +2 -2
- package/dist/utils/editSessionHunks.js.map +1 -1
- package/package.json +2 -2
|
@@ -69,11 +69,18 @@ var DiffHunksRenderer = class {
|
|
|
69
69
|
* Enter edit-session mode: hunk updates preserve the current region
|
|
70
70
|
* skeleton instead of recomputing hunks, and rendering happens locally
|
|
71
71
|
* with the token transformer forced on (worker-pool requests/results are
|
|
72
|
-
* suspended for this renderer).
|
|
73
|
-
* a
|
|
72
|
+
* suspended for this renderer). An empty additions document gets one row so
|
|
73
|
+
* the editor has a line for its caret. Called on every editor attach,
|
|
74
|
+
* including a re-attach after recycle.
|
|
74
75
|
*/
|
|
75
76
|
beginEditSession() {
|
|
76
77
|
this.editSessionActive = true;
|
|
78
|
+
const diff = this.diffCache;
|
|
79
|
+
if (diff != null && !diff.isPartial && diff.additionLines.length === 0) {
|
|
80
|
+
Object.assign(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
81
|
+
this.markEditSessionPass(diff);
|
|
82
|
+
this.clearRenderCache();
|
|
83
|
+
}
|
|
77
84
|
}
|
|
78
85
|
/** Leave edit-session mode. The exit recompute is the host's concern. */
|
|
79
86
|
endEditSession() {
|
|
@@ -269,7 +276,7 @@ var DiffHunksRenderer = class {
|
|
|
269
276
|
result.code.additionLines = realignAdditionHastLines(previousAdditionLines, diff.additionLines, result.code.additionLines, textDocument);
|
|
270
277
|
if (diff.additionLines.length <= 1 && diff.additionLines.join("") === "") {
|
|
271
278
|
Object.assign(diff, recomputeEmptyDocumentDiff(diff, this.options.parseDiffOptions));
|
|
272
|
-
result.code.additionLines[0] = createPlainAdditionLineElement(0, textDocument);
|
|
279
|
+
result.code.additionLines[0] = createPlainAdditionLineElement(0, textDocument.getLineText(0));
|
|
273
280
|
this.markEditSessionPass(diff);
|
|
274
281
|
} else if (this.editSessionActive) this.applySessionDocumentChange(diff);
|
|
275
282
|
else Object.assign(diff, recomputeDiffHunksForEdit(diff, this.options.parseDiffOptions));
|
|
@@ -489,12 +496,29 @@ var DiffHunksRenderer = class {
|
|
|
489
496
|
renderDiffWithHighlighter(diff, highlighter, forcePlainText = false) {
|
|
490
497
|
const { options } = this.getRenderOptions(diff);
|
|
491
498
|
const { collapsedContextThreshold } = this.getOptionsWithDefaults();
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
499
|
+
const result = renderDiffWithHighlighter(diff, highlighter, options, {
|
|
500
|
+
forcePlainText,
|
|
501
|
+
expandedHunks: forcePlainText ? true : void 0,
|
|
502
|
+
collapsedContextThreshold
|
|
503
|
+
});
|
|
504
|
+
if (this.editSessionActive && diff.additionLines.length === 1 && diff.additionLines[0] === "" && result.code.additionLines[0] == null) {
|
|
505
|
+
let fallbackLine;
|
|
506
|
+
iterateOverDiff({
|
|
507
|
+
diff,
|
|
508
|
+
diffStyle: "both",
|
|
495
509
|
expandedHunks: forcePlainText ? true : void 0,
|
|
496
|
-
collapsedContextThreshold
|
|
497
|
-
|
|
510
|
+
collapsedContextThreshold,
|
|
511
|
+
callback: ({ additionLine }) => {
|
|
512
|
+
if (additionLine?.lineIndex !== 0) return;
|
|
513
|
+
fallbackLine = additionLine;
|
|
514
|
+
return true;
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
if (fallbackLine == null) throw new Error("DiffHunksRenderer: missing empty addition line");
|
|
518
|
+
result.code.additionLines[0] = createPlainAdditionLineElement(0, "", fallbackLine.unifiedLineIndex, fallbackLine.splitLineIndex);
|
|
519
|
+
}
|
|
520
|
+
return {
|
|
521
|
+
result,
|
|
498
522
|
options
|
|
499
523
|
};
|
|
500
524
|
}
|
|
@@ -1120,16 +1144,16 @@ function realignAdditionHastLines(previousLines, nextLines, hastLines, textDocum
|
|
|
1120
1144
|
for (let offset = 0; offset < suffix; offset++) realigned[nextContentLength - 1 - offset] = hastLines[previousContentLength - 1 - offset];
|
|
1121
1145
|
if (previousContentLength < previousLines.length && nextContentLength < nextLines.length) realigned[nextLines.length - 1] = hastLines[previousLines.length - 1];
|
|
1122
1146
|
for (let index = previousLines.length; index < nextLines.length; index++) realigned[index] ??= hastLines[index];
|
|
1123
|
-
for (let index = prefix; index < nextLines.length; index++) realigned[index] ??= createPlainAdditionLineElement(index, textDocument);
|
|
1147
|
+
for (let index = prefix; index < nextLines.length; index++) realigned[index] ??= createPlainAdditionLineElement(index, textDocument.getLineText(index));
|
|
1124
1148
|
return realigned;
|
|
1125
1149
|
}
|
|
1126
|
-
function createPlainAdditionLineElement(lineIndex,
|
|
1150
|
+
function createPlainAdditionLineElement(lineIndex, lineText, unifiedLineIndex = lineIndex, splitLineIndex = lineIndex) {
|
|
1127
1151
|
return {
|
|
1128
1152
|
type: "element",
|
|
1129
1153
|
tagName: "div",
|
|
1130
1154
|
properties: {
|
|
1131
1155
|
"data-line": lineIndex + 1,
|
|
1132
|
-
"data-line-index": `${
|
|
1156
|
+
"data-line-index": `${unifiedLineIndex},${splitLineIndex}`,
|
|
1133
1157
|
"data-line-type": "context"
|
|
1134
1158
|
},
|
|
1135
1159
|
children: [{
|
|
@@ -1138,7 +1162,7 @@ function createPlainAdditionLineElement(lineIndex, textDocument) {
|
|
|
1138
1162
|
properties: { "data-char": 0 },
|
|
1139
1163
|
children: [{
|
|
1140
1164
|
type: "text",
|
|
1141
|
-
value:
|
|
1165
|
+
value: lineText
|
|
1142
1166
|
}]
|
|
1143
1167
|
}]
|
|
1144
1168
|
};
|