@lvce-editor/editor-worker 19.28.1 → 19.28.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 +78 -33
- package/package.json +1 -1
package/dist/editorWorkerMain.js
CHANGED
|
@@ -1589,7 +1589,7 @@ const sendMessagePortToErrorWorker = async (port, rpcId) => {
|
|
|
1589
1589
|
const command = 'Errors.handleMessagePort';
|
|
1590
1590
|
await invokeAndTransfer('SendMessagePortToExtensionHostWorker.sendMessagePortToErrorWorker', port, command, rpcId);
|
|
1591
1591
|
};
|
|
1592
|
-
const readFile = async uri => {
|
|
1592
|
+
const readFile$1 = async uri => {
|
|
1593
1593
|
return invoke$b('FileSystem.readFile', uri);
|
|
1594
1594
|
};
|
|
1595
1595
|
const handleWorkspaceRefresh = async () => {
|
|
@@ -1639,7 +1639,7 @@ const RendererWorker = {
|
|
|
1639
1639
|
invokeAndTransfer,
|
|
1640
1640
|
openUri,
|
|
1641
1641
|
readClipBoardText,
|
|
1642
|
-
readFile,
|
|
1642
|
+
readFile: readFile$1,
|
|
1643
1643
|
sendMessagePortToDialogWorker,
|
|
1644
1644
|
sendMessagePortToErrorWorker,
|
|
1645
1645
|
sendMessagePortToExtensionHostWorker,
|
|
@@ -3779,7 +3779,8 @@ const splitLines = lines => {
|
|
|
3779
3779
|
};
|
|
3780
3780
|
|
|
3781
3781
|
const {
|
|
3782
|
-
invoke: invoke$7
|
|
3782
|
+
invoke: invoke$7,
|
|
3783
|
+
readFile} = RendererWorker;
|
|
3783
3784
|
|
|
3784
3785
|
const notifyTabModifiedStatusChange = async (uri, modified) => {
|
|
3785
3786
|
try {
|
|
@@ -5025,44 +5026,80 @@ const applyEdit = async (editor, changes) => {
|
|
|
5025
5026
|
|
|
5026
5027
|
// TODO maybe use a separate worker for bulk edits and bulk edit history
|
|
5027
5028
|
|
|
5028
|
-
const
|
|
5029
|
+
const sortEditsDescending = edits => {
|
|
5030
|
+
return edits.toSorted((a, b) => b.offset - a.offset);
|
|
5031
|
+
};
|
|
5032
|
+
const applyEditsToText = (text, edits) => {
|
|
5033
|
+
let newText = text;
|
|
5034
|
+
for (const edit of sortEditsDescending(edits)) {
|
|
5035
|
+
newText = newText.slice(0, edit.offset) + edit.inserted + newText.slice(edit.offset + edit.deleted);
|
|
5036
|
+
}
|
|
5037
|
+
return newText;
|
|
5038
|
+
};
|
|
5039
|
+
const getTextChanges = (editor, edits) => {
|
|
5029
5040
|
const textChanges = [];
|
|
5041
|
+
for (const edit of sortEditsDescending(edits)) {
|
|
5042
|
+
const startPosition = positionAt(editor, edit.offset);
|
|
5043
|
+
const endPosition = positionAt(editor, edit.offset + edit.deleted);
|
|
5044
|
+
const deleted = getSelectionText(editor, {
|
|
5045
|
+
end: endPosition,
|
|
5046
|
+
start: startPosition
|
|
5047
|
+
});
|
|
5048
|
+
const textChange = {
|
|
5049
|
+
deleted,
|
|
5050
|
+
end: endPosition,
|
|
5051
|
+
inserted: [edit.inserted],
|
|
5052
|
+
origin: Rename,
|
|
5053
|
+
start: startPosition
|
|
5054
|
+
};
|
|
5055
|
+
textChanges.push(textChange);
|
|
5056
|
+
}
|
|
5057
|
+
return textChanges;
|
|
5058
|
+
};
|
|
5059
|
+
const groupEditsByUri = changes => {
|
|
5060
|
+
const editsByUri = new Map();
|
|
5030
5061
|
for (const change of changes) {
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
end: endPosition,
|
|
5037
|
-
start: startPosition
|
|
5038
|
-
});
|
|
5039
|
-
const textChange = {
|
|
5040
|
-
deleted,
|
|
5041
|
-
end: endPosition,
|
|
5042
|
-
inserted: [edit.inserted],
|
|
5043
|
-
origin: Rename,
|
|
5044
|
-
start: startPosition
|
|
5045
|
-
};
|
|
5046
|
-
textChanges.push(textChange);
|
|
5047
|
-
}
|
|
5062
|
+
const edits = editsByUri.get(change.uri);
|
|
5063
|
+
if (edits) {
|
|
5064
|
+
edits.push(...change.edits);
|
|
5065
|
+
} else {
|
|
5066
|
+
editsByUri.set(change.uri, [...change.edits]);
|
|
5048
5067
|
}
|
|
5049
5068
|
}
|
|
5050
|
-
return
|
|
5069
|
+
return editsByUri;
|
|
5070
|
+
};
|
|
5071
|
+
const getOpenEditor = (currentEditor, uri) => {
|
|
5072
|
+
if (currentEditor.uri === uri) {
|
|
5073
|
+
return currentEditor;
|
|
5074
|
+
}
|
|
5075
|
+
for (const key of getKeys$2()) {
|
|
5076
|
+
const editor = get$7(Number(key))?.newState;
|
|
5077
|
+
if (editor && !editor.initial && editor.uri === uri) {
|
|
5078
|
+
return editor;
|
|
5079
|
+
}
|
|
5080
|
+
}
|
|
5081
|
+
return undefined;
|
|
5051
5082
|
};
|
|
5052
5083
|
const applyWorkspaceEdit = async (editor, changes) => {
|
|
5053
5084
|
object(editor);
|
|
5054
5085
|
array(changes);
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5086
|
+
let currentEditor = editor;
|
|
5087
|
+
const editsByUri = groupEditsByUri(changes);
|
|
5088
|
+
for (const [uri, edits] of editsByUri) {
|
|
5089
|
+
const openEditor = getOpenEditor(currentEditor, uri);
|
|
5090
|
+
if (openEditor) {
|
|
5091
|
+
const textChanges = getTextChanges(openEditor, edits);
|
|
5092
|
+
const updatedEditor = await scheduleDocumentAndCursorsSelections(openEditor, textChanges);
|
|
5093
|
+
if (openEditor.uid === currentEditor.uid) {
|
|
5094
|
+
currentEditor = updatedEditor;
|
|
5095
|
+
}
|
|
5096
|
+
continue;
|
|
5097
|
+
}
|
|
5098
|
+
const text = await readFile(uri);
|
|
5099
|
+
const newText = applyEditsToText(text, edits);
|
|
5100
|
+
await invoke$7('FileSystem.writeFile', uri, newText);
|
|
5058
5101
|
}
|
|
5059
|
-
|
|
5060
|
-
// for now only apply edits to single file, if it matches the URI
|
|
5061
|
-
//
|
|
5062
|
-
// in the future:
|
|
5063
|
-
// 1. if a change targets the current editor, apply an edit to this editor
|
|
5064
|
-
// 2. else, use file system worker to write file change
|
|
5065
|
-
return scheduleDocumentAndCursorsSelections(editor, textChanges);
|
|
5102
|
+
return currentEditor;
|
|
5066
5103
|
};
|
|
5067
5104
|
|
|
5068
5105
|
const isPersistentWidget = widgetId => {
|
|
@@ -8807,6 +8844,11 @@ const createFn = (key, name, widgetId) => {
|
|
|
8807
8844
|
} = state;
|
|
8808
8845
|
const invoke = getWidgetInvoke(widgetId);
|
|
8809
8846
|
await invoke(`${name}.${key}`, uid, ...args);
|
|
8847
|
+
const latestAfterInvoke = get$7(editor.uid).newState;
|
|
8848
|
+
const latestChildIndex = latestAfterInvoke.widgets.findIndex(isWidget);
|
|
8849
|
+
if (latestChildIndex === -1) {
|
|
8850
|
+
return latestAfterInvoke;
|
|
8851
|
+
}
|
|
8810
8852
|
const diff = await invoke(`${name}.diff2`, uid);
|
|
8811
8853
|
const commands = await invoke(`${name}.render2`, uid, diff);
|
|
8812
8854
|
const latest = get$7(editor.uid).newState;
|
|
@@ -12354,7 +12396,7 @@ const loadContent = async (state, savedState) => {
|
|
|
12354
12396
|
let content = existingEditor ? getText$1(existingEditor) : '';
|
|
12355
12397
|
try {
|
|
12356
12398
|
if (!existingEditor) {
|
|
12357
|
-
content = await readFile(uri);
|
|
12399
|
+
content = await readFile$1(uri);
|
|
12358
12400
|
}
|
|
12359
12401
|
} catch (error) {
|
|
12360
12402
|
const newEditor1 = setBounds(newEditor0, x, y, width, height, 9);
|
|
@@ -12536,6 +12578,9 @@ const renderCss$1 = (oldState, newState) => {
|
|
|
12536
12578
|
};
|
|
12537
12579
|
|
|
12538
12580
|
const renderFocus$2 = (oldState, newState) => {
|
|
12581
|
+
if (!newState.focused) {
|
|
12582
|
+
return [];
|
|
12583
|
+
}
|
|
12539
12584
|
const selector = '.EditorInput textarea';
|
|
12540
12585
|
return [FocusSelector$1, newState.uid, selector];
|
|
12541
12586
|
};
|