@lvce-editor/editor-worker 19.70.2 → 19.70.3
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 +56 -1
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -8785,9 +8785,64 @@ const cursorDown = editor => {
|
|
|
8785
8785
|
return scheduleSelections(editor, newSelections);
|
|
8786
8786
|
};
|
|
8787
8787
|
|
|
8788
|
+
const getSelectionsAtLineEnd = (selections, lines) => {
|
|
8789
|
+
const newSelections = new Uint32Array(selections.length);
|
|
8790
|
+
for (let i = 0; i < selections.length; i += 4) {
|
|
8791
|
+
const [selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn] = getSelectionPairs(selections, i);
|
|
8792
|
+
const rowIndex = selectionStartRow === selectionEndRow && selectionStartColumn === selectionEndColumn ? selectionStartRow : selectionEndRow;
|
|
8793
|
+
const columnIndex = selectionStartRow === selectionEndRow && selectionStartColumn === selectionEndColumn ? getLineLength(lines[rowIndex]) : selectionEndColumn;
|
|
8794
|
+
newSelections[i] = rowIndex;
|
|
8795
|
+
newSelections[i + 1] = columnIndex;
|
|
8796
|
+
newSelections[i + 2] = rowIndex;
|
|
8797
|
+
newSelections[i + 3] = columnIndex;
|
|
8798
|
+
}
|
|
8799
|
+
return newSelections;
|
|
8800
|
+
};
|
|
8801
|
+
const removeDuplicateSelections = (editor, selections) => {
|
|
8802
|
+
const uniqueSelections = new Uint32Array(selections.length);
|
|
8803
|
+
const selectionIndices = new Map();
|
|
8804
|
+
const primarySelectionIndex = editor.primarySelectionIndex || 0;
|
|
8805
|
+
let uniqueSelectionCount = 0;
|
|
8806
|
+
let newPrimarySelectionIndex = 0;
|
|
8807
|
+
for (let i = 0; i < selections.length; i += 4) {
|
|
8808
|
+
const rowIndex = selections[i + 2];
|
|
8809
|
+
const columnIndex = selections[i + 3];
|
|
8810
|
+
const key = `${rowIndex}:${columnIndex}`;
|
|
8811
|
+
const existingSelectionIndex = selectionIndices.get(key);
|
|
8812
|
+
if (existingSelectionIndex !== undefined) {
|
|
8813
|
+
if (i === primarySelectionIndex) {
|
|
8814
|
+
newPrimarySelectionIndex = existingSelectionIndex * 4;
|
|
8815
|
+
}
|
|
8816
|
+
continue;
|
|
8817
|
+
}
|
|
8818
|
+
selectionIndices.set(key, uniqueSelectionCount);
|
|
8819
|
+
uniqueSelections.set(selections.subarray(i, i + 4), uniqueSelectionCount * 4);
|
|
8820
|
+
if (i === primarySelectionIndex) {
|
|
8821
|
+
newPrimarySelectionIndex = uniqueSelectionCount * 4;
|
|
8822
|
+
}
|
|
8823
|
+
uniqueSelectionCount++;
|
|
8824
|
+
}
|
|
8825
|
+
return {
|
|
8826
|
+
primarySelectionIndex: newPrimarySelectionIndex,
|
|
8827
|
+
selections: uniqueSelections.slice(0, uniqueSelectionCount * 4)
|
|
8828
|
+
};
|
|
8829
|
+
};
|
|
8830
|
+
|
|
8788
8831
|
// @ts-ignore
|
|
8789
8832
|
const cursorEnd = editor => {
|
|
8790
|
-
|
|
8833
|
+
const {
|
|
8834
|
+
lines,
|
|
8835
|
+
selections: oldSelections
|
|
8836
|
+
} = editor;
|
|
8837
|
+
const movedSelections = getSelectionsAtLineEnd(oldSelections, lines);
|
|
8838
|
+
const {
|
|
8839
|
+
primarySelectionIndex,
|
|
8840
|
+
selections
|
|
8841
|
+
} = removeDuplicateSelections(editor, movedSelections);
|
|
8842
|
+
return scheduleSelections({
|
|
8843
|
+
...editor,
|
|
8844
|
+
primarySelectionIndex
|
|
8845
|
+
}, selections);
|
|
8791
8846
|
};
|
|
8792
8847
|
|
|
8793
8848
|
// @ts-ignore
|