@lvce-editor/editor-worker 19.27.1 → 19.27.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.
@@ -1620,7 +1620,11 @@ const getPreference = async key => {
1620
1620
  return await invoke$b('Preferences.get', key);
1621
1621
  };
1622
1622
  const openUri = async (uri, focus, options) => {
1623
- await invoke$b('Main.openUri', uri, focus, options);
1623
+ await invoke$b('Main.openUri', {
1624
+ ...options,
1625
+ focus,
1626
+ uri
1627
+ });
1624
1628
  };
1625
1629
  const sendMessagePortToSyntaxHighlightingWorker$1 = async port => {
1626
1630
  await invokeAndTransfer('SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort2');
@@ -12182,9 +12186,19 @@ const loadContent = async (state, savedState) => {
12182
12186
  tabSize,
12183
12187
  tokenizerId: newTokenizerId
12184
12188
  };
12185
- let content = '';
12189
+ let existingEditor;
12190
+ for (const key of getKeys$2()) {
12191
+ const editor = get$7(Number(key))?.newState;
12192
+ if (editor && editor.id !== id && !editor.initial && editor.uri === uri) {
12193
+ existingEditor = editor;
12194
+ break;
12195
+ }
12196
+ }
12197
+ let content = existingEditor ? getText$1(existingEditor) : '';
12186
12198
  try {
12187
- content = await readFile(uri);
12199
+ if (!existingEditor) {
12200
+ content = await readFile(uri);
12201
+ }
12188
12202
  } catch (error) {
12189
12203
  const newEditor1 = setBounds(newEditor0, x, y, width, height, 9);
12190
12204
  return {
@@ -12231,7 +12245,10 @@ const loadContent = async (state, savedState) => {
12231
12245
  const newEditor5 = {
12232
12246
  ...newEditor4,
12233
12247
  completionsOnType,
12234
- initial: false
12248
+ initial: false,
12249
+ modified: existingEditor?.modified || false,
12250
+ redoStack: existingEditor?.redoStack || [],
12251
+ undoStack: existingEditor?.undoStack || []
12235
12252
  };
12236
12253
  return newEditor5;
12237
12254
  };
@@ -13463,18 +13480,20 @@ const editorDiagnosticEffect = {
13463
13480
  isActive: (oldEditor, newEditor) => newEditor.diagnosticsEnabled && JSON.stringify(oldEditor.lines) !== JSON.stringify(newEditor.lines)
13464
13481
  };
13465
13482
 
13466
- const queues = [];
13483
+ const queues = {};
13467
13484
 
13468
13485
  // TODO wrap commands globally, not per editor
13469
13486
  // TODO only store editor state in editor worker, not in renderer worker also
13470
13487
 
13471
13488
  const wrapCommand = fn => async (uid, ...args) => {
13472
- const previous = queues[uid];
13489
+ const initialInstance = get$7(uid);
13490
+ const queueKey = initialInstance?.newState.uri || uid;
13491
+ const previous = queues[queueKey];
13473
13492
  const {
13474
13493
  promise: next,
13475
13494
  resolve
13476
13495
  } = Promise.withResolvers();
13477
- queues[uid] = next;
13496
+ queues[queueKey] = next;
13478
13497
  if (previous) {
13479
13498
  await previous;
13480
13499
  }
@@ -13487,19 +13506,50 @@ const wrapCommand = fn => async (uid, ...args) => {
13487
13506
  }
13488
13507
  const newEditorWithDerivedState = await updateDerivedState(state, newEditor);
13489
13508
  set$9(uid, state, newEditorWithDerivedState);
13490
- if (!editorDiagnosticEffect.isActive(state, newEditorWithDerivedState)) {
13491
- return newEditorWithDerivedState;
13509
+ let finalEditor = newEditorWithDerivedState;
13510
+ if (editorDiagnosticEffect.isActive(state, newEditorWithDerivedState)) {
13511
+ finalEditor = await editorDiagnosticEffect.apply(newEditorWithDerivedState);
13512
+ if (!get$7(uid)) {
13513
+ return finalEditor;
13514
+ }
13515
+ set$9(uid, state, finalEditor);
13492
13516
  }
13493
- const newEditorWithDiagnostics = await editorDiagnosticEffect.apply(newEditorWithDerivedState);
13494
- if (!get$7(uid)) {
13495
- return newEditorWithDiagnostics;
13517
+ const {
13518
+ initial,
13519
+ lines,
13520
+ modified,
13521
+ redoStack,
13522
+ undoStack,
13523
+ uri
13524
+ } = state;
13525
+ if (!initial && uri === finalEditor.uri && (lines !== finalEditor.lines || modified !== finalEditor.modified || redoStack !== finalEditor.redoStack || undoStack !== finalEditor.undoStack)) {
13526
+ for (const key of getKeys$2()) {
13527
+ const otherUid = Number(key);
13528
+ const instance = get$7(otherUid);
13529
+ const editor = instance?.newState;
13530
+ if (otherUid === uid || !instance || !editor || editor.initial || editor.uri !== finalEditor.uri) {
13531
+ continue;
13532
+ }
13533
+ const synchronizedEditor = await updateDerivedState(editor, {
13534
+ ...editor,
13535
+ decorations: finalEditor.decorations,
13536
+ diagnostics: finalEditor.diagnostics,
13537
+ incrementalEdits: emptyIncrementalEdits,
13538
+ invalidStartIndex: Math.min(editor.invalidStartIndex, finalEditor.invalidStartIndex),
13539
+ lines: finalEditor.lines,
13540
+ modified: finalEditor.modified,
13541
+ redoStack: finalEditor.redoStack,
13542
+ undoStack: finalEditor.undoStack,
13543
+ visualDecorations: finalEditor.visualDecorations
13544
+ });
13545
+ set$9(otherUid, instance.oldState, synchronizedEditor);
13546
+ }
13496
13547
  }
13497
- set$9(uid, state, newEditorWithDiagnostics);
13498
- return newEditorWithDiagnostics;
13548
+ return finalEditor;
13499
13549
  } finally {
13500
13550
  resolve();
13501
- if (queues[uid] === next) {
13502
- queues[uid] = undefined;
13551
+ if (queues[queueKey] === next) {
13552
+ delete queues[queueKey];
13503
13553
  }
13504
13554
  }
13505
13555
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.27.1",
3
+ "version": "19.27.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"