@lvce-editor/editor-worker 19.61.4 → 19.61.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/editorWorkerMain.js +73 -32
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -4211,6 +4211,14 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
|
|
|
4211
4211
|
const newLines = applyEdits(editor, changes);
|
|
4212
4212
|
const partialNewEditor = updateLines(editor, newLines);
|
|
4213
4213
|
const newSelections = selectionChanges || applyEdit$1(partialNewEditor, changes);
|
|
4214
|
+
const selectionHistory = {
|
|
4215
|
+
after: newSelections,
|
|
4216
|
+
before: editor.selections
|
|
4217
|
+
};
|
|
4218
|
+
Object.defineProperty(changes, 'selectionHistory', {
|
|
4219
|
+
configurable: true,
|
|
4220
|
+
value: selectionHistory
|
|
4221
|
+
});
|
|
4214
4222
|
// TODO should separate rendering from business logic somehow
|
|
4215
4223
|
// currently hard to test because need to mock editor height, top, left,
|
|
4216
4224
|
// invalidStartIndex, lineCache, etc. just for testing editorType
|
|
@@ -4281,7 +4289,7 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
|
|
|
4281
4289
|
};
|
|
4282
4290
|
};
|
|
4283
4291
|
// @ts-ignore
|
|
4284
|
-
const scheduleDocumentAndCursorsSelectionIsUndo = async (editor, changes) => {
|
|
4292
|
+
const scheduleDocumentAndCursorsSelectionIsUndo = async (editor, changes, selectionChanges = undefined) => {
|
|
4285
4293
|
object(editor);
|
|
4286
4294
|
array(changes);
|
|
4287
4295
|
if (changes.length === 0) {
|
|
@@ -4289,7 +4297,7 @@ const scheduleDocumentAndCursorsSelectionIsUndo = async (editor, changes) => {
|
|
|
4289
4297
|
}
|
|
4290
4298
|
const newLines = applyEdits(editor, changes);
|
|
4291
4299
|
const partialNewEditor = updateLines(editor, newLines);
|
|
4292
|
-
const newSelections = applyEdit$1(partialNewEditor, changes);
|
|
4300
|
+
const newSelections = selectionChanges || applyEdit$1(partialNewEditor, changes);
|
|
4293
4301
|
const invalidStartIndex = Math.min(editor.invalidStartIndex, changes[0].start.rowIndex);
|
|
4294
4302
|
const newEditor = {
|
|
4295
4303
|
...partialNewEditor,
|
|
@@ -7445,40 +7453,69 @@ const copy$1 = async editor => {
|
|
|
7445
7453
|
return editor;
|
|
7446
7454
|
};
|
|
7447
7455
|
|
|
7448
|
-
|
|
7449
|
-
|
|
7456
|
+
const getCopyLineOperations = selections => {
|
|
7457
|
+
const operations = [];
|
|
7458
|
+
for (let i = 0; i < selections.length; i += 4) {
|
|
7459
|
+
const [startRowIndex,, selectionEndRowIndex, endColumnIndex] = getSelectionPairs(selections, i);
|
|
7460
|
+
const endRowIndex = startRowIndex < selectionEndRowIndex && endColumnIndex === 0 ? selectionEndRowIndex - 1 : selectionEndRowIndex;
|
|
7461
|
+
operations.push({
|
|
7462
|
+
endRowIndex,
|
|
7463
|
+
startRowIndex
|
|
7464
|
+
});
|
|
7465
|
+
}
|
|
7466
|
+
operations.sort((a, b) => a.startRowIndex - b.startRowIndex || a.endRowIndex - b.endRowIndex);
|
|
7467
|
+
const mergedOperations = [];
|
|
7468
|
+
for (const operation of operations) {
|
|
7469
|
+
const previous = mergedOperations.at(-1);
|
|
7470
|
+
if (previous && previous.endRowIndex >= operation.startRowIndex) {
|
|
7471
|
+
mergedOperations[mergedOperations.length - 1] = {
|
|
7472
|
+
...previous,
|
|
7473
|
+
endRowIndex: Math.max(previous.endRowIndex, operation.endRowIndex)
|
|
7474
|
+
};
|
|
7475
|
+
} else {
|
|
7476
|
+
mergedOperations.push(operation);
|
|
7477
|
+
}
|
|
7478
|
+
}
|
|
7479
|
+
return mergedOperations;
|
|
7480
|
+
};
|
|
7450
7481
|
const copyLineDown = editor => {
|
|
7451
7482
|
const {
|
|
7452
7483
|
selections
|
|
7453
7484
|
} = editor;
|
|
7454
|
-
const
|
|
7455
|
-
|
|
7456
|
-
|
|
7457
|
-
|
|
7458
|
-
|
|
7459
|
-
|
|
7460
|
-
const uniqueRows = [...new Set(rows)].toSorted((a, b) => a - b);
|
|
7461
|
-
const changes = uniqueRows.map(rowIndex => {
|
|
7462
|
-
const position = {
|
|
7463
|
-
columnIndex: 0,
|
|
7464
|
-
rowIndex
|
|
7465
|
-
};
|
|
7485
|
+
const operations = getCopyLineOperations(selections);
|
|
7486
|
+
const changes = operations.map(({
|
|
7487
|
+
endRowIndex,
|
|
7488
|
+
startRowIndex
|
|
7489
|
+
}) => {
|
|
7490
|
+
const selectedLines = editor.lines.slice(startRowIndex, endRowIndex + 1);
|
|
7466
7491
|
return {
|
|
7467
|
-
deleted:
|
|
7468
|
-
end:
|
|
7469
|
-
|
|
7470
|
-
|
|
7492
|
+
deleted: selectedLines,
|
|
7493
|
+
end: {
|
|
7494
|
+
columnIndex: editor.lines[endRowIndex].length,
|
|
7495
|
+
rowIndex: endRowIndex
|
|
7496
|
+
},
|
|
7497
|
+
inserted: [...selectedLines, ...selectedLines],
|
|
7498
|
+
start: {
|
|
7499
|
+
columnIndex: 0,
|
|
7500
|
+
rowIndex: startRowIndex
|
|
7501
|
+
}
|
|
7471
7502
|
};
|
|
7472
7503
|
});
|
|
7473
|
-
const
|
|
7504
|
+
const getRowOffset = rowIndex => {
|
|
7505
|
+
let offset = 0;
|
|
7506
|
+
for (const operation of operations) {
|
|
7507
|
+
if (operation.startRowIndex <= rowIndex) {
|
|
7508
|
+
offset += operation.endRowIndex - operation.startRowIndex + 1;
|
|
7509
|
+
}
|
|
7510
|
+
}
|
|
7511
|
+
return offset;
|
|
7512
|
+
};
|
|
7474
7513
|
const selectionChanges = new Uint32Array(selections.length);
|
|
7475
7514
|
for (let i = 0; i < selections.length; i += 4) {
|
|
7476
|
-
|
|
7477
|
-
|
|
7478
|
-
selectionChanges[i] =
|
|
7479
|
-
selectionChanges[i +
|
|
7480
|
-
selectionChanges[i + 2] = rowIndex;
|
|
7481
|
-
selectionChanges[i + 3] = columnIndex;
|
|
7515
|
+
selectionChanges[i] = selections[i] + getRowOffset(selections[i]);
|
|
7516
|
+
selectionChanges[i + 1] = selections[i + 1];
|
|
7517
|
+
selectionChanges[i + 2] = selections[i + 2] + getRowOffset(selections[i + 2]);
|
|
7518
|
+
selectionChanges[i + 3] = selections[i + 3];
|
|
7482
7519
|
}
|
|
7483
7520
|
return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
|
|
7484
7521
|
};
|
|
@@ -11106,12 +11143,13 @@ const redo = state => {
|
|
|
11106
11143
|
return state;
|
|
11107
11144
|
}
|
|
11108
11145
|
const last = redoStack.at(-1);
|
|
11146
|
+
const selectionChanges = last.selectionHistory?.after;
|
|
11109
11147
|
const newState = {
|
|
11110
11148
|
...state,
|
|
11111
11149
|
redoStack: redoStack.slice(0, -1),
|
|
11112
11150
|
undoStack: [...state.undoStack, last]
|
|
11113
11151
|
};
|
|
11114
|
-
return scheduleDocumentAndCursorsSelectionIsUndo(newState, last);
|
|
11152
|
+
return scheduleDocumentAndCursorsSelectionIsUndo(newState, last, selectionChanges);
|
|
11115
11153
|
};
|
|
11116
11154
|
|
|
11117
11155
|
// @ts-ignore
|
|
@@ -12627,12 +12665,14 @@ const typeWithAutoClosing = async (editor, text) => {
|
|
|
12627
12665
|
};
|
|
12628
12666
|
|
|
12629
12667
|
const inverseChange = edit => {
|
|
12630
|
-
const
|
|
12668
|
+
const insertedLines = edit.inserted;
|
|
12669
|
+
const endRowIndex = edit.start.rowIndex + insertedLines.length - 1;
|
|
12670
|
+
const endColumnIndex = insertedLines.length === 1 ? edit.start.columnIndex + insertedLines[0].length : insertedLines.at(-1).length;
|
|
12631
12671
|
return {
|
|
12632
|
-
deleted:
|
|
12672
|
+
deleted: insertedLines,
|
|
12633
12673
|
end: {
|
|
12634
12674
|
columnIndex: endColumnIndex,
|
|
12635
|
-
rowIndex:
|
|
12675
|
+
rowIndex: endRowIndex
|
|
12636
12676
|
},
|
|
12637
12677
|
inserted: edit.deleted,
|
|
12638
12678
|
start: edit.start
|
|
@@ -12648,12 +12688,13 @@ const undo = state => {
|
|
|
12648
12688
|
}
|
|
12649
12689
|
const last = undoStack.at(-1);
|
|
12650
12690
|
const inverseChanges = last.toReversed().map(inverseChange);
|
|
12691
|
+
const selectionChanges = last.selectionHistory?.before;
|
|
12651
12692
|
const newState = {
|
|
12652
12693
|
...state,
|
|
12653
12694
|
redoStack: [...(state.redoStack || []), last],
|
|
12654
12695
|
undoStack: undoStack.slice(0, -1)
|
|
12655
12696
|
};
|
|
12656
|
-
return scheduleDocumentAndCursorsSelectionIsUndo(newState, inverseChanges);
|
|
12697
|
+
return scheduleDocumentAndCursorsSelectionIsUndo(newState, inverseChanges, selectionChanges);
|
|
12657
12698
|
};
|
|
12658
12699
|
|
|
12659
12700
|
const unfold = editor => {
|