@lvce-editor/editor-worker 19.67.1 → 19.67.2
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/editorWorkerMain.js +33 -3
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -12776,9 +12776,39 @@ const getMatchingClosingBrace = brace => {
|
|
|
12776
12776
|
};
|
|
12777
12777
|
const typeWithAutoClosingBracket = (editor, text) => {
|
|
12778
12778
|
const closingBracket = getMatchingClosingBrace(text);
|
|
12779
|
-
const
|
|
12780
|
-
const
|
|
12781
|
-
|
|
12779
|
+
const changes = editorReplaceSelections(editor, [text + closingBracket], EditorTypeWithAutoClosing);
|
|
12780
|
+
const selectionChanges = new Uint32Array(editor.selections.length);
|
|
12781
|
+
let lineDelta = 0;
|
|
12782
|
+
for (let i = 0; i < changes.length; i++) {
|
|
12783
|
+
const selectionIndex = i * 4;
|
|
12784
|
+
const change = changes[i];
|
|
12785
|
+
const isEmptySelection = change.start.rowIndex === change.end.rowIndex && change.start.columnIndex === change.end.columnIndex;
|
|
12786
|
+
const selection = editor.selections.subarray(selectionIndex, selectionIndex + 4);
|
|
12787
|
+
const isReversedSelection = selection[0] > selection[2] || selection[0] === selection[2] && selection[1] > selection[3];
|
|
12788
|
+
if (isEmptySelection) {
|
|
12789
|
+
selectionChanges[selectionIndex] = change.start.rowIndex + lineDelta;
|
|
12790
|
+
selectionChanges[selectionIndex + 1] = change.start.columnIndex + 1;
|
|
12791
|
+
selectionChanges[selectionIndex + 2] = change.start.rowIndex + lineDelta;
|
|
12792
|
+
selectionChanges[selectionIndex + 3] = change.start.columnIndex + 1;
|
|
12793
|
+
} else {
|
|
12794
|
+
change.inserted = change.deleted.length === 1 ? [text + change.deleted[0] + closingBracket] : [text + change.deleted[0], ...change.deleted.slice(1, -1), change.deleted.at(-1) + closingBracket];
|
|
12795
|
+
const start = {
|
|
12796
|
+
columnIndex: change.start.columnIndex + 1,
|
|
12797
|
+
rowIndex: change.start.rowIndex + lineDelta
|
|
12798
|
+
};
|
|
12799
|
+
const end = {
|
|
12800
|
+
columnIndex: (change.inserted.length === 1 ? change.start.columnIndex + change.inserted[0].length : change.inserted.at(-1).length) - 1,
|
|
12801
|
+
rowIndex: start.rowIndex + change.inserted.length - 1
|
|
12802
|
+
};
|
|
12803
|
+
const anchor = isReversedSelection ? end : start;
|
|
12804
|
+
const active = isReversedSelection ? start : end;
|
|
12805
|
+
selectionChanges[selectionIndex] = anchor.rowIndex;
|
|
12806
|
+
selectionChanges[selectionIndex + 1] = anchor.columnIndex;
|
|
12807
|
+
selectionChanges[selectionIndex + 2] = active.rowIndex;
|
|
12808
|
+
selectionChanges[selectionIndex + 3] = active.columnIndex;
|
|
12809
|
+
}
|
|
12810
|
+
lineDelta += change.inserted.length - change.deleted.length;
|
|
12811
|
+
}
|
|
12782
12812
|
// @ts-ignore
|
|
12783
12813
|
return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
|
|
12784
12814
|
};
|