@lvce-editor/editor-worker 19.73.0 → 19.73.2

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.
@@ -3779,6 +3779,10 @@ const getIncrementalEdits = async (oldState, newState) => {
3779
3779
  lines
3780
3780
  } = newState;
3781
3781
  const oldLine = oldState.lines[rowIndex];
3782
+ // Empty lines have no nonempty token to update; render the new token normally.
3783
+ if (oldLine.length === 0) {
3784
+ return emptyIncrementalEdits;
3785
+ }
3782
3786
  const newLine = lines[rowIndex];
3783
3787
  // Renderer edit offsets address full lines, so clipped rows need a fresh visible window.
3784
3788
  const threshold = newState.horizontalVirtualizationThreshold ?? 500;
@@ -7189,6 +7193,43 @@ const {
7189
7193
  setFactory
7190
7194
  } = createLazyRpc(CompletionWorker);
7191
7195
 
7196
+ // These commits preserve the document, selection, layout, widgets and lifecycle.
7197
+ const diagnosticFields = new Set(['decorations', 'diagnostics', 'lightBulbRowIndex', 'visualDecorations']);
7198
+ const isCurrent$1 = (snapshot, current) => {
7199
+ if (!current || current.lifecycle?.disposed) {
7200
+ return false;
7201
+ }
7202
+ if (snapshot === current) {
7203
+ return true;
7204
+ }
7205
+ const keys = new Set([...Object.keys(snapshot), ...Object.keys(current)]);
7206
+ for (const key of keys) {
7207
+ if (diagnosticFields.has(key)) {
7208
+ continue;
7209
+ }
7210
+ const field = key;
7211
+ if (Object.hasOwn(snapshot, field) !== Object.hasOwn(current, field) || snapshot[field] !== current[field]) {
7212
+ return false;
7213
+ }
7214
+ }
7215
+ return true;
7216
+ };
7217
+ const merge = (current, snapshot, result) => {
7218
+ if (!isCurrent$1(snapshot, current) || result === snapshot || result === current) {
7219
+ return current;
7220
+ }
7221
+ if (current === snapshot) {
7222
+ return result;
7223
+ }
7224
+ return {
7225
+ ...result,
7226
+ decorations: current.decorations,
7227
+ diagnostics: current.diagnostics,
7228
+ lightBulbRowIndex: current.lightBulbRowIndex,
7229
+ visualDecorations: current.visualDecorations
7230
+ };
7231
+ };
7232
+
7192
7233
  const updateWidget = (editor, widgetId, newState) => {
7193
7234
  // TODO avoid closure
7194
7235
  const isWidget = widget => {
@@ -7255,7 +7296,7 @@ const openCompletion = async (editor, automatic = false) => {
7255
7296
  uid
7256
7297
  } = widget.newState;
7257
7298
  await invoke$4('Completions.loadContent', uid, automatic);
7258
- if (get$8(editor.uid)?.newState !== editor) {
7299
+ if (!isCurrent$1(editor, get$8(editor.uid)?.newState)) {
7259
7300
  return get$8(editor.uid)?.newState || editor;
7260
7301
  }
7261
7302
  if (automatic && !(await invoke$4('Completions.hasItems', uid))) {
@@ -7289,7 +7330,7 @@ const openCompletion = async (editor, automatic = false) => {
7289
7330
  const result = await addWidgetToEditor(Completion, EditorCompletion, editor, create$7, generateState, fullFocus);
7290
7331
  const wasAdded = (result?.widgets || []).some(widget => widget.id === Completion && widget.newState.uid === completionUid);
7291
7332
  const currentEditor = get$8(editor.uid)?.newState;
7292
- if (created && (!wasAdded || currentEditor !== editor)) {
7333
+ if (created && (!wasAdded || !isCurrent$1(editor, currentEditor))) {
7293
7334
  await disposeCompletion(completionUid);
7294
7335
  }
7295
7336
  return result;
@@ -8563,7 +8604,7 @@ const wrapFocusCommand$1 = (fn, returnState = true) => {
8563
8604
 
8564
8605
  // Optional provider work must not hold the editing queue while another worker responds.
8565
8606
  const wrapDeferredCommand$1 = (fn, returnState = true) => {
8566
- const apply = wrapCommand$1((editor, snapshot, result) => editor === snapshot ? result : editor, false, returnState);
8607
+ const apply = wrapCommand$1((editor, snapshot, result) => merge(editor, snapshot, result), false, returnState);
8567
8608
  return async (uid, ...args) => {
8568
8609
  const snapshot = await enqueue(uid, async () => get$8(uid)?.newState);
8569
8610
  if (!snapshot) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "19.73.0",
3
+ "version": "19.73.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git@github.com:lvce-editor/editor-worker.git"