@lvce-editor/editor-worker 19.75.0 → 19.75.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.
@@ -543,7 +543,7 @@ class CommandNotFoundError extends Error {
543
543
  }
544
544
  }
545
545
  const commands = Object.create(null);
546
- const register = commandMap => {
546
+ const register$1 = commandMap => {
547
547
  Object.assign(commands, commandMap);
548
548
  };
549
549
  const getCommand = key => {
@@ -1102,7 +1102,7 @@ const create$h = async ({
1102
1102
  messagePort
1103
1103
  }) => {
1104
1104
  // TODO create a commandMap per rpc instance
1105
- register(commandMap);
1105
+ register$1(commandMap);
1106
1106
  const rawIpc = await IpcParentWithMessagePort$1.create({
1107
1107
  isMessagePortOpen,
1108
1108
  messagePort
@@ -1159,7 +1159,7 @@ const create$d = async ({
1159
1159
  commandMap
1160
1160
  }) => {
1161
1161
  // TODO create a commandMap per rpc instance
1162
- register(commandMap);
1162
+ register$1(commandMap);
1163
1163
  const ipc = await listen$1(IpcChildWithModuleWorkerAndMessagePort$1);
1164
1164
  handleIpc(ipc);
1165
1165
  const rpc = createRpc(ipc);
@@ -1187,7 +1187,7 @@ const createMockRpc = ({
1187
1187
  };
1188
1188
 
1189
1189
  const rpcs = Object.create(null);
1190
- const set$k = (id, rpc) => {
1190
+ const set$j = (id, rpc) => {
1191
1191
  rpcs[id] = rpc;
1192
1192
  };
1193
1193
  const get$9 = id => {
@@ -1220,7 +1220,7 @@ const create$c = rpcId => {
1220
1220
  const mockRpc = createMockRpc({
1221
1221
  commandMap
1222
1222
  });
1223
- set$k(rpcId, mockRpc);
1223
+ set$j(rpcId, mockRpc);
1224
1224
  // @ts-ignore
1225
1225
  mockRpc[Symbol.dispose] = () => {
1226
1226
  remove$8(rpcId);
@@ -1229,7 +1229,7 @@ const create$c = rpcId => {
1229
1229
  return mockRpc;
1230
1230
  },
1231
1231
  set(rpc) {
1232
- set$k(rpcId, rpc);
1232
+ set$j(rpcId, rpc);
1233
1233
  }
1234
1234
  };
1235
1235
  };
@@ -1328,23 +1328,23 @@ const FocusEditorText$1 = 12;
1328
1328
 
1329
1329
  const {
1330
1330
  invoke: invoke$k,
1331
- set: set$j
1331
+ set: set$i
1332
1332
  } = create$c(DialogWorker);
1333
1333
 
1334
1334
  const {
1335
1335
  invoke: invoke$j,
1336
- set: set$i
1336
+ set: set$h
1337
1337
  } = create$c(DragAndDropWorker);
1338
1338
 
1339
1339
  const {
1340
1340
  invoke: invoke$i,
1341
- set: set$h
1341
+ set: set$g
1342
1342
  } = create$c(ErrorWorker);
1343
1343
 
1344
1344
  const {
1345
1345
  invoke: invoke$h,
1346
1346
  invokeAndTransfer: invokeAndTransfer$2,
1347
- set: set$g
1347
+ set: set$f
1348
1348
  } = create$c(ExtensionManagementWorker);
1349
1349
  const getLanguages$1 = (platform, assetDir) => {
1350
1350
  return invoke$h('Extensions.getLanguages', platform, assetDir);
@@ -1363,7 +1363,7 @@ const createLazyRpc = rpcId => {
1363
1363
  throw new Error('Lazy RPC launch was superseded');
1364
1364
  }
1365
1365
  activeRpc = rpc;
1366
- set$k(rpcId, rpc);
1366
+ set$j(rpcId, rpc);
1367
1367
  return rpc;
1368
1368
  };
1369
1369
  const ensureRpc = async () => {
@@ -1425,7 +1425,7 @@ const createLazyRpc = rpcId => {
1425
1425
 
1426
1426
  const {
1427
1427
  invoke: invoke$g,
1428
- set: set$f
1428
+ set: set$e
1429
1429
  } = create$c(OpenerWorker);
1430
1430
  const openUrl = async (url, platform) => {
1431
1431
  return invoke$g('Open.openUrl', url, platform);
@@ -1433,13 +1433,13 @@ const openUrl = async (url, platform) => {
1433
1433
 
1434
1434
  const {
1435
1435
  invoke: invoke$f,
1436
- set: set$e
1436
+ set: set$d
1437
1437
  } = create$c(TextMeasurementWorker);
1438
1438
 
1439
1439
  const {
1440
1440
  invoke: invoke$e,
1441
1441
  invokeAndTransfer: invokeAndTransfer$1,
1442
- set: set$d
1442
+ set: set$c
1443
1443
  } = create$c(RendererWorker);
1444
1444
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
1445
1445
  number(uid);
@@ -1494,7 +1494,7 @@ const sendMessagePortToSyntaxHighlightingWorker$1 = async port => {
1494
1494
 
1495
1495
  const {
1496
1496
  invoke: invoke$d,
1497
- set: set$c
1497
+ set: set$b
1498
1498
  } = create$c(MarkdownWorker);
1499
1499
 
1500
1500
  const toCommandId = key => {
@@ -1796,6 +1796,7 @@ const {
1796
1796
  dispose: dispose$6,
1797
1797
  getCommandIds,
1798
1798
  registerCommands,
1799
+ wrapCommand: wrapCommand$2,
1799
1800
  wrapGetter
1800
1801
  } = editorStates;
1801
1802
  const get$8 = id => {
@@ -1805,7 +1806,7 @@ const getKeys$2 = () => {
1805
1806
  const keys = editorStates.getKeys();
1806
1807
  return keys.map(String);
1807
1808
  };
1808
- const set$b = (id, oldEditor, newEditor) => {
1809
+ const set$a = (id, oldEditor, newEditor) => {
1809
1810
  editorStates.set(id, oldEditor, newEditor);
1810
1811
  };
1811
1812
 
@@ -1856,7 +1857,7 @@ const ToggleBlockComment$1 = 'toggleBlockComment';
1856
1857
  const Unknown$2 = 'unknown';
1857
1858
 
1858
1859
  const map$1 = Object.create(null);
1859
- const set$a = (id, widget) => {
1860
+ const set$9 = (id, widget) => {
1860
1861
  map$1[id] = widget;
1861
1862
  };
1862
1863
  const get$7 = id => {
@@ -2465,6 +2466,13 @@ const getHorizontalVisibleRange = (line, deltaX, width, averageCharWidth, tabSiz
2465
2466
  };
2466
2467
  const getHorizontalVisibleRangesMeasured = async (requests, measureWidths) => {
2467
2468
  const fallback = request => {
2469
+ if (request.line.length <= request.threshold) {
2470
+ return {
2471
+ difference: getHorizontalVisibleDifference(request.line, 0, request.deltaX, request.averageCharWidth, request.tabSize, []),
2472
+ end: request.line.length,
2473
+ start: 0
2474
+ };
2475
+ }
2468
2476
  const segments = request.segments || getSegments(request.line);
2469
2477
  const range = getHorizontalVisibleRange(request.line, request.deltaX, request.width, request.averageCharWidth, request.tabSize, request.threshold, segments);
2470
2478
  return {
@@ -2728,7 +2736,7 @@ const getEnabled$1 = () => {
2728
2736
  };
2729
2737
 
2730
2738
  const invoke$c = (...args) => invoke$d(...args);
2731
- const set$9 = (...args) => set$c(...args);
2739
+ const set$8 = (...args) => set$b(...args);
2732
2740
 
2733
2741
  const state$d = {
2734
2742
  pending: Object.create(null),
@@ -2738,7 +2746,7 @@ const state$d = {
2738
2746
  const has = languageId => {
2739
2747
  return Object.hasOwn(state$d.tokenizers, languageId);
2740
2748
  };
2741
- const set$8 = (languageId, tokenizer) => {
2749
+ const set$7 = (languageId, tokenizer) => {
2742
2750
  state$d.tokenizers[languageId] = tokenizer;
2743
2751
  };
2744
2752
  const get$6 = languageId => {
@@ -2762,7 +2770,7 @@ const isPending = languageId => {
2762
2770
  };
2763
2771
 
2764
2772
  const tokenMaps = Object.create(null);
2765
- const set$7 = (languageId, tokenMap) => {
2773
+ const set$6 = (languageId, tokenMap) => {
2766
2774
  tokenMaps[languageId] = tokenMap;
2767
2775
  };
2768
2776
  const get$5 = languageId => {
@@ -2778,7 +2786,7 @@ const loadTokenizer = async (languageId, tokenizePath) => {
2778
2786
  if (getEnabled$1()) {
2779
2787
  // @ts-ignore
2780
2788
  const tokenMap = await invoke$c('Tokenizer.load', languageId, tokenizePath);
2781
- set$7(languageId, tokenMap);
2789
+ set$6(languageId, tokenMap);
2782
2790
  return;
2783
2791
  }
2784
2792
  try {
@@ -2794,8 +2802,8 @@ const loadTokenizer = async (languageId, tokenizePath) => {
2794
2802
  console.warn(`tokenizer.TokenMap should be an object in "${tokenizePath}"`);
2795
2803
  return;
2796
2804
  }
2797
- set$7(languageId, tokenizer.TokenMap);
2798
- set$8(languageId, tokenizer);
2805
+ set$6(languageId, tokenizer.TokenMap);
2806
+ set$7(languageId, tokenizer);
2799
2807
  } catch (error) {
2800
2808
  // TODO better error handling
2801
2809
  console.error(error);
@@ -2811,13 +2819,18 @@ const getTokenizer = languageId => {
2811
2819
  return TokenizePlainText;
2812
2820
  };
2813
2821
 
2814
- const tokenizers = Object.create(null);
2815
- const set$6 = (id, value) => {
2816
- tokenizers[id] = value;
2817
- };
2822
+ const tokenizers = [TokenizePlainText];
2818
2823
  const get$4 = id => {
2819
2824
  return tokenizers[id] || TokenizePlainText;
2820
2825
  };
2826
+ const register = tokenizer => {
2827
+ const existingId = tokenizers.indexOf(tokenizer);
2828
+ if (existingId !== -1) {
2829
+ return existingId;
2830
+ }
2831
+ tokenizers.push(tokenizer);
2832
+ return tokenizers.length - 1;
2833
+ };
2821
2834
 
2822
2835
  const getEmbeddedTokenization = (langageId, line, embeddedLanguage, embeddedLanguageStart, embeddedLanguageEnd, topContexts, tokenizersToLoad) => {
2823
2836
  const embeddedTokenizer = getTokenizer(embeddedLanguage);
@@ -3241,7 +3254,10 @@ const positionAt = (textDocument, offset) => {
3241
3254
  };
3242
3255
 
3243
3256
  const maxTokenizerLoadPasses$1 = 10;
3244
- const getGraphemeSegments = async lines => {
3257
+ const getGraphemeSegments = async (lines, threshold) => {
3258
+ if (lines.every(line => line.length <= threshold)) {
3259
+ return undefined;
3260
+ }
3245
3261
  try {
3246
3262
  return await invoke$f('TextMeasurement.getGraphemeSegments', lines);
3247
3263
  } catch {
@@ -3574,7 +3590,7 @@ const getLineInfosViewport = async (editor, tokens, embeddedResults, minLineY, m
3574
3590
  let offset = minLineOffset;
3575
3591
  const tabSize = editor.tabSize ?? 2;
3576
3592
  const visibleLines = lines.slice(minLineY, maxLineY);
3577
- const graphemeSegments = await getGraphemeSegments(visibleLines);
3593
+ const graphemeSegments = await getGraphemeSegments(visibleLines, horizontalVirtualizationThreshold);
3578
3594
  const measuredRanges = await getHorizontalVisibleRangesMeasured(visibleLines.map((line, index) => ({
3579
3595
  averageCharWidth,
3580
3596
  deltaX,
@@ -4407,7 +4423,7 @@ const getTabCount = string => {
4407
4423
  return count;
4408
4424
  };
4409
4425
 
4410
- const getX = async (line, column, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference = 0) => {
4426
+ const getX = async (line, column, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference = 0, measuredLineWidth) => {
4411
4427
  if (!line) {
4412
4428
  return 0;
4413
4429
  }
@@ -4426,7 +4442,7 @@ const getX = async (line, column, fontWeight, fontSize, fontFamily, isMonospaceF
4426
4442
  const normalizedLine = normalizeText(line, normalize, tabSize);
4427
4443
  const tabCount = getTabCount(line.slice(0, column));
4428
4444
  const partialText = normalizedLine.slice(0, column + tabCount * (tabSize - 1));
4429
- const textWidth = await measureTextWidth(partialText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, averageCharWidth);
4445
+ const textWidth = column === line.length && measuredLineWidth !== undefined ? measuredLineWidth : await measureTextWidth(partialText, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, averageCharWidth);
4430
4446
  return Math.min(width, textWidth - halfCursorWidth + difference);
4431
4447
  };
4432
4448
 
@@ -4583,7 +4599,7 @@ const commitDiagnostics = async (editor, generation, diagnostics, onAccepted) =>
4583
4599
  return latest.newState;
4584
4600
  }
4585
4601
  const newEditor = mergeDiagnostics(latest.newState, editorWithDiagnostics);
4586
- set$b(editor.id, latest.oldState, newEditor);
4602
+ set$a(editor.id, latest.oldState, newEditor);
4587
4603
  requestDiagnosticSnapshots.set(editor.id, diagnostics);
4588
4604
  onAccepted?.();
4589
4605
  await invoke$8('Editor.renderPending', newEditor.id);
@@ -4809,6 +4825,109 @@ const px = value => {
4809
4825
  return `${value}px`;
4810
4826
  };
4811
4827
 
4828
+ // Owned by the editor lifecycle, with only the current document's distinct lines retained.
4829
+ const caches = new WeakMap();
4830
+ const getFontKey = ({
4831
+ charWidth,
4832
+ fontFamily,
4833
+ fontSize,
4834
+ fontWeight,
4835
+ isMonospaceFont,
4836
+ letterSpacing,
4837
+ tabSize
4838
+ }) => JSON.stringify([charWidth, fontFamily, fontSize, fontWeight, isMonospaceFont, letterSpacing, tabSize]);
4839
+ const getCachedLineWidth = (state, line) => {
4840
+ const {
4841
+ largeFile,
4842
+ lifecycle,
4843
+ lines
4844
+ } = state;
4845
+ if (largeFile || lifecycle?.disposed) {
4846
+ return undefined;
4847
+ }
4848
+ const cache = caches.get(lifecycle || lines);
4849
+ return cache?.font === getFontKey(state) ? cache.widths.get(line) : undefined;
4850
+ };
4851
+ const updateHorizontalLayout = async state => {
4852
+ const {
4853
+ breakPoints = [],
4854
+ deltaX,
4855
+ gutterDecorations = [],
4856
+ largeFile,
4857
+ lifecycle,
4858
+ lightBulbRowIndex = -1,
4859
+ lineNumbers
4860
+ } = state;
4861
+ if (largeFile || lifecycle?.disposed) {
4862
+ return state;
4863
+ }
4864
+ const {
4865
+ charWidth,
4866
+ fontFamily,
4867
+ fontSize,
4868
+ fontWeight,
4869
+ isMonospaceFont,
4870
+ letterSpacing,
4871
+ lines,
4872
+ tabSize,
4873
+ width
4874
+ } = state;
4875
+ const font = getFontKey(state);
4876
+ const owner = lifecycle || lines;
4877
+ const previous = caches.get(owner);
4878
+ const previousWidths = previous?.font === font ? previous.widths : undefined;
4879
+ const widths = new Map();
4880
+ const textsToMeasure = new Set();
4881
+ const textByLine = new Map();
4882
+ for (const line of lines) {
4883
+ const measured = previousWidths?.get(line);
4884
+ if (measured !== undefined) {
4885
+ widths.set(line, measured);
4886
+ continue;
4887
+ }
4888
+ const text = line.replaceAll('\t', () => ' '.repeat(tabSize));
4889
+ textByLine.set(line, text);
4890
+ textsToMeasure.add(text);
4891
+ }
4892
+ const showGutter = lineNumbers || breakPoints.length > 0 || lightBulbRowIndex >= 0 || gutterDecorations.length > 0;
4893
+ const gutterText = String(lines.length);
4894
+ if (showGutter && !widths.has(gutterText)) {
4895
+ const measured = previousWidths?.get(gutterText);
4896
+ if (measured === undefined) {
4897
+ textsToMeasure.add(gutterText);
4898
+ } else {
4899
+ widths.set(gutterText, measured);
4900
+ }
4901
+ }
4902
+ const texts = [...textsToMeasure];
4903
+ const measuredWidths = texts.length > 0 ? await measureTextWidths(texts, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth) : [];
4904
+ const measuredByText = new Map(texts.map((text, index) => [text, measuredWidths[index]]));
4905
+ for (const [line, text] of textByLine) {
4906
+ widths.set(line, measuredByText.get(text));
4907
+ }
4908
+ if (showGutter && !widths.has(gutterText)) {
4909
+ widths.set(gutterText, measuredByText.get(gutterText));
4910
+ }
4911
+ let longestLineWidth = 0;
4912
+ for (const line of lines) {
4913
+ longestLineWidth = Math.max(longestLineWidth, widths.get(line));
4914
+ }
4915
+ if (lifecycle?.disposed) {
4916
+ return state;
4917
+ }
4918
+ const gutterWidth = showGutter ? Math.max(30, widths.get(gutterText) + 1) : 0;
4919
+ caches.set(owner, {
4920
+ font,
4921
+ widths
4922
+ });
4923
+ return {
4924
+ ...state,
4925
+ deltaX: clamp(deltaX, 0, Math.max(0, longestLineWidth - Math.max(0, width - gutterWidth))),
4926
+ gutterWidth,
4927
+ longestLineWidth
4928
+ };
4929
+ };
4930
+
4812
4931
  const fromRange = (startRowIndex, startColumnIndex, endRowIndex, endColumnIndex) => {
4813
4932
  return new Uint32Array([startRowIndex, startColumnIndex, endRowIndex, endColumnIndex]);
4814
4933
  };
@@ -4953,7 +5072,7 @@ const getVisible = async editor => {
4953
5072
  const relativeEndLineRow = getRelativeRow(selectionEndRow);
4954
5073
  const endLineDifference = horizontalOffset;
4955
5074
  const endLine = lines[selectionEndRow];
4956
- const endLineEndX = await getX(endLine, selectionEndColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, endLineDifference);
5075
+ const endLineEndX = await getX(endLine, selectionEndColumn, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, endLineDifference, getCachedLineWidth(editor, endLine));
4957
5076
  const endLineY = relativeEndLineRow * rowHeight;
4958
5077
  if (isEmpty$1(selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) && endLineEndX > 0) {
4959
5078
  visibleCursors.push(endLineEndX, endLineY);
@@ -5230,7 +5349,7 @@ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionCh
5230
5349
  ...newEditor,
5231
5350
  decorations: linkDecorations
5232
5351
  };
5233
- set$b(editor.uid, editor, newEditorWithDecorations);
5352
+ set$a(editor.uid, editor, newEditorWithDecorations);
5234
5353
 
5235
5354
  // Notify main-area-worker about modified status change
5236
5355
  if (!editor.modified) {
@@ -6066,88 +6185,6 @@ const getVisibleBracketMatches = async editor => {
6066
6185
  return infos.filter(info => info !== undefined);
6067
6186
  };
6068
6187
 
6069
- // Owned by the editor lifecycle, with only the current document's distinct lines retained.
6070
- const caches = new WeakMap();
6071
- const updateHorizontalLayout = async state => {
6072
- const {
6073
- breakPoints = [],
6074
- deltaX,
6075
- gutterDecorations = [],
6076
- largeFile,
6077
- lifecycle,
6078
- lightBulbRowIndex = -1,
6079
- lineNumbers
6080
- } = state;
6081
- if (largeFile || lifecycle?.disposed) {
6082
- return state;
6083
- }
6084
- const {
6085
- charWidth,
6086
- fontFamily,
6087
- fontSize,
6088
- fontWeight,
6089
- isMonospaceFont,
6090
- letterSpacing,
6091
- lines,
6092
- tabSize,
6093
- width
6094
- } = state;
6095
- const font = JSON.stringify([charWidth, fontFamily, fontSize, fontWeight, isMonospaceFont, letterSpacing, tabSize]);
6096
- const owner = lifecycle || lines;
6097
- const previous = caches.get(owner);
6098
- const previousWidths = previous?.font === font ? previous.widths : undefined;
6099
- const widths = new Map();
6100
- const textsToMeasure = new Set();
6101
- const textByLine = new Map();
6102
- for (const line of lines) {
6103
- const measured = previousWidths?.get(line);
6104
- if (measured !== undefined) {
6105
- widths.set(line, measured);
6106
- continue;
6107
- }
6108
- const text = line.replaceAll('\t', () => ' '.repeat(tabSize));
6109
- textByLine.set(line, text);
6110
- textsToMeasure.add(text);
6111
- }
6112
- const showGutter = lineNumbers || breakPoints.length > 0 || lightBulbRowIndex >= 0 || gutterDecorations.length > 0;
6113
- const gutterText = String(lines.length);
6114
- if (showGutter && !widths.has(gutterText)) {
6115
- const measured = previousWidths?.get(gutterText);
6116
- if (measured === undefined) {
6117
- textsToMeasure.add(gutterText);
6118
- } else {
6119
- widths.set(gutterText, measured);
6120
- }
6121
- }
6122
- const texts = [...textsToMeasure];
6123
- const measuredWidths = texts.length > 0 ? await measureTextWidths(texts, fontWeight, fontSize, fontFamily, letterSpacing, isMonospaceFont, charWidth) : [];
6124
- const measuredByText = new Map(texts.map((text, index) => [text, measuredWidths[index]]));
6125
- for (const [line, text] of textByLine) {
6126
- widths.set(line, measuredByText.get(text));
6127
- }
6128
- if (showGutter && !widths.has(gutterText)) {
6129
- widths.set(gutterText, measuredByText.get(gutterText));
6130
- }
6131
- let longestLineWidth = 0;
6132
- for (const line of lines) {
6133
- longestLineWidth = Math.max(longestLineWidth, widths.get(line));
6134
- }
6135
- if (lifecycle?.disposed) {
6136
- return state;
6137
- }
6138
- const gutterWidth = showGutter ? Math.max(30, widths.get(gutterText) + 1) : 0;
6139
- caches.set(owner, {
6140
- font,
6141
- widths
6142
- });
6143
- return {
6144
- ...state,
6145
- deltaX: clamp(deltaX, 0, Math.max(0, longestLineWidth - Math.max(0, width - gutterWidth))),
6146
- gutterWidth,
6147
- longestLineWidth
6148
- };
6149
- };
6150
-
6151
6188
  const shouldUpdateDiagnosticData = (oldState, newState) => {
6152
6189
  return oldState.diagnostics !== newState.diagnostics || (newState.diagnostics?.length ?? 0) > 0 && (oldState.deltaX !== newState.deltaX || oldState.minLineY !== newState.minLineY || oldState.charWidth !== newState.charWidth || oldState.fontFamily !== newState.fontFamily || oldState.fontSize !== newState.fontSize || oldState.fontWeight !== newState.fontWeight || oldState.isMonospaceFont !== newState.isMonospaceFont || oldState.letterSpacing !== newState.letterSpacing || oldState.lines !== newState.lines || oldState.rowHeight !== newState.rowHeight || oldState.tabSize !== newState.tabSize || oldState.width !== newState.width);
6153
6190
  };
@@ -6288,7 +6325,7 @@ const updateColorPickerValue = async (editorUid, value) => {
6288
6325
  return;
6289
6326
  }
6290
6327
  const newEditorWithDerivedState = await updateDerivedState(editor, newEditor);
6291
- set$b(editorUid, editor, newEditorWithDerivedState);
6328
+ set$a(editorUid, editor, newEditorWithDerivedState);
6292
6329
  };
6293
6330
 
6294
6331
  const getColorPickerWorkerCommandMap = () => ({
@@ -6500,7 +6537,7 @@ const createEditor2 = (id, uri, x, y, width, height, platform, assetDir, _langua
6500
6537
  x,
6501
6538
  y
6502
6539
  };
6503
- set$b(id, editor, editor);
6540
+ set$a(id, editor, editor);
6504
6541
  };
6505
6542
 
6506
6543
  const emptyEditor = {
@@ -6843,16 +6880,17 @@ const createEditor = async ({
6843
6880
  focused: true,
6844
6881
  textInfos
6845
6882
  };
6846
- set$b(id, emptyEditor, newEditor4);
6883
+ set$a(id, emptyEditor, newEditor4);
6847
6884
  const completionsOnTypeRaw = await get$3('editor.completionsOnType');
6848
6885
  const completionsOnType = Boolean(completionsOnTypeRaw);
6849
- set$b(id, emptyEditor, {
6886
+ set$a(id, emptyEditor, {
6850
6887
  ...newEditor4,
6851
6888
  completionsOnType
6852
6889
  });
6853
6890
  };
6854
6891
 
6855
6892
  const createStandaloneEditor = async ({
6893
+ applicationId,
6856
6894
  assetDir,
6857
6895
  charWidth,
6858
6896
  content,
@@ -6873,11 +6911,10 @@ const createStandaloneEditor = async ({
6873
6911
  x,
6874
6912
  y
6875
6913
  }) => {
6876
- createEditor2(id, uri, x, y, width, height, platform, assetDir);
6914
+ createEditor2(id, uri, x, y, width, height, platform, assetDir, undefined, undefined, undefined, applicationId);
6877
6915
  const createdEditor = get$8(id).newState;
6878
6916
  await loadTokenizer(languageId, tokenizePath);
6879
- const tokenizerId = createdEditor.tokenizerId + 1;
6880
- set$6(tokenizerId, getTokenizer(languageId));
6917
+ const tokenizerId = register(getTokenizer(languageId));
6881
6918
  const configuredEditor = {
6882
6919
  ...createdEditor,
6883
6920
  charWidth,
@@ -6922,7 +6959,7 @@ const createStandaloneEditor = async ({
6922
6959
  selectionInfos
6923
6960
  };
6924
6961
  if (!createdEditor.lifecycle?.disposed) {
6925
- set$b(id, createdEditor, finalEditor);
6962
+ set$a(id, createdEditor, finalEditor);
6926
6963
  }
6927
6964
  };
6928
6965
 
@@ -7425,7 +7462,7 @@ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGe
7425
7462
  };
7426
7463
  if (fullFocus) {
7427
7464
  // Staging changes pending state; only rendering may advance the mounted baseline.
7428
- set$b(editor.uid, get$8(editor.uid)?.oldState || editor, stagedEditor);
7465
+ set$a(editor.uid, get$8(editor.uid)?.oldState || editor, stagedEditor);
7429
7466
  }
7430
7467
  const newState = await newStateGenerator(initialState, editor.uid);
7431
7468
  if (!newState) {
@@ -7435,7 +7472,7 @@ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGe
7435
7472
  if (fullFocus) {
7436
7473
  const latestEditor = getLatestEditor(editor.uid, stagedEditor);
7437
7474
  if (latestEditor === stagedEditor) {
7438
- set$b(editor.uid, get$8(editor.uid)?.oldState || editor, editor);
7475
+ set$a(editor.uid, get$8(editor.uid)?.oldState || editor, editor);
7439
7476
  }
7440
7477
  return latestEditor === stagedEditor ? editor : latestEditor;
7441
7478
  }
@@ -7456,7 +7493,7 @@ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGe
7456
7493
  } : currentEditor;
7457
7494
  const hydratedEditor = hydrateWidget(latestEditor, widgetId, widgetUid, latestState);
7458
7495
  if (hydratedEditor !== latestEditor) {
7459
- set$b(editor.uid, get$8(editor.uid)?.oldState || editor, hydratedEditor);
7496
+ set$a(editor.uid, get$8(editor.uid)?.oldState || editor, hydratedEditor);
7460
7497
  }
7461
7498
  return hydratedEditor;
7462
7499
  }
@@ -8562,7 +8599,7 @@ const editorShowMessage = async (editor, rowIndex, columnIndex, message, _isErro
8562
8599
  widgetRevision: next(editor.uid),
8563
8600
  widgets: removeEditorWidget(latestEditor.widgets, Message)
8564
8601
  };
8565
- set$b(editor.uid, latestEditor, editorWithoutMessage);
8602
+ set$a(editor.uid, latestEditor, editorWithoutMessage);
8566
8603
  await invoke$e('Editor.renderPending', editor.uid);
8567
8604
  }, editor.messageDelay ?? defaultMessageDelay);
8568
8605
  set$3(editor.uid, {
@@ -8756,7 +8793,7 @@ const refresh = async request => {
8756
8793
  if (!isCurrent(latest?.newState, snapshot)) {
8757
8794
  return false;
8758
8795
  }
8759
- set$b(snapshot.uid, latest.oldState, next);
8796
+ set$a(snapshot.uid, latest.oldState, next);
8760
8797
  return true;
8761
8798
  });
8762
8799
  if (changed) {
@@ -8838,107 +8875,110 @@ const saveAfterDelay = async (uid, token) => {
8838
8875
  // TODO wrap commands globally, not per editor
8839
8876
  // TODO only store editor state in editor worker, not in renderer worker also
8840
8877
 
8841
- const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true) => async (uid, ...args) => {
8842
- return enqueue(uid, async () => {
8843
- const oldInstance = get$8(uid);
8844
- if (!oldInstance) {
8845
- return undefined;
8846
- }
8847
- const state = oldInstance.newState;
8848
- const {
8849
- cursorUndoStack,
8850
- endOfLine,
8851
- initial,
8852
- insertSpaces,
8853
- isSelecting,
8854
- lifecycle,
8855
- lines,
8856
- modified,
8857
- redoStack,
8858
- selections,
8859
- undoStack,
8860
- uri
8861
- } = state;
8862
- const commandResult = await fn(state, ...args);
8863
- let newEditor = !preservesTypingCoalescing && commandResult.canCoalesceTyping ? {
8864
- ...commandResult,
8865
- canCoalesceTyping: false
8866
- } : commandResult;
8867
- if (lines !== newEditor.lines && newEditor.cursorUndoStack?.length) {
8868
- newEditor = {
8869
- ...newEditor,
8870
- cursorUndoStack: []
8871
- };
8872
- } else if (selections && newEditor.selections && !isSelecting && newEditor.cursorUndoStack === cursorUndoStack && (!selectionsEqual(selections, newEditor.selections) || newEditor.isSelecting)) {
8873
- const previousCursorUndoStack = cursorUndoStack || [];
8874
- newEditor = {
8875
- ...newEditor,
8876
- cursorUndoStack: [...previousCursorUndoStack.slice(1 - cursorUndoLimit), new Uint32Array(selections)]
8877
- };
8878
- }
8879
- if (state === newEditor || !get$8(uid) || lifecycle?.disposed || get$8(uid).newState.lifecycle !== lifecycle) {
8880
- return returnState ? newEditor : undefined;
8881
- }
8882
- const deferGutterDecorations = !initial && uri === newEditor.uri && lines !== newEditor.lines && Boolean(newEditor.lifecycle);
8883
- const newEditorWithDerivedState = await updateDerivedState(state, newEditor, deferGutterDecorations);
8884
- if (!get$8(uid) || lifecycle?.disposed || get$8(uid).newState.lifecycle !== lifecycle) {
8885
- return returnState ? newEditorWithDerivedState : undefined;
8886
- }
8887
- // Another command can commit before the renderer consumes this edit.
8888
- // Keep its last rendered baseline, including renders completed while we awaited derived state.
8889
- const renderedState = get$8(uid)?.oldState ?? oldInstance.oldState;
8890
- set$b(uid, renderedState, newEditorWithDerivedState);
8891
- await dispose$3();
8892
- if (editorDiagnosticEffect.isActive(state, newEditorWithDerivedState)) {
8893
- void editorDiagnosticEffect.apply(newEditorWithDerivedState);
8894
- }
8895
- const finalEditor = newEditorWithDerivedState;
8896
- if (deferGutterDecorations) {
8897
- schedule(finalEditor);
8898
- }
8899
- await notifyEditorStatusChange(state, finalEditor);
8900
- if (!initial && uri === finalEditor.uri && (endOfLine !== finalEditor.endOfLine || insertSpaces !== finalEditor.insertSpaces || lines !== finalEditor.lines || modified !== finalEditor.modified || redoStack !== finalEditor.redoStack || undoStack !== finalEditor.undoStack)) {
8901
- for (const key of getKeys$2()) {
8902
- const otherUid = Number(key);
8903
- const instance = get$8(otherUid);
8904
- const editor = instance?.newState;
8905
- if (otherUid === uid || !instance || !editor || editor.initial || editor.uri !== finalEditor.uri || editor.applicationId !== finalEditor.applicationId) {
8906
- continue;
8907
- }
8908
- const synchronizedEditor = await updateDerivedState(editor, {
8909
- ...editor,
8910
- decorations: finalEditor.decorations,
8911
- diagnostics: finalEditor.diagnostics,
8912
- endOfLine: finalEditor.endOfLine,
8913
- incrementalEdits: emptyIncrementalEdits,
8914
- insertSpaces: finalEditor.insertSpaces,
8915
- invalidStartIndex: Math.min(editor.invalidStartIndex, finalEditor.invalidStartIndex),
8916
- lines: finalEditor.lines,
8917
- modified: finalEditor.modified,
8918
- redoStack: finalEditor.redoStack,
8919
- undoStack: finalEditor.undoStack,
8920
- visualDecorations: finalEditor.visualDecorations
8921
- }, deferGutterDecorations);
8922
- const latest = get$8(otherUid);
8923
- if (!latest || editor.lifecycle?.disposed || latest.newState.lifecycle !== editor.lifecycle) {
8924
- continue;
8925
- }
8926
- set$b(otherUid, latest.oldState, synchronizedEditor);
8927
- if (deferGutterDecorations) {
8928
- schedule(synchronizedEditor);
8929
- }
8930
- if (editorDiagnosticEffect.isActive(editor, synchronizedEditor)) {
8931
- void editorDiagnosticEffect.apply(synchronizedEditor);
8878
+ const wrapCommand$1 = (fn, preservesTypingCoalescing = false, returnState = true) => {
8879
+ const command = async (uid, ...args) => {
8880
+ return enqueue(uid, async () => {
8881
+ const oldInstance = get$8(uid);
8882
+ if (!oldInstance) {
8883
+ return undefined;
8884
+ }
8885
+ const state = oldInstance.newState;
8886
+ const {
8887
+ cursorUndoStack,
8888
+ endOfLine,
8889
+ initial,
8890
+ insertSpaces,
8891
+ isSelecting,
8892
+ lifecycle,
8893
+ lines,
8894
+ modified,
8895
+ redoStack,
8896
+ selections,
8897
+ undoStack,
8898
+ uri
8899
+ } = state;
8900
+ const commandResult = await fn(state, ...args);
8901
+ let newEditor = !preservesTypingCoalescing && commandResult.canCoalesceTyping ? {
8902
+ ...commandResult,
8903
+ canCoalesceTyping: false
8904
+ } : commandResult;
8905
+ if (lines !== newEditor.lines && newEditor.cursorUndoStack?.length) {
8906
+ newEditor = {
8907
+ ...newEditor,
8908
+ cursorUndoStack: []
8909
+ };
8910
+ } else if (selections && newEditor.selections && !isSelecting && newEditor.cursorUndoStack === cursorUndoStack && (!selectionsEqual(selections, newEditor.selections) || newEditor.isSelecting)) {
8911
+ const previousCursorUndoStack = cursorUndoStack || [];
8912
+ newEditor = {
8913
+ ...newEditor,
8914
+ cursorUndoStack: [...previousCursorUndoStack.slice(1 - cursorUndoLimit), new Uint32Array(selections)]
8915
+ };
8916
+ }
8917
+ if (state === newEditor || !get$8(uid) || lifecycle?.disposed || get$8(uid).newState.lifecycle !== lifecycle) {
8918
+ return returnState ? newEditor : undefined;
8919
+ }
8920
+ const deferGutterDecorations = !initial && uri === newEditor.uri && lines !== newEditor.lines && Boolean(newEditor.lifecycle);
8921
+ const newEditorWithDerivedState = await updateDerivedState(state, newEditor, deferGutterDecorations);
8922
+ if (!get$8(uid) || lifecycle?.disposed || get$8(uid).newState.lifecycle !== lifecycle) {
8923
+ return returnState ? newEditorWithDerivedState : undefined;
8924
+ }
8925
+ // Another command can commit before the renderer consumes this edit.
8926
+ // Keep its last rendered baseline, including renders completed while we awaited derived state.
8927
+ const renderedState = get$8(uid)?.oldState ?? oldInstance.oldState;
8928
+ set$a(uid, renderedState, newEditorWithDerivedState);
8929
+ await dispose$3();
8930
+ if (editorDiagnosticEffect.isActive(state, newEditorWithDerivedState)) {
8931
+ void editorDiagnosticEffect.apply(newEditorWithDerivedState);
8932
+ }
8933
+ const finalEditor = newEditorWithDerivedState;
8934
+ if (deferGutterDecorations) {
8935
+ schedule(finalEditor);
8936
+ }
8937
+ await notifyEditorStatusChange(state, finalEditor);
8938
+ if (!initial && uri === finalEditor.uri && (endOfLine !== finalEditor.endOfLine || insertSpaces !== finalEditor.insertSpaces || lines !== finalEditor.lines || modified !== finalEditor.modified || redoStack !== finalEditor.redoStack || undoStack !== finalEditor.undoStack)) {
8939
+ for (const key of getKeys$2()) {
8940
+ const otherUid = Number(key);
8941
+ const instance = get$8(otherUid);
8942
+ const editor = instance?.newState;
8943
+ if (otherUid === uid || !instance || !editor || editor.initial || editor.uri !== finalEditor.uri || editor.applicationId !== finalEditor.applicationId) {
8944
+ continue;
8945
+ }
8946
+ const synchronizedEditor = await updateDerivedState(editor, {
8947
+ ...editor,
8948
+ decorations: finalEditor.decorations,
8949
+ diagnostics: finalEditor.diagnostics,
8950
+ endOfLine: finalEditor.endOfLine,
8951
+ incrementalEdits: emptyIncrementalEdits,
8952
+ insertSpaces: finalEditor.insertSpaces,
8953
+ invalidStartIndex: Math.min(editor.invalidStartIndex, finalEditor.invalidStartIndex),
8954
+ lines: finalEditor.lines,
8955
+ modified: finalEditor.modified,
8956
+ redoStack: finalEditor.redoStack,
8957
+ undoStack: finalEditor.undoStack,
8958
+ visualDecorations: finalEditor.visualDecorations
8959
+ }, deferGutterDecorations);
8960
+ const latest = get$8(otherUid);
8961
+ if (!latest || editor.lifecycle?.disposed || latest.newState.lifecycle !== editor.lifecycle) {
8962
+ continue;
8963
+ }
8964
+ set$a(otherUid, latest.oldState, synchronizedEditor);
8965
+ if (deferGutterDecorations) {
8966
+ schedule(synchronizedEditor);
8967
+ }
8968
+ if (editorDiagnosticEffect.isActive(editor, synchronizedEditor)) {
8969
+ void editorDiagnosticEffect.apply(synchronizedEditor);
8970
+ }
8932
8971
  }
8933
8972
  }
8934
- }
8935
- if (lines !== finalEditor.lines && !isUntitledFile(finalEditor.uri)) {
8936
- schedule$1(uid, token => saveAfterDelay(uid, token));
8937
- } else if (modified && !finalEditor.modified) {
8938
- dispose$4(uid);
8939
- }
8940
- return returnState ? finalEditor : undefined;
8941
- });
8973
+ if (lines !== finalEditor.lines && !isUntitledFile(finalEditor.uri)) {
8974
+ schedule$1(uid, token => saveAfterDelay(uid, token));
8975
+ } else if (modified && !finalEditor.modified) {
8976
+ dispose$4(uid);
8977
+ }
8978
+ return returnState ? finalEditor : undefined;
8979
+ });
8980
+ };
8981
+ return command;
8942
8982
  };
8943
8983
  const wrapFocusCommand$1 = (fn, returnState = true) => {
8944
8984
  const command = wrapCommand$1((editor, widgetRevision) => {
@@ -8947,18 +8987,19 @@ const wrapFocusCommand$1 = (fn, returnState = true) => {
8947
8987
  }
8948
8988
  return fn(editor);
8949
8989
  }, false, returnState);
8950
- return uid => {
8990
+ const focusCommand = uid => {
8951
8991
  // DOM focus events can arrive while a queued command is still opening a widget.
8952
8992
  const widgetRevision = get$8(uid)?.newState.widgetRevision;
8953
8993
  return command(uid, widgetRevision);
8954
8994
  };
8995
+ return focusCommand;
8955
8996
  };
8956
8997
 
8957
8998
  // Mouse positions are replaceable; edits and explicit navigation remain ordered.
8958
8999
  // Check before starting provider work and again before committing its result.
8959
9000
  const wrapLatestCommand$1 = (fn, returnState = true) => {
8960
9001
  const latest = new Map();
8961
- return async (uid, ...args) => {
9002
+ const latestCommand = async (uid, ...args) => {
8962
9003
  const token = {};
8963
9004
  latest.set(uid, token);
8964
9005
  const command = wrapCommand$1(async editor => {
@@ -8972,12 +9013,13 @@ const wrapLatestCommand$1 = (fn, returnState = true) => {
8972
9013
  if (latest.get(uid) === token) latest.delete(uid);
8973
9014
  }
8974
9015
  };
9016
+ return latestCommand;
8975
9017
  };
8976
9018
 
8977
9019
  // Optional provider work must not hold the editing queue while another worker responds.
8978
9020
  const wrapDeferredCommand$1 = (fn, returnState = true) => {
8979
9021
  const apply = wrapCommand$1((editor, snapshot, result) => merge(editor, snapshot, result), false, returnState);
8980
- return async (uid, ...args) => {
9022
+ const deferredCommand = async (uid, ...args) => {
8981
9023
  const snapshot = await enqueue(uid, async () => get$8(uid)?.newState);
8982
9024
  if (!snapshot) {
8983
9025
  return undefined;
@@ -8985,6 +9027,7 @@ const wrapDeferredCommand$1 = (fn, returnState = true) => {
8985
9027
  const result = await fn(snapshot, ...args);
8986
9028
  return apply(uid, snapshot, result);
8987
9029
  };
9030
+ return deferredCommand;
8988
9031
  };
8989
9032
 
8990
9033
  // TODO maybe use a separate worker for bulk edits and bulk edit history
@@ -11584,7 +11627,7 @@ const handleMouseLeave = (viewletUid, editorUidValue) => {
11584
11627
  widgetRevision: next(editorUid),
11585
11628
  widgets: removeEditorWidget(latestEditor.widgets, Hover)
11586
11629
  };
11587
- set$b(editorUid, latestEditor, newEditor);
11630
+ set$a(editorUid, latestEditor, newEditor);
11588
11631
  await invoke$e('Editor.renderPending', editorUid);
11589
11632
  }, editorHoverDismissDelay);
11590
11633
  set$5(editorUid, {
@@ -11994,7 +12037,7 @@ const showHover = async (editor, position, token) => {
11994
12037
  if (latestEditor === newEditor || !latestInstance || latestInstance.newState !== latestEditor || get$2().token !== token) {
11995
12038
  return;
11996
12039
  }
11997
- set$b(editor.uid, latestInstance.oldState, newEditor);
12040
+ set$a(editor.uid, latestInstance.oldState, newEditor);
11998
12041
  await invoke$e('Editor.renderPending', editor.uid);
11999
12042
  };
12000
12043
 
@@ -12256,7 +12299,7 @@ const continueScrollingAndMovingSelection = async editorUid => {
12256
12299
  }
12257
12300
  return;
12258
12301
  }
12259
- set$b(editor.uid, editor, derivedEditor);
12302
+ set$a(editor.uid, editor, derivedEditor);
12260
12303
  await invoke$e('Editor.renderPending', editor.uid);
12261
12304
  if (derivedEditor.hasListener) {
12262
12305
  requestAnimationFrame(() => continueScrollingAndMovingSelection(editorUid));
@@ -12969,7 +13012,7 @@ const updateEditor = async (editorUid, editor, newEditor) => {
12969
13012
  return;
12970
13013
  }
12971
13014
  const newEditorWithDerivedState = await updateDerivedState(editor, newEditor);
12972
- set$b(editorUid, editor, newEditorWithDerivedState);
13015
+ set$a(editorUid, editor, newEditorWithDerivedState);
12973
13016
  };
12974
13017
  const applyDocumentEdits = async (editorUid, edits) => {
12975
13018
  const editor = getEditor$1(editorUid);
@@ -13019,7 +13062,7 @@ const launch = async () => {
13019
13062
  return;
13020
13063
  }
13021
13064
  const rpc = await launchFindWidgetWorker();
13022
- set$k(rpcId, rpc);
13065
+ set$j(rpcId, rpc);
13023
13066
  };
13024
13067
  const invoke$4 = async (method, ...params) => {
13025
13068
  const rpc = get$9(rpcId);
@@ -13150,7 +13193,7 @@ const createFn = (key, name, widgetId) => {
13150
13193
  const latestAfterInvoke = get$8(editor.uid).newState;
13151
13194
  const latestChildIndex = latestAfterInvoke.widgets.findIndex(isWidget);
13152
13195
  if (latestChildIndex === -1) {
13153
- set$b(editor.uid, editor, latestAfterInvoke);
13196
+ set$a(editor.uid, editor, latestAfterInvoke);
13154
13197
  await dispose$3();
13155
13198
  return latestAfterInvoke;
13156
13199
  }
@@ -13164,7 +13207,7 @@ const createFn = (key, name, widgetId) => {
13164
13207
  widgetRevision,
13165
13208
  widgets: removeEditorWidget(latest.widgets, widgetId)
13166
13209
  };
13167
- set$b(editor.uid, latest, newEditor);
13210
+ set$a(editor.uid, latest, newEditor);
13168
13211
  return newEditor;
13169
13212
  }
13170
13213
  const newState = {
@@ -13172,7 +13215,7 @@ const createFn = (key, name, widgetId) => {
13172
13215
  commands
13173
13216
  };
13174
13217
  const newEditor = updateWidget(latest, widgetId, newState);
13175
- set$b(editor.uid, editor, newEditor);
13218
+ set$a(editor.uid, editor, newEditor);
13176
13219
  return newEditor;
13177
13220
  };
13178
13221
  return fn;
@@ -14230,13 +14273,9 @@ const setLanguageId = async (editor, languageId, tokenizePath, isExplicit = fals
14230
14273
  languageId
14231
14274
  };
14232
14275
  }
14233
- const {
14234
- tokenizerId
14235
- } = editor;
14236
14276
  await loadTokenizer(languageId, tokenizePath);
14237
14277
  const tokenizer = getTokenizer(languageId);
14238
- const newTokenizerId = tokenizerId + 1;
14239
- set$6(newTokenizerId, tokenizer);
14278
+ const newTokenizerId = register(tokenizer);
14240
14279
  return {
14241
14280
  ...editor,
14242
14281
  explicitLanguageId: isExplicit ? languageId : editor.explicitLanguageId,
@@ -16262,7 +16301,7 @@ const setSelections2 = async (editorUid, selections) => {
16262
16301
  if (!current || lifecycle?.disposed || current.newState.lifecycle !== lifecycle) {
16263
16302
  return;
16264
16303
  }
16265
- set$b(editorUid, current.oldState, newEditorWithDerivedState);
16304
+ set$a(editorUid, current.oldState, newEditorWithDerivedState);
16266
16305
  });
16267
16306
  };
16268
16307
  const closeWidget2 = async (editorUid, widgetId, widgetName, unsetAdditionalFocus$1) => {
@@ -16287,7 +16326,7 @@ const closeWidget2 = async (editorUid, widgetId, widgetName, unsetAdditionalFocu
16287
16326
  widgets: newWidgets
16288
16327
  };
16289
16328
  const newEditorWithDerivedState = await updateDerivedState(editor, newEditor);
16290
- set$b(editorUid, editor, newEditorWithDerivedState);
16329
+ set$a(editorUid, editor, newEditorWithDerivedState);
16291
16330
  await setFocus(FocusEditorText);
16292
16331
  if (unsetAdditionalFocus$1) {
16293
16332
  await unsetAdditionalFocus(unsetAdditionalFocus$1);
@@ -16315,6 +16354,17 @@ const ensure = async (fontName, fontUrl) => {
16315
16354
  await invoke$f('TextMeasurement.ensureFont', fontName, fontUrl);
16316
16355
  };
16317
16356
 
16357
+ const getComponentState = uid => {
16358
+ const {
16359
+ newState
16360
+ } = get$8(uid);
16361
+ return {
16362
+ ...newState,
16363
+ cursorUndoStack: newState.cursorUndoStack?.map(selection => [...selection]),
16364
+ selections: [...newState.selections]
16365
+ };
16366
+ };
16367
+
16318
16368
  const findWidgetFocusContexts = [FindWidget, FocusFindWidgetReplace$1, FocusFindWidgetOptions, FocusFindWidgetToggleReplace, FocusFindWidgetPreviousMatchButton, FocusFindWidgetNextMatchButton, FocusFindWidgetCloseButton, FocusFindWidgetReplaceButton, FocusFindWidgetReplaceAllButton];
16319
16369
  const getFindWidgetFocusKeyBindings = () => {
16320
16370
  return findWidgetFocusContexts.flatMap(focusContext => [{
@@ -16972,7 +17022,7 @@ const handleBeforeInput = (editor, inputType, data) => {
16972
17022
  };
16973
17023
 
16974
17024
  // These commands have renderer-owned effects in addition to editor state updates.
16975
- const rendererCommands = new Set(['ColorPicker.handleSliderKeyDown', 'handleFocus', 'handleUriChange', 'handleWorkspaceRefresh', 'hotReload', 'loadContent', 'loadContentLater', 'refreshGutterDecorationsAll', 'renderPending', 'setLanguageId', 'showOverlayMessage', 'updateDiagnostics']);
17025
+ const rendererCommands = new Set(['ColorPicker.handleSliderKeyDown', 'handleFocus', 'handleMouseDown', 'handleUriChange', 'handleWorkspaceRefresh', 'hotReload', 'loadContent', 'loadContentLater', 'refreshGutterDecorationsAll', 'renderPending', 'setLanguageId', 'showOverlayMessage', 'updateDiagnostics']);
16976
17026
  const createCommandMap = commands => ({
16977
17027
  async 'Viewlet.executeViewletCommand'(uid, command, ...args) {
16978
17028
  if (rendererCommands.has(command)) {
@@ -17022,7 +17072,7 @@ const handleMessagePort = async (port, rpcId) => {
17022
17072
  messagePort: port
17023
17073
  });
17024
17074
  if (rpcId) {
17025
- set$k(rpcId, rpc);
17075
+ set$j(rpcId, rpc);
17026
17076
  await initializeListener(rpcId);
17027
17077
  }
17028
17078
  };
@@ -17461,7 +17511,7 @@ const hotReload = async () => {
17461
17511
  await relaunchWorkers();
17462
17512
  const newEditors = await restoreWidgetState(keys, savedStates);
17463
17513
  for (const editor of newEditors) {
17464
- set$b(editor.newState.uid, editor.oldState, editor.newState);
17514
+ set$a(editor.newState.uid, editor.oldState, editor.newState);
17465
17515
  }
17466
17516
 
17467
17517
  // TODO ask renderer worker to rerender all editors
@@ -17499,7 +17549,7 @@ const initializeSyntaxHighlighting = async (syntaxHighlightingEnabled, syncIncre
17499
17549
  if (syntaxHighlightingEnabled) {
17500
17550
  setEnabled$1(true);
17501
17551
  const syntaxRpc = await createSyntaxHighlightingWorkerRpc();
17502
- set$9(syntaxRpc);
17552
+ set$8(syntaxRpc);
17503
17553
  }
17504
17554
  if (syncIncremental) {
17505
17555
  setEnabled(true);
@@ -17807,8 +17857,7 @@ const loadContent = async (state, savedState, largeFile = false, focus = true, f
17807
17857
  const tokenizePath = getTokenizePath(languages, computedLanguageId);
17808
17858
  await loadTokenizer(computedLanguageId, tokenizePath);
17809
17859
  const tokenizer = getTokenizer(computedLanguageId);
17810
- const newTokenizerId = state.tokenizerId + 1;
17811
- set$6(newTokenizerId, tokenizer);
17860
+ const newTokenizerId = register(tokenizer);
17812
17861
  effectiveEditor.tokenizerId = newTokenizerId;
17813
17862
  }
17814
17863
  const savedHistory = existingEditor ? undefined : getSavedHistory(savedState, content);
@@ -17954,7 +18003,7 @@ const refreshGutterDecorationsAll = async () => {
17954
18003
  if (!latest) {
17955
18004
  continue;
17956
18005
  }
17957
- set$b(editor.id, latest.oldState, {
18006
+ set$a(editor.id, latest.oldState, {
17958
18007
  ...latest.newState,
17959
18008
  gutterDecorations: refreshedEditor.gutterDecorations
17960
18009
  });
@@ -19288,7 +19337,7 @@ const render2 = (uid, _diffResult) => {
19288
19337
  } = editor;
19289
19338
  // Diagnostics can change after the caller calculated its diff in a separate RPC.
19290
19339
  const diffResult = diff(oldState, newState);
19291
- set$b(uid, newState, newState);
19340
+ set$a(uid, newState, newState);
19292
19341
  const commands = applyRender(oldState, newState, diffResult);
19293
19342
  return commands;
19294
19343
  };
@@ -19323,7 +19372,7 @@ const renderDirect = async (uid, preserveFocus) => {
19323
19372
  const latest = get$8(uid);
19324
19373
  if (latest?.newState.lifecycle === newState.lifecycle && latest.oldState === newState) {
19325
19374
  // A rejected queue RPC must not acknowledge patches that never arrived.
19326
- set$b(uid, oldState, latest.newState);
19375
+ set$a(uid, oldState, latest.newState);
19327
19376
  if (oldDom) set$2(uid, oldDom, oldPaths);else dispose$2(uid);
19328
19377
  }
19329
19378
  throw error;
@@ -19453,7 +19502,7 @@ const renderEditor = async id => {
19453
19502
  oldState
19454
19503
  } = instance;
19455
19504
  const commands = [];
19456
- set$b(id, newState, newState);
19505
+ set$a(id, newState, newState);
19457
19506
  for (const item of render$7) {
19458
19507
  if (item.isEqual(oldState, newState)) {
19459
19508
  continue;
@@ -19679,6 +19728,62 @@ const sendDeprecatedExtensionHostPortToExtensionManagementWorker = async (port,
19679
19728
  await sendMessagePortToExtensionManagementWorker$1(port, rpcId);
19680
19729
  };
19681
19730
 
19731
+ const restoreSelections = value => {
19732
+ if (!Array.isArray(value) || value.length % 4 !== 0 || value.some(item => !Number.isSafeInteger(item) || item < 0 || item > 0xff_ff_ff_ff)) {
19733
+ throw new TypeError('Editor selections must be an array of unsigned integer ranges');
19734
+ }
19735
+ return new Uint32Array(value);
19736
+ };
19737
+ const applyComponentState = async (currentState, value) => {
19738
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
19739
+ throw new TypeError('Editor state must be an object');
19740
+ }
19741
+ const state = value;
19742
+ const {
19743
+ cursorUndoStack: jsonCursorUndoStack,
19744
+ lines,
19745
+ selections: jsonSelections
19746
+ } = state;
19747
+ for (const key of ['uid', 'id', 'uri']) {
19748
+ if (state[key] !== currentState[key]) {
19749
+ throw new Error(`Editor state ${key} must remain ${currentState[key]}`);
19750
+ }
19751
+ }
19752
+ if (!Array.isArray(lines) || lines.some(line => typeof line !== 'string')) {
19753
+ throw new TypeError('Editor lines must be an array of strings');
19754
+ }
19755
+ if (jsonCursorUndoStack !== undefined && !Array.isArray(jsonCursorUndoStack)) {
19756
+ throw new TypeError('Editor cursorUndoStack must be an array');
19757
+ }
19758
+ const selections = restoreSelections(jsonSelections);
19759
+ const cursorUndoStack = jsonCursorUndoStack?.map(restoreSelections);
19760
+ const normalized = {
19761
+ ...state,
19762
+ cursorUndoStack,
19763
+ selections
19764
+ };
19765
+ const currentJsonState = getComponentState(currentState.uid);
19766
+ // Keep unchanged collections so a JSON round trip does not invalidate every render cache.
19767
+ const entries = Object.entries(normalized).map(([key, entry]) => [key, JSON.stringify(state[key]) === JSON.stringify(currentJsonState[key]) ? currentState[key] : entry]);
19768
+ // A save can repeat an earlier live edit with its old text caches still in the JSON.
19769
+ const newState = {
19770
+ ...Object.fromEntries(entries),
19771
+ differences: currentState.differences,
19772
+ textInfos: currentState.textInfos
19773
+ };
19774
+ const updatedState = newState.lines === currentState.lines ? newState : {
19775
+ ...newState,
19776
+ incrementalEdits: emptyIncrementalEdits,
19777
+ invalidStartIndex: 0,
19778
+ numberOfLines: newState.lines.length
19779
+ };
19780
+ return updateDerivedState(currentState, updatedState);
19781
+ };
19782
+ const applyState = wrapCommand$2(applyComponentState);
19783
+ const setComponentState = (uid, value) => {
19784
+ return enqueue(uid, () => applyState(uid, value));
19785
+ };
19786
+
19682
19787
  const setDebugEnabled = (state, enabled) => {
19683
19788
  return state;
19684
19789
  };
@@ -19730,7 +19835,7 @@ const updateDebugInfo = async debugId => {
19730
19835
  ...newState,
19731
19836
  highlightedLine: newInfo.rowIndex
19732
19837
  };
19733
- set$b(key, oldState, newEditor);
19838
+ set$a(key, oldState, newEditor);
19734
19839
  // @ts-ignore
19735
19840
  await invoke$e('Editor.rerender', key);
19736
19841
  };
@@ -19777,7 +19882,7 @@ const wrapTypingCommand = (fn, shouldOpenCompletion, shouldDismissHover, preserv
19777
19882
  const newEditor = await fn(editor, ...args);
19778
19883
  return shouldDismissHover(...args) ? removeHoverFromEditor(newEditor) : newEditor;
19779
19884
  }, preservesTypingCoalescing);
19780
- return async (uid, ...args) => {
19885
+ const typingCommand = async (uid, ...args) => {
19781
19886
  const dismissHover = shouldDismissHover(...args);
19782
19887
  if (dismissHover) {
19783
19888
  clear$2(uid);
@@ -19789,6 +19894,7 @@ const wrapTypingCommand = (fn, shouldOpenCompletion, shouldDismissHover, preserv
19789
19894
  void updateAutomaticCompletionDeferred(uid).then(() => invoke$e('Editor.renderPending', uid)).catch(error => handleError$1(error, 'Failed to open completion widget: '));
19790
19895
  }
19791
19896
  };
19897
+ return typingCommand;
19792
19898
  };
19793
19899
  const deleteLeftCommand = wrapTypingCommand(deleteCharacterLeft, () => false, () => false);
19794
19900
  const typeCommand = wrapTypingCommand(type, () => true, Boolean);
@@ -19868,6 +19974,7 @@ const commandMap = {
19868
19974
  'Editor.format': wrapCommand(format),
19869
19975
  'Editor.getCommandIds': getCommandIds,
19870
19976
  'Editor.getCompletionContext': getCompletionContext,
19977
+ 'Editor.getComponentState': getComponentState,
19871
19978
  'Editor.getDiagnostics': getDiagnostics,
19872
19979
  'Editor.getKeyBindings': getKeyBindings,
19873
19980
  'Editor.getKeys': getKeys,
@@ -19990,6 +20097,7 @@ const commandMap = {
19990
20097
  'Editor.selectWord': wrapCommand(selectWord),
19991
20098
  'Editor.selectWordLeft': wrapCommand(selectWordLeft),
19992
20099
  'Editor.selectWordRight': wrapCommand(selectWordRight),
20100
+ 'Editor.setComponentState': setComponentState,
19993
20101
  'Editor.setDebugEnabled': wrapCommand(setDebugEnabled),
19994
20102
  'Editor.setDecorations': wrapCommand(setDecorations),
19995
20103
  'Editor.setDelta': wrapCommand(setDelta),
@@ -20120,7 +20228,7 @@ const initializeDragAndDropWorker = async () => {
20120
20228
  commandMap: {},
20121
20229
  send: sendMessagePortToDragAndDropWorker
20122
20230
  });
20123
- set$i(rpc);
20231
+ set$h(rpc);
20124
20232
  };
20125
20233
 
20126
20234
  const initializeErrorWorker = async () => {
@@ -20130,7 +20238,7 @@ const initializeErrorWorker = async () => {
20130
20238
  return sendMessagePortToErrorWorker(port, EditorWorker);
20131
20239
  }
20132
20240
  });
20133
- set$h(rpc);
20241
+ set$g(rpc);
20134
20242
  };
20135
20243
 
20136
20244
  const createExtensionManagementWorkerRpc = async () => {
@@ -20146,7 +20254,7 @@ const createExtensionManagementWorkerRpc = async () => {
20146
20254
  const initializeExtensionManagementWorker = async () => {
20147
20255
  try {
20148
20256
  const rpc = await createExtensionManagementWorkerRpc();
20149
- set$g(rpc);
20257
+ set$f(rpc);
20150
20258
  } catch {
20151
20259
  // ignore
20152
20260
  }
@@ -20161,14 +20269,14 @@ const initializeOpenerWorker = async () => {
20161
20269
  commandMap: {},
20162
20270
  send: send$1
20163
20271
  });
20164
- set$f(rpc);
20272
+ set$e(rpc);
20165
20273
  };
20166
20274
 
20167
20275
  const initializeRendererWorker = async () => {
20168
20276
  const rpc = await create$d({
20169
20277
  commandMap: commandMap
20170
20278
  });
20171
- set$d(rpc);
20279
+ set$c(rpc);
20172
20280
  };
20173
20281
 
20174
20282
  const send = port => {
@@ -20179,7 +20287,7 @@ const initializeTextMeasurementWorker = async () => {
20179
20287
  commandMap: {},
20180
20288
  send
20181
20289
  });
20182
- set$e(rpc);
20290
+ set$d(rpc);
20183
20291
  };
20184
20292
 
20185
20293
  const listen = async () => {
@@ -20189,7 +20297,7 @@ const listen = async () => {
20189
20297
  commandMap: {},
20190
20298
  send: sendMessagePortToDialogWorker
20191
20299
  });
20192
- set$j(dialogRpc);
20300
+ set$i(dialogRpc);
20193
20301
  };
20194
20302
 
20195
20303
  const CodeGeneratorInput = 'CodeGeneratorInput';
@@ -20511,15 +20619,15 @@ const EditorMessageWidget = {
20511
20619
  };
20512
20620
 
20513
20621
  const registerWidgets = () => {
20514
- set$a(ColorPicker$2, EditorColorPickerWidget);
20515
- set$a(Completion, EditorCompletionWidget);
20516
- set$a(CompletionDetail, EditorCompletionDetailWidget);
20517
- set$a(Find, EditorFindWidget);
20518
- set$a(Hover, EditorHoverWidget);
20519
- set$a(Message, EditorMessageWidget);
20520
- set$a(Rename$1, EditorRenameWidget);
20521
- set$a(SourceAction$1, EditorSourceActionWidget);
20522
- set$a(CodeGenerator, EditorCodeGeneratorWidget);
20622
+ set$9(ColorPicker$2, EditorColorPickerWidget);
20623
+ set$9(Completion, EditorCompletionWidget);
20624
+ set$9(CompletionDetail, EditorCompletionDetailWidget);
20625
+ set$9(Find, EditorFindWidget);
20626
+ set$9(Hover, EditorHoverWidget);
20627
+ set$9(Message, EditorMessageWidget);
20628
+ set$9(Rename$1, EditorRenameWidget);
20629
+ set$9(SourceAction$1, EditorSourceActionWidget);
20630
+ set$9(CodeGenerator, EditorCodeGeneratorWidget);
20523
20631
  };
20524
20632
 
20525
20633
  const handleUnhandledRejection = event => {