@pierre/diffs 1.3.0-beta.2 → 1.3.0-beta.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/dist/components/CodeView.d.ts +4 -0
- package/dist/components/CodeView.d.ts.map +1 -1
- package/dist/components/CodeView.js +38 -0
- package/dist/components/CodeView.js.map +1 -1
- package/dist/components/File.d.ts +2 -2
- package/dist/components/File.d.ts.map +1 -1
- package/dist/components/File.js +13 -13
- package/dist/components/File.js.map +1 -1
- package/dist/components/FileDiff.d.ts +7 -4
- package/dist/components/FileDiff.d.ts.map +1 -1
- package/dist/components/FileDiff.js +57 -47
- package/dist/components/FileDiff.js.map +1 -1
- package/dist/components/UnresolvedFile.d.ts.map +1 -1
- package/dist/components/UnresolvedFile.js +1 -1
- package/dist/components/VirtualizedFile.d.ts +1 -1
- package/dist/components/VirtualizedFile.d.ts.map +1 -1
- package/dist/components/VirtualizedFile.js +13 -4
- package/dist/components/VirtualizedFile.js.map +1 -1
- package/dist/components/VirtualizedFileDiff.d.ts +2 -1
- package/dist/components/VirtualizedFileDiff.d.ts.map +1 -1
- package/dist/components/VirtualizedFileDiff.js +36 -42
- package/dist/components/VirtualizedFileDiff.js.map +1 -1
- package/dist/components/Virtualizer.js +5 -3
- package/dist/components/Virtualizer.js.map +1 -1
- package/dist/components/VirtulizerDevelopment.d.ts.map +1 -1
- package/dist/editor/editStack.d.ts +1 -1
- package/dist/editor/editor.d.ts +14 -6
- package/dist/editor/editor.d.ts.map +1 -1
- package/dist/editor/editor.js +745 -553
- package/dist/editor/editor.js.map +1 -1
- package/dist/editor/editor2.js +6 -0
- package/dist/editor/editor2.js.map +1 -0
- package/dist/editor/lineAnnotations.d.ts +2 -1
- package/dist/editor/lineAnnotations.d.ts.map +1 -1
- package/dist/editor/lineAnnotations.js +111 -1
- package/dist/editor/lineAnnotations.js.map +1 -1
- package/dist/editor/marker.d.ts +33 -0
- package/dist/editor/marker.d.ts.map +1 -0
- package/dist/editor/marker.js +185 -0
- package/dist/editor/marker.js.map +1 -0
- package/dist/editor/pieceTable.d.ts +3 -3
- package/dist/editor/pieceTable.d.ts.map +1 -1
- package/dist/editor/pieceTable.js +44 -33
- package/dist/editor/pieceTable.js.map +1 -1
- package/dist/editor/searchPanel.d.ts +6 -7
- package/dist/editor/searchPanel.d.ts.map +1 -1
- package/dist/editor/searchPanel.js +103 -138
- package/dist/editor/searchPanel.js.map +1 -1
- package/dist/editor/selection.d.ts +19 -3
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/selection.js +196 -39
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/{quickEdit.d.ts → selectionAction.d.ts} +8 -8
- package/dist/editor/selectionAction.d.ts.map +1 -0
- package/dist/editor/{quickEdit.js → selectionAction.js} +19 -21
- package/dist/editor/selectionAction.js.map +1 -0
- package/dist/editor/sprite.d.ts +8 -0
- package/dist/editor/sprite.d.ts.map +1 -0
- package/dist/editor/sprite.js +45 -0
- package/dist/editor/sprite.js.map +1 -0
- package/dist/editor/textDocument.d.ts +5 -5
- package/dist/editor/textDocument.d.ts.map +1 -1
- package/dist/editor/textDocument.js +9 -9
- package/dist/editor/textDocument.js.map +1 -1
- package/dist/editor/textMeasure.js +3 -3
- package/dist/editor/textMeasure.js.map +1 -1
- package/dist/editor/tokenzier.d.ts +6 -2
- package/dist/editor/tokenzier.d.ts.map +1 -1
- package/dist/editor/tokenzier.js +135 -85
- package/dist/editor/tokenzier.js.map +1 -1
- package/dist/editor/utils.d.ts +3 -1
- package/dist/editor/utils.d.ts.map +1 -1
- package/dist/editor/utils.js +16 -1
- package/dist/editor/utils.js.map +1 -1
- package/dist/highlighter/shared_highlighter.js +3 -29
- package/dist/highlighter/shared_highlighter.js.map +1 -1
- package/dist/highlighter/themes/attachResolvedThemes.js +4 -3
- package/dist/highlighter/themes/attachResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/cleanUpResolvedThemes.js +3 -2
- package/dist/highlighter/themes/cleanUpResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/constants.d.ts +1 -7
- package/dist/highlighter/themes/constants.d.ts.map +1 -1
- package/dist/highlighter/themes/constants.js +1 -4
- package/dist/highlighter/themes/constants.js.map +1 -1
- package/dist/highlighter/themes/getResolvedOrResolveTheme.js +2 -2
- package/dist/highlighter/themes/getResolvedOrResolveTheme.js.map +1 -1
- package/dist/highlighter/themes/getResolvedThemes.js +2 -8
- package/dist/highlighter/themes/getResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/hasResolvedThemes.js +2 -3
- package/dist/highlighter/themes/hasResolvedThemes.js.map +1 -1
- package/dist/highlighter/themes/registerCustomCSSVariableTheme.js +1 -1
- package/dist/highlighter/themes/registerCustomTheme.d.ts +5 -3
- package/dist/highlighter/themes/registerCustomTheme.d.ts.map +1 -1
- package/dist/highlighter/themes/registerCustomTheme.js +15 -5
- package/dist/highlighter/themes/registerCustomTheme.js.map +1 -1
- package/dist/highlighter/themes/resolveTheme.js +6 -27
- package/dist/highlighter/themes/resolveTheme.js.map +1 -1
- package/dist/highlighter/themes/resolveThemes.js +5 -12
- package/dist/highlighter/themes/resolveThemes.js.map +1 -1
- package/dist/highlighter/themes/themeResolution.d.ts +8 -0
- package/dist/highlighter/themes/themeResolution.d.ts.map +1 -0
- package/dist/highlighter/themes/themeResolution.js +22 -0
- package/dist/highlighter/themes/themeResolution.js.map +1 -0
- package/dist/highlighter/themes/themeResolver.d.ts +8 -0
- package/dist/highlighter/themes/themeResolver.d.ts.map +1 -0
- package/dist/highlighter/themes/themeResolver.js +8 -0
- package/dist/highlighter/themes/themeResolver.js.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/react/index.d.ts +2 -2
- package/dist/react/jsx.d.ts.map +1 -1
- package/dist/react/utils/useFileDiffInstance.js +1 -0
- package/dist/react/utils/useFileDiffInstance.js.map +1 -1
- package/dist/renderers/DiffHunksRenderer.d.ts +4 -1
- package/dist/renderers/DiffHunksRenderer.d.ts.map +1 -1
- package/dist/renderers/DiffHunksRenderer.js +139 -19
- package/dist/renderers/DiffHunksRenderer.js.map +1 -1
- package/dist/renderers/FileRenderer.d.ts +2 -2
- package/dist/renderers/FileRenderer.d.ts.map +1 -1
- package/dist/renderers/FileRenderer.js +5 -5
- package/dist/renderers/FileRenderer.js.map +1 -1
- package/dist/ssr/index.d.ts +2 -2
- package/dist/style.js +1 -1
- package/dist/style.js.map +1 -1
- package/dist/types.d.ts +19 -16
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/computeEstimatedDiffHeights.js +9 -20
- package/dist/utils/computeEstimatedDiffHeights.js.map +1 -1
- package/dist/utils/getHighlighterThemeStyles.js +16 -12
- package/dist/utils/getHighlighterThemeStyles.js.map +1 -1
- package/dist/utils/iterateOverDiff.js +147 -182
- package/dist/utils/iterateOverDiff.js.map +1 -1
- package/dist/utils/parsePatchFiles.js +93 -4
- package/dist/utils/parsePatchFiles.js.map +1 -1
- package/dist/utils/updateDiffHunks.d.ts +13 -0
- package/dist/utils/updateDiffHunks.d.ts.map +1 -0
- package/dist/utils/updateDiffHunks.js +171 -0
- package/dist/utils/updateDiffHunks.js.map +1 -0
- package/dist/utils/virtualDiffLayout.d.ts +24 -2
- package/dist/utils/virtualDiffLayout.d.ts.map +1 -1
- package/dist/utils/virtualDiffLayout.js +49 -1
- package/dist/utils/virtualDiffLayout.js.map +1 -1
- package/dist/worker/WorkerPoolManager.js +1 -1
- package/dist/worker/WorkerPoolManager.js.map +1 -1
- package/dist/worker/{wasm-D4DU5jgR.js → wasm-BaDzIkIn.js} +2 -2
- package/dist/worker/wasm-BaDzIkIn.js.map +1 -0
- package/dist/worker/worker-portable.js +1021 -314
- package/dist/worker/worker-portable.js.map +1 -1
- package/dist/worker/worker.js +202 -196
- package/dist/worker/worker.js.map +1 -1
- package/package.json +4 -2
- package/dist/editor/css.d.ts +0 -6
- package/dist/editor/css.d.ts.map +0 -1
- package/dist/editor/css.js +0 -218
- package/dist/editor/css.js.map +0 -1
- package/dist/editor/quickEdit.d.ts.map +0 -1
- package/dist/editor/quickEdit.js.map +0 -1
- package/dist/worker/wasm-D4DU5jgR.js.map +0 -1
package/dist/editor/selection.js
CHANGED
|
@@ -84,24 +84,28 @@ function mapCursorMove(textDocument, selections, shortcut) {
|
|
|
84
84
|
if (shortcut === "textStart") {
|
|
85
85
|
const indent = getLeadingSpaces(textDocument.getLineText(line));
|
|
86
86
|
character = character === indent ? 0 : indent;
|
|
87
|
-
} else character = shortcut === "start" ? 0 : textDocument.
|
|
87
|
+
} else character = shortcut === "start" ? 0 : textDocument.getLineLength(line);
|
|
88
88
|
if (selection.direction === DirectionBackward) line = selection.start.line;
|
|
89
89
|
else line = selection.end.line;
|
|
90
90
|
} else if (shortcut === "up") line = Math.max(0, line - 1);
|
|
91
91
|
else if (shortcut === "down") line = Math.min(Math.max(lineCount - 1, 0), line + 1);
|
|
92
|
-
else if (isCollapsedSelection(selection))
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
character
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
else {
|
|
103
|
-
|
|
104
|
-
character
|
|
92
|
+
else if (isCollapsedSelection(selection)) {
|
|
93
|
+
const lineLength = textDocument.getLineLength(line);
|
|
94
|
+
character = Math.min(character, lineLength);
|
|
95
|
+
if (shortcut === "left") {
|
|
96
|
+
character--;
|
|
97
|
+
if (character < 0) if (line === 0) character = 0;
|
|
98
|
+
else {
|
|
99
|
+
line = Math.max(0, line - 1);
|
|
100
|
+
character = textDocument.getLineLength(line);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
character++;
|
|
104
|
+
if (character > lineLength) if (line === lineCount - 1) character--;
|
|
105
|
+
else {
|
|
106
|
+
line = Math.min(Math.max(lineCount - 1, 0), line + 1);
|
|
107
|
+
character = 0;
|
|
108
|
+
}
|
|
105
109
|
}
|
|
106
110
|
}
|
|
107
111
|
const pos = {
|
|
@@ -137,7 +141,7 @@ function applyTextChangeToSelections(textDocument, selections, edit, lineAnnotat
|
|
|
137
141
|
if (selections[selections.length - 1] === void 0) return { nextSelections: [] };
|
|
138
142
|
const selectionPositions = [];
|
|
139
143
|
for (const selection of selections) selectionPositions.push(selection.start, selection.end);
|
|
140
|
-
const selectionOffsets = textDocument.
|
|
144
|
+
const selectionOffsets = selectionPositions.map((position) => textDocument.offsetAt(position));
|
|
141
145
|
const primaryStartOffset = selectionOffsets[(selections.length - 1) * 2];
|
|
142
146
|
const primaryEndOffset = selectionOffsets[(selections.length - 1) * 2 + 1];
|
|
143
147
|
const ordered = [];
|
|
@@ -220,7 +224,7 @@ function applyTextReplaceToSelections(textDocument, selections, texts, lineAnnot
|
|
|
220
224
|
if (selections.length !== texts.length) throw new Error("Selection text replacements must match the selection count");
|
|
221
225
|
const selectionPositions = [];
|
|
222
226
|
for (const selection of selections) selectionPositions.push(selection.start, selection.end);
|
|
223
|
-
const selectionOffsets = textDocument.
|
|
227
|
+
const selectionOffsets = selectionPositions.map((position) => textDocument.offsetAt(position));
|
|
224
228
|
const ordered = [];
|
|
225
229
|
let isAlreadyOrdered = true;
|
|
226
230
|
for (let index = 0; index < selections.length; index++) {
|
|
@@ -241,21 +245,61 @@ function applyTextReplaceToSelections(textDocument, selections, texts, lineAnnot
|
|
|
241
245
|
if (endOrder !== 0) return endOrder;
|
|
242
246
|
return a.index - b.index;
|
|
243
247
|
});
|
|
244
|
-
const
|
|
248
|
+
const allDeletes = texts.every((text) => text === "");
|
|
249
|
+
let edits;
|
|
245
250
|
const nextSelectionOffsets = Array.from({ length: selections.length });
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
251
|
+
if (allDeletes) {
|
|
252
|
+
edits = [];
|
|
253
|
+
let hasEffect = false;
|
|
254
|
+
for (const entry of ordered) {
|
|
255
|
+
nextSelectionOffsets[entry.index] = entry.end;
|
|
256
|
+
if (entry.start >= entry.end) continue;
|
|
257
|
+
hasEffect = true;
|
|
258
|
+
const last = edits[edits.length - 1];
|
|
259
|
+
if (last !== void 0 && entry.start < last.end) edits[edits.length - 1] = {
|
|
260
|
+
start: last.start,
|
|
261
|
+
end: Math.max(last.end, entry.end),
|
|
262
|
+
text: ""
|
|
263
|
+
};
|
|
264
|
+
else edits.push({
|
|
265
|
+
start: entry.start,
|
|
266
|
+
end: entry.end,
|
|
267
|
+
text: ""
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
if (!hasEffect) return { nextSelections: selections };
|
|
271
|
+
for (const entry of ordered) {
|
|
272
|
+
const caret = entry.end;
|
|
273
|
+
let delta = 0;
|
|
274
|
+
let next = caret;
|
|
275
|
+
for (const edit of edits) {
|
|
276
|
+
if (caret <= edit.start) break;
|
|
277
|
+
if (caret >= edit.end) {
|
|
278
|
+
delta -= edit.end - edit.start;
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
next = edit.start + delta;
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
if (next === caret) next += delta;
|
|
285
|
+
nextSelectionOffsets[entry.index] = next;
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
edits = [];
|
|
289
|
+
let offsetDelta = 0;
|
|
290
|
+
let previousEditEnd = -1;
|
|
291
|
+
for (const entry of ordered) {
|
|
292
|
+
if (entry.start < previousEditEnd) throw new Error("Overlapping multi-selection edits are not supported");
|
|
293
|
+
previousEditEnd = entry.end;
|
|
294
|
+
const newText = expandSingleNewlineInsert(textDocument, entry.text, entry.start);
|
|
295
|
+
edits.push({
|
|
296
|
+
start: entry.start,
|
|
297
|
+
end: entry.end,
|
|
298
|
+
text: newText
|
|
299
|
+
});
|
|
300
|
+
nextSelectionOffsets[entry.index] = entry.start + offsetDelta + newText.length;
|
|
301
|
+
offsetDelta += newText.length - (entry.end - entry.start);
|
|
302
|
+
}
|
|
259
303
|
}
|
|
260
304
|
const change = textDocument.applyResolvedEdits(edits, true, selections);
|
|
261
305
|
const nextSelections = createSelectionsFromOffsetPairs(textDocument, nextSelectionOffsets.map((offset) => [offset, offset]));
|
|
@@ -285,7 +329,7 @@ function applyTransposeToSelections(textDocument, selections, lineAnnotations) {
|
|
|
285
329
|
}
|
|
286
330
|
const { line, character } = selection.start;
|
|
287
331
|
const offset = anchor;
|
|
288
|
-
const lineLength = textDocument.
|
|
332
|
+
const lineLength = textDocument.getLineLength(line);
|
|
289
333
|
let edit;
|
|
290
334
|
if (character > 0 && character < lineLength) {
|
|
291
335
|
edit = {
|
|
@@ -303,7 +347,7 @@ function applyTransposeToSelections(textDocument, selections, lineAnnotations) {
|
|
|
303
347
|
nextOffsetPairs.push([offset, offset]);
|
|
304
348
|
} else if (character === 0 && line > 0 && lineLength > 0) {
|
|
305
349
|
const prevLine = line - 1;
|
|
306
|
-
const prevLength = textDocument.
|
|
350
|
+
const prevLength = textDocument.getLineLength(prevLine);
|
|
307
351
|
const prevEnd = textDocument.offsetAt({
|
|
308
352
|
line: prevLine,
|
|
309
353
|
character: prevLength
|
|
@@ -350,7 +394,66 @@ function applyDeleteHardLineForwardToSelections(textDocument, selections, lineAn
|
|
|
350
394
|
direction: DirectionNone
|
|
351
395
|
};
|
|
352
396
|
});
|
|
353
|
-
|
|
397
|
+
return applyTextReplaceToSelections(textDocument, deleteSelections, deleteSelections.map(() => ""), lineAnnotations);
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Deletes from each selection back to the start of its soft (visual) line.
|
|
401
|
+
* Non-collapsed selections delete their selected text instead.
|
|
402
|
+
*/
|
|
403
|
+
function applyDeleteSoftLineBackwardToSelections(textDocument, selections, getSoftLineStart, lineAnnotations) {
|
|
404
|
+
const deleteSelections = selections.map((selection) => {
|
|
405
|
+
if (!isCollapsedSelection(selection)) return {
|
|
406
|
+
start: selection.start,
|
|
407
|
+
end: selection.end,
|
|
408
|
+
direction: DirectionNone
|
|
409
|
+
};
|
|
410
|
+
const caret = getCaretPosition(selection);
|
|
411
|
+
const { line, character } = caret;
|
|
412
|
+
const softLineStart = getSoftLineStart?.(line, character) ?? 0;
|
|
413
|
+
if (character > softLineStart) return {
|
|
414
|
+
start: {
|
|
415
|
+
line,
|
|
416
|
+
character: softLineStart
|
|
417
|
+
},
|
|
418
|
+
end: {
|
|
419
|
+
line,
|
|
420
|
+
character
|
|
421
|
+
},
|
|
422
|
+
direction: DirectionNone
|
|
423
|
+
};
|
|
424
|
+
if (line === 0) return {
|
|
425
|
+
start: caret,
|
|
426
|
+
end: caret,
|
|
427
|
+
direction: DirectionNone
|
|
428
|
+
};
|
|
429
|
+
const prevLineLength = textDocument.getLineLength(line - 1);
|
|
430
|
+
return {
|
|
431
|
+
start: {
|
|
432
|
+
line: line - 1,
|
|
433
|
+
character: prevLineLength
|
|
434
|
+
},
|
|
435
|
+
end: {
|
|
436
|
+
line,
|
|
437
|
+
character: 0
|
|
438
|
+
},
|
|
439
|
+
direction: DirectionNone
|
|
440
|
+
};
|
|
441
|
+
});
|
|
442
|
+
return applyTextReplaceToSelections(textDocument, deleteSelections, deleteSelections.map(() => ""), lineAnnotations);
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Deletes the word or separator group immediately before each selection.
|
|
446
|
+
* Non-collapsed selections delete their selected text instead.
|
|
447
|
+
*/
|
|
448
|
+
function applyDeleteWordBackwardToSelections(textDocument, selections, lineAnnotations) {
|
|
449
|
+
const deleteSelections = selections.map((selection) => {
|
|
450
|
+
const [start, end] = resolveDeleteWordBackwardRange(textDocument, selection);
|
|
451
|
+
return {
|
|
452
|
+
start,
|
|
453
|
+
end,
|
|
454
|
+
direction: DirectionNone
|
|
455
|
+
};
|
|
456
|
+
});
|
|
354
457
|
return applyTextReplaceToSelections(textDocument, deleteSelections, deleteSelections.map(() => ""), lineAnnotations);
|
|
355
458
|
}
|
|
356
459
|
/**
|
|
@@ -370,7 +473,7 @@ function getCaretPosition(selection) {
|
|
|
370
473
|
* Checks if a line is editable.
|
|
371
474
|
*/
|
|
372
475
|
function isLineEditable(lineType) {
|
|
373
|
-
return lineType === "context" || lineType === "
|
|
476
|
+
return lineType === "context" || lineType === "context-expanded" || lineType === "change-addition";
|
|
374
477
|
}
|
|
375
478
|
/**
|
|
376
479
|
* Checks whether selections `a` and `b` intersect.
|
|
@@ -517,7 +620,7 @@ function getDocumentFullSelection(textDocument) {
|
|
|
517
620
|
},
|
|
518
621
|
end: {
|
|
519
622
|
line: lastLine,
|
|
520
|
-
character: textDocument.
|
|
623
|
+
character: textDocument.getLineLength(lastLine)
|
|
521
624
|
},
|
|
522
625
|
direction: DirectionForward
|
|
523
626
|
};
|
|
@@ -529,7 +632,7 @@ function getDocumentBoundarySelection(textDocument, atEnd) {
|
|
|
529
632
|
const line = atEnd ? textDocument.lineCount - 1 : 0;
|
|
530
633
|
const start = {
|
|
531
634
|
line,
|
|
532
|
-
character: atEnd ? textDocument.
|
|
635
|
+
character: atEnd ? textDocument.getLineLength(line) : 0
|
|
533
636
|
};
|
|
534
637
|
return {
|
|
535
638
|
start,
|
|
@@ -615,6 +718,54 @@ function expandCollapsedLineWord(lineText, character) {
|
|
|
615
718
|
};
|
|
616
719
|
}
|
|
617
720
|
}
|
|
721
|
+
function resolveDeleteWordBackwardRange(textDocument, selection) {
|
|
722
|
+
if (!isCollapsedSelection(selection)) return [selection.start, selection.end];
|
|
723
|
+
const caret = getCaretPosition(selection);
|
|
724
|
+
const { line, character: head } = caret;
|
|
725
|
+
if (head === 0) {
|
|
726
|
+
if (line === 0) return [caret, caret];
|
|
727
|
+
const prevLineLength = textDocument.getLineLength(line - 1);
|
|
728
|
+
return [{
|
|
729
|
+
line: line - 1,
|
|
730
|
+
character: prevLineLength
|
|
731
|
+
}, {
|
|
732
|
+
line,
|
|
733
|
+
character: 0
|
|
734
|
+
}];
|
|
735
|
+
}
|
|
736
|
+
const lineText = textDocument.getLineText(line);
|
|
737
|
+
const graphemeStarts = [0];
|
|
738
|
+
const segmenter = new Intl.Segmenter(void 0, { granularity: "grapheme" });
|
|
739
|
+
for (const segment of segmenter.segment(lineText)) if (segment.index > 0) graphemeStarts.push(segment.index);
|
|
740
|
+
let pos = head;
|
|
741
|
+
let match;
|
|
742
|
+
while (pos > 0) {
|
|
743
|
+
const prev = findClusterBreak(lineText, pos, false, graphemeStarts);
|
|
744
|
+
const nextChar = lineText.slice(prev, pos);
|
|
745
|
+
const nextMatch = !/\S/.test(nextChar) ? 0 : /\p{Alphabetic}|\p{Number}|_/u.test(nextChar) ? 1 : 2;
|
|
746
|
+
if (match !== void 0 && nextMatch !== match) break;
|
|
747
|
+
if (nextChar !== " " || pos !== head) match = nextMatch;
|
|
748
|
+
pos = prev;
|
|
749
|
+
}
|
|
750
|
+
return [{
|
|
751
|
+
line,
|
|
752
|
+
character: pos
|
|
753
|
+
}, {
|
|
754
|
+
line,
|
|
755
|
+
character: head
|
|
756
|
+
}];
|
|
757
|
+
}
|
|
758
|
+
function findClusterBreak(text, pos, forward, graphemeStarts) {
|
|
759
|
+
if (forward) {
|
|
760
|
+
for (const start of graphemeStarts) if (start > pos) return start;
|
|
761
|
+
return text.length;
|
|
762
|
+
}
|
|
763
|
+
for (let i = graphemeStarts.length - 1; i >= 0; i--) {
|
|
764
|
+
const start = graphemeStarts[i];
|
|
765
|
+
if (start < pos) return start;
|
|
766
|
+
}
|
|
767
|
+
return 0;
|
|
768
|
+
}
|
|
618
769
|
function getSelectionAnchorAndFocusOffsets(textDocument, selection) {
|
|
619
770
|
const isBackward = selection.direction === DirectionBackward;
|
|
620
771
|
return [textDocument.offsetAt(isBackward ? selection.end : selection.start), textDocument.offsetAt(getCaretPosition(selection))];
|
|
@@ -883,11 +1034,17 @@ function getLineChildEnd(child, textOffsetInChild) {
|
|
|
883
1034
|
}
|
|
884
1035
|
function getLineIndex(el) {
|
|
885
1036
|
const { line } = el.dataset;
|
|
886
|
-
if (line !== void 0)
|
|
1037
|
+
if (line !== void 0) {
|
|
1038
|
+
const lineNumber = parseInt(line, 10);
|
|
1039
|
+
if (!Number.isNaN(lineNumber)) return lineNumber - 1;
|
|
1040
|
+
}
|
|
887
1041
|
}
|
|
888
1042
|
function getCharacterIndex(el) {
|
|
889
1043
|
const { char } = el.dataset;
|
|
890
|
-
|
|
1044
|
+
if (char !== void 0) {
|
|
1045
|
+
const charIndex = parseInt(char, 10);
|
|
1046
|
+
if (!Number.isNaN(charIndex)) return charIndex;
|
|
1047
|
+
}
|
|
891
1048
|
}
|
|
892
1049
|
function getTextOffset(text, offset) {
|
|
893
1050
|
const value = text ?? "";
|
|
@@ -896,5 +1053,5 @@ function getTextOffset(text, offset) {
|
|
|
896
1053
|
}
|
|
897
1054
|
|
|
898
1055
|
//#endregion
|
|
899
|
-
export { DirectionBackward, DirectionForward, DirectionNone, applyDeleteHardLineForwardToSelections, applyTextChangeToSelections, applyTextReplaceToSelections, applyTransposeToSelections, comparePosition, convertSelection, createSelectionFrom, createSelectionFromAnchorAndFocusOffsets, expandCollapsedSelectionToWord, extendSelection, extendSelections, findNexMatch, getCaretPosition, getDocumentBoundarySelection, getDocumentFullSelection, getSelectionAnchor, getSelectionText, isCollapsedSelection, isLineEditable, mapCursorMove, mapSelectionShift, mergeOverlappingSelections, resolveIndentEdits, selectionIntersects };
|
|
1056
|
+
export { DirectionBackward, DirectionForward, DirectionNone, applyDeleteHardLineForwardToSelections, applyDeleteSoftLineBackwardToSelections, applyDeleteWordBackwardToSelections, applyTextChangeToSelections, applyTextReplaceToSelections, applyTransposeToSelections, comparePosition, convertSelection, createSelectionFrom, createSelectionFromAnchorAndFocusOffsets, expandCollapsedSelectionToWord, extendSelection, extendSelections, findNexMatch, getCaretPosition, getDocumentBoundarySelection, getDocumentFullSelection, getSelectionAnchor, getSelectionText, isCollapsedSelection, isLineEditable, mapCursorMove, mapSelectionShift, mergeOverlappingSelections, resolveIndentEdits, selectionIntersects };
|
|
900
1057
|
//# sourceMappingURL=selection.js.map
|