@lvce-editor/editor-worker 19.30.3 → 19.30.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/editorWorkerMain.js +29 -8
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -4987,24 +4987,45 @@ const addCursorBelow = editor => {
|
|
|
4987
4987
|
|
|
4988
4988
|
const getDocumentEdits = (editor, edits) => {
|
|
4989
4989
|
const documentEdits = [];
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4990
|
+
let currentDocument = editor;
|
|
4991
|
+
let linesDelta = 0;
|
|
4992
|
+
let offsetDelta = 0;
|
|
4993
|
+
const sortedEdits = edits.toSorted((a, b) => a.startOffset - b.startOffset || a.endOffset - b.endOffset);
|
|
4994
|
+
for (const edit of sortedEdits) {
|
|
4995
|
+
const currentStart = positionAt(currentDocument, edit.startOffset + offsetDelta);
|
|
4996
|
+
const currentEnd = positionAt(currentDocument, edit.endOffset + offsetDelta);
|
|
4997
|
+
const deleted = getSelectionText(currentDocument, {
|
|
4998
|
+
end: currentEnd,
|
|
4999
|
+
start: currentStart
|
|
4996
5000
|
});
|
|
4997
5001
|
const documentEdit = {
|
|
4998
5002
|
deleted,
|
|
4999
|
-
end
|
|
5003
|
+
end: {
|
|
5004
|
+
columnIndex: currentEnd.columnIndex,
|
|
5005
|
+
rowIndex: currentEnd.rowIndex - linesDelta
|
|
5006
|
+
},
|
|
5000
5007
|
inserted: splitLines(edit.inserted),
|
|
5001
5008
|
origin: Format,
|
|
5002
|
-
start
|
|
5009
|
+
start: {
|
|
5010
|
+
columnIndex: currentStart.columnIndex,
|
|
5011
|
+
rowIndex: currentStart.rowIndex - linesDelta
|
|
5012
|
+
}
|
|
5003
5013
|
};
|
|
5004
5014
|
if (documentEdit.inserted.length === 0) {
|
|
5005
5015
|
documentEdit.inserted = [''];
|
|
5006
5016
|
}
|
|
5007
5017
|
documentEdits.push(documentEdit);
|
|
5018
|
+
const currentEdit = {
|
|
5019
|
+
...documentEdit,
|
|
5020
|
+
end: currentEnd,
|
|
5021
|
+
start: currentStart
|
|
5022
|
+
};
|
|
5023
|
+
currentDocument = {
|
|
5024
|
+
...currentDocument,
|
|
5025
|
+
lines: applyEdits(currentDocument, [currentEdit])
|
|
5026
|
+
};
|
|
5027
|
+
linesDelta += documentEdit.inserted.length - documentEdit.deleted.length;
|
|
5028
|
+
offsetDelta += edit.inserted.length - (edit.endOffset - edit.startOffset);
|
|
5008
5029
|
}
|
|
5009
5030
|
return documentEdits;
|
|
5010
5031
|
};
|