@lvce-editor/editor-worker 19.67.0 → 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.
@@ -7665,7 +7665,7 @@ const getCopyLineOperations = selections => {
7665
7665
  }
7666
7666
  return mergedOperations;
7667
7667
  };
7668
- const copyLineDown = editor => {
7668
+ const copyLineDown = async editor => {
7669
7669
  const {
7670
7670
  selections
7671
7671
  } = editor;
@@ -7704,7 +7704,8 @@ const copyLineDown = editor => {
7704
7704
  selectionChanges[i + 2] = selections[i + 2] + getRowOffset(selections[i + 2]);
7705
7705
  selectionChanges[i + 3] = selections[i + 3];
7706
7706
  }
7707
- return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
7707
+ const newEditor = await scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
7708
+ return typeof newEditor.finalDeltaY === 'number' ? scheduleSelections(newEditor, selectionChanges) : newEditor;
7708
7709
  };
7709
7710
 
7710
7711
  const copyLineUp = editor => {
@@ -12775,9 +12776,39 @@ const getMatchingClosingBrace = brace => {
12775
12776
  };
12776
12777
  const typeWithAutoClosingBracket = (editor, text) => {
12777
12778
  const closingBracket = getMatchingClosingBrace(text);
12778
- const newText = text + closingBracket;
12779
- const changes = editorReplaceSelections(editor, [newText], EditorTypeWithAutoClosing);
12780
- const selectionChanges = new Uint32Array([changes[0].start.rowIndex, changes[0].start.columnIndex + 1, changes[0].end.rowIndex, changes[0].end.columnIndex + 1]);
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
+ }
12781
12812
  // @ts-ignore
12782
12813
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
12783
12814
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.67.0",
3
+ "version": "19.67.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"