@lvce-editor/editor-worker 6.2.0 → 7.0.0

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.
Files changed (2) hide show
  1. package/dist/editorWorkerMain.js +826 -2416
  2. package/package.json +1 -1
@@ -263,7 +263,7 @@ const getErrorResponse = (message, error, preparePrettyError, logError) => {
263
263
  const errorProperty = getErrorProperty(error, prettyError);
264
264
  return create$1$1(message, errorProperty);
265
265
  };
266
- const create$e = (message, result) => {
266
+ const create$d = (message, result) => {
267
267
  return {
268
268
  jsonrpc: Two,
269
269
  id: message.id,
@@ -272,7 +272,7 @@ const create$e = (message, result) => {
272
272
  };
273
273
  const getSuccessResponse = (message, result) => {
274
274
  const resultProperty = result ?? null;
275
- return create$e(message, resultProperty);
275
+ return create$d(message, resultProperty);
276
276
  };
277
277
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
278
278
  try {
@@ -365,16 +365,16 @@ const send = (transport, method, ...params) => {
365
365
  const message = create$4$1(method, params);
366
366
  transport.send(message);
367
367
  };
368
- const invoke$7 = (ipc, method, ...params) => {
368
+ const invoke$9 = (ipc, method, ...params) => {
369
369
  return invokeHelper(ipc, method, params, false);
370
370
  };
371
371
  const invokeAndTransfer$2 = (ipc, method, ...params) => {
372
372
  return invokeHelper(ipc, method, params, true);
373
373
  };
374
374
 
375
- const invoke$6 = async (method, ...params) => {
375
+ const invoke$8 = async (method, ...params) => {
376
376
  const ipc = get$7();
377
- return invoke$7(ipc, method, ...params);
377
+ return invoke$9(ipc, method, ...params);
378
378
  };
379
379
  const invokeAndTransfer$1 = async (method, ...params) => {
380
380
  const ipc = get$7();
@@ -384,8 +384,8 @@ const listen$5 = ipc => {
384
384
  set$7(ipc);
385
385
  };
386
386
 
387
- const invoke$5 = async (method, ...params) => {
388
- return invoke$6(method, ...params);
387
+ const invoke$7 = async (method, ...params) => {
388
+ return invoke$8(method, ...params);
389
389
  };
390
390
  const invokeAndTransfer = async (method, ...params) => {
391
391
  return invokeAndTransfer$1(method, ...params);
@@ -393,7 +393,7 @@ const invokeAndTransfer = async (method, ...params) => {
393
393
 
394
394
  // TODO add tests for this
395
395
  const activateByEvent = async event => {
396
- await invoke$5('ExtensionHostManagement.activateByEvent', event);
396
+ await invoke$7('ExtensionHostManagement.activateByEvent', event);
397
397
  };
398
398
 
399
399
  const codeGeneratorAccept = state => {
@@ -981,7 +981,7 @@ const createRpc$1 = ipc => {
981
981
  send(ipc, method, ...params);
982
982
  },
983
983
  invoke(method, ...params) {
984
- return invoke$7(ipc, method, ...params);
984
+ return invoke$9(ipc, method, ...params);
985
985
  },
986
986
  invokeAndTransfer(method, ...params) {
987
987
  return invokeAndTransfer$2(ipc, method, ...params);
@@ -1070,19 +1070,19 @@ const launchColorPickerWorker = async () => {
1070
1070
  return rpc;
1071
1071
  };
1072
1072
 
1073
- let workerPromise$1;
1074
- const getOrCreate$2 = () => {
1075
- if (!workerPromise$1) {
1076
- workerPromise$1 = launchColorPickerWorker();
1073
+ let workerPromise$3;
1074
+ const getOrCreate$4 = () => {
1075
+ if (!workerPromise$3) {
1076
+ workerPromise$3 = launchColorPickerWorker();
1077
1077
  }
1078
- return workerPromise$1;
1078
+ return workerPromise$3;
1079
1079
  };
1080
- const invoke$4 = async (method, ...params) => {
1081
- const worker = await getOrCreate$2();
1080
+ const invoke$6 = async (method, ...params) => {
1081
+ const worker = await getOrCreate$4();
1082
1082
  return await worker.invoke(method, ...params);
1083
1083
  };
1084
1084
 
1085
- const loadContent$3 = async (state, parentUid) => {
1085
+ const loadContent$2 = async (state, parentUid) => {
1086
1086
  const {
1087
1087
  uid,
1088
1088
  x,
@@ -1090,10 +1090,10 @@ const loadContent$3 = async (state, parentUid) => {
1090
1090
  width,
1091
1091
  height
1092
1092
  } = state;
1093
- await invoke$4('ColorPicker.create', uid, x, y, width, height, parentUid);
1094
- await invoke$4('ColorPicker.loadContent', uid);
1095
- const diff = await invoke$4('ColorPicker.diff2', uid);
1096
- const commands = await invoke$4('ColorPicker.render2', uid, diff);
1093
+ await invoke$6('ColorPicker.create', uid, x, y, width, height, parentUid);
1094
+ await invoke$6('ColorPicker.loadContent', uid);
1095
+ const diff = await invoke$6('ColorPicker.diff2', uid);
1096
+ const commands = await invoke$6('ColorPicker.render2', uid, diff);
1097
1097
  return {
1098
1098
  ...state,
1099
1099
  commands
@@ -1115,7 +1115,6 @@ const IndentLess = 'indentLess';
1115
1115
  const IndentMore = 'indentMore';
1116
1116
  const InsertLineBreak = 'insertLineBreak';
1117
1117
  const LineComment = 'lineComment';
1118
- const ReplaceAll$2 = 'replaceAll';
1119
1118
  const ToggleBlockComment$1 = 'toggleBlockComment';
1120
1119
 
1121
1120
  const map$1 = Object.create(null);
@@ -1130,17 +1129,17 @@ const getModule$2 = id => {
1130
1129
  return get$5(id);
1131
1130
  };
1132
1131
 
1133
- const applyWidgetChange = (editor, widget, changes) => {
1132
+ const applyWidgetChange = async (editor, widget, changes) => {
1134
1133
  const module = getModule$2(widget.id);
1135
1134
  if (changes.length === 1 && changes[0].origin === EditorType && module.handleEditorType) {
1136
- const newState = module.handleEditorType(editor, widget.newState);
1135
+ const newState = await module.handleEditorType(editor, widget.newState);
1137
1136
  return {
1138
1137
  ...widget,
1139
1138
  newState
1140
1139
  };
1141
1140
  }
1142
1141
  if (changes.length === 1 && changes[0].origin === DeleteLeft && module.handleEditorDeleteLeft) {
1143
- const newState = module.handleEditorDeleteLeft(editor, widget.newState);
1142
+ const newState = await module.handleEditorDeleteLeft(editor, widget.newState);
1144
1143
  return {
1145
1144
  ...widget,
1146
1145
  newState
@@ -1149,14 +1148,14 @@ const applyWidgetChange = (editor, widget, changes) => {
1149
1148
  return widget;
1150
1149
  };
1151
1150
 
1152
- const applyWidgetChanges = (editor, changes) => {
1151
+ const applyWidgetChanges = async (editor, changes) => {
1153
1152
  const widgets = editor.widgets || [];
1154
1153
  if (widgets.length === 0) {
1155
1154
  return widgets;
1156
1155
  }
1157
1156
  const newWidgets = [];
1158
1157
  for (const widget of widgets) {
1159
- const newWidget = applyWidgetChange(editor, widget, changes);
1158
+ const newWidget = await applyWidgetChange(editor, widget, changes);
1160
1159
  if (newWidget.newState) {
1161
1160
  newWidgets.push(newWidget);
1162
1161
  }
@@ -1164,6 +1163,20 @@ const applyWidgetChanges = (editor, changes) => {
1164
1163
  return newWidgets;
1165
1164
  };
1166
1165
 
1166
+ const editors = Object.create(null);
1167
+ const get$4 = id => {
1168
+ number(id);
1169
+ return editors[id];
1170
+ };
1171
+ const set$4 = (id, oldEditor, newEditor) => {
1172
+ object(oldEditor);
1173
+ object(newEditor);
1174
+ editors[id] = {
1175
+ oldState: oldEditor,
1176
+ newState: newEditor
1177
+ };
1178
+ };
1179
+
1167
1180
  const clamp = (num, min, max) => {
1168
1181
  number(num);
1169
1182
  number(min);
@@ -1215,7 +1228,7 @@ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
1215
1228
  };
1216
1229
 
1217
1230
  // TODO this should be in a separate scrolling module
1218
- const setDeltaY$3 = (state, value) => {
1231
+ const setDeltaY$2 = (state, value) => {
1219
1232
  object(state);
1220
1233
  number(value);
1221
1234
  const {
@@ -1366,15 +1379,11 @@ const getText$1 = state => {
1366
1379
  // TDOO this doesn;t belong here
1367
1380
  const getSelectionText = (textDocument, range) => {
1368
1381
  object(textDocument);
1369
- // console.log(range)
1370
- // console.log(textDocument)
1371
1382
  const startRowIndex = range.start.rowIndex;
1372
1383
  const startColumnIndex = range.start.columnIndex;
1373
1384
  const endRowIndex = Math.min(range.end.rowIndex, textDocument.lines.length - 1);
1374
1385
  const endColumnIndex = range.end.columnIndex;
1375
1386
  if (startRowIndex === endRowIndex) {
1376
- // console.log(startRowIndex)
1377
- // console.log(textDocument.lines)
1378
1387
  return [textDocument.lines[startRowIndex].slice(startColumnIndex, endColumnIndex)];
1379
1388
  }
1380
1389
  const selectedLines = [textDocument.lines[startRowIndex].slice(startColumnIndex), ...textDocument.lines.slice(startRowIndex + 1, endRowIndex), textDocument.lines[endRowIndex].slice(0, endColumnIndex)];
@@ -1449,9 +1458,9 @@ const getSelectionPairs = (selections, i) => {
1449
1458
  return [first, second, third, fourth, 0];
1450
1459
  };
1451
1460
 
1452
- const EmptyString$1 = '';
1461
+ const EmptyString = '';
1453
1462
  const NewLine = '\n';
1454
- const Space$2 = ' ';
1463
+ const Space$1 = ' ';
1455
1464
  const Tab$1 = '\t';
1456
1465
  const DoubleQuote$1 = '"';
1457
1466
 
@@ -1489,7 +1498,7 @@ const createMeasureContext = () => {
1489
1498
  const state$8 = {
1490
1499
  ctx: undefined
1491
1500
  };
1492
- const getOrCreate$1 = createCtx => {
1501
+ const getOrCreate$3 = createCtx => {
1493
1502
  if (state$8.ctx) {
1494
1503
  return state$8.ctx;
1495
1504
  }
@@ -1498,7 +1507,7 @@ const getOrCreate$1 = createCtx => {
1498
1507
  };
1499
1508
 
1500
1509
  const getContext = () => {
1501
- const ctx = getOrCreate$1(createMeasureContext);
1510
+ const ctx = getOrCreate$3(createMeasureContext);
1502
1511
  return ctx;
1503
1512
  };
1504
1513
 
@@ -1535,7 +1544,7 @@ const measureTextWidth = (text, fontWeight, fontSize, fontFamily, letterSpacing,
1535
1544
 
1536
1545
  const normalizeText = (text, normalize, tabSize) => {
1537
1546
  if (normalize) {
1538
- return text.replaceAll(Tab$1, Space$2.repeat(tabSize));
1547
+ return text.replaceAll(Tab$1, Space$1.repeat(tabSize));
1539
1548
  }
1540
1549
  return text;
1541
1550
  };
@@ -1823,9 +1832,9 @@ const applyEdit$1 = (editor, changes) => {
1823
1832
 
1824
1833
  // TODO
1825
1834
  const setDeltaYFixedValue$1 = (editor, value) => {
1826
- return setDeltaY$3(editor, value);
1835
+ return setDeltaY$2(editor, value);
1827
1836
  };
1828
- const setDeltaY$2 = (editor, value) => {
1837
+ const setDeltaY$1 = (editor, value) => {
1829
1838
  return setDeltaYFixedValue$1(editor, editor.deltaY + value);
1830
1839
  };
1831
1840
  const isAutoClosingChange = change => {
@@ -1870,7 +1879,7 @@ const scheduleSelections = (editor, selectionEdits) => {
1870
1879
  * @param {Uint32Array|undefined} selectionChanges
1871
1880
  * @returns
1872
1881
  */
1873
- const scheduleDocumentAndCursorsSelections = (editor, changes, selectionChanges = undefined) => {
1882
+ const scheduleDocumentAndCursorsSelections = async (editor, changes, selectionChanges = undefined) => {
1874
1883
  object(editor);
1875
1884
  array(changes);
1876
1885
  if (changes.length === 0) {
@@ -1899,7 +1908,8 @@ const scheduleDocumentAndCursorsSelections = (editor, changes, selectionChanges
1899
1908
  invalidStartIndex,
1900
1909
  autoClosingRanges
1901
1910
  };
1902
- const newWidgets = applyWidgetChanges(newEditor, changes);
1911
+ set$4(editor.uid, editor, newEditor);
1912
+ const newWidgets = await applyWidgetChanges(newEditor, changes);
1903
1913
  const newEditor2 = {
1904
1914
  ...newEditor,
1905
1915
  widgets: newWidgets
@@ -1932,11 +1942,7 @@ const scheduleDocumentAndCursorsSelectionIsUndo = (editor, changes) => {
1932
1942
 
1933
1943
  // @ts-ignore
1934
1944
  const scheduleDocument = async (editor, changes) => {
1935
- // console.log('before')
1936
- // console.log([...editor.lines])
1937
1945
  const newLines = applyEdits(editor, changes);
1938
- // console.log('after')
1939
- // console.log([...editor.lines])
1940
1946
  const invalidStartIndex = changes[0].start.rowIndex;
1941
1947
  // if (editor.undoStack) {
1942
1948
  // editor.undoStack.push(changes)
@@ -2018,23 +2024,6 @@ const setText = (editor, text) => {
2018
2024
  };
2019
2025
  };
2020
2026
 
2021
- const editors = Object.create(null);
2022
- const get$4 = id => {
2023
- number(id);
2024
- return editors[id];
2025
- };
2026
- const set$4 = (id, oldEditor, newEditor) => {
2027
- number(id);
2028
- object(oldEditor);
2029
- object(newEditor);
2030
- editors[id] = {
2031
- oldState: oldEditor,
2032
- newState: newEditor
2033
- };
2034
- };
2035
-
2036
- const CompletionExecute = 'ExtensionHostCompletion.execute';
2037
- const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
2038
2027
  const HoverExecute = 'ExtensionHostHover.execute';
2039
2028
  const TabCompletionExecuteTabCompletionProvider = 'ExtensionHost.executeTabCompletionProvider';
2040
2029
  const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
@@ -2112,7 +2101,7 @@ const waitForFirstMessage = async port => {
2112
2101
  return event;
2113
2102
  };
2114
2103
 
2115
- const create$d = async () => {
2104
+ const create$c = async () => {
2116
2105
  const {
2117
2106
  port1,
2118
2107
  port2
@@ -2157,7 +2146,7 @@ const wrap$2 = port => {
2157
2146
 
2158
2147
  const IpcParentWithExtensionHostWorker = {
2159
2148
  __proto__: null,
2160
- create: create$d,
2149
+ create: create$c,
2161
2150
  wrap: wrap$2
2162
2151
  };
2163
2152
 
@@ -2165,7 +2154,7 @@ const sendMessagePortToRendererProcess = async port => {
2165
2154
  await invokeAndTransfer('SendMessagePortToRendererProcess.sendMessagePortToRendererProcess', port, 'HandleMessagePort.handleMessagePort');
2166
2155
  };
2167
2156
 
2168
- const create$c = async () => {
2157
+ const create$b = async () => {
2169
2158
  const {
2170
2159
  port1,
2171
2160
  port2
@@ -2210,7 +2199,7 @@ const wrap$1 = port => {
2210
2199
 
2211
2200
  const IpcParentWithRendererProcess = {
2212
2201
  __proto__: null,
2213
- create: create$c,
2202
+ create: create$b,
2214
2203
  wrap: wrap$1
2215
2204
  };
2216
2205
 
@@ -2218,7 +2207,7 @@ const sendMessagePortToSyntaxHighlightingWorker = async port => {
2218
2207
  await invokeAndTransfer('SendMessagePortToSyntaxHighlightingWorker.sendMessagePortToSyntaxHighlightingWorker', port, 'HandleMessagePort.handleMessagePort');
2219
2208
  };
2220
2209
 
2221
- const create$b = async () => {
2210
+ const create$a = async () => {
2222
2211
  const {
2223
2212
  port1,
2224
2213
  port2
@@ -2263,7 +2252,7 @@ const wrap = port => {
2263
2252
 
2264
2253
  const IpcParentWithSyntaxHighlightingWorker = {
2265
2254
  __proto__: null,
2266
- create: create$b,
2255
+ create: create$a,
2267
2256
  wrap
2268
2257
  };
2269
2258
 
@@ -2280,7 +2269,7 @@ const getModule$1 = method => {
2280
2269
  }
2281
2270
  };
2282
2271
 
2283
- const create$a = async ({
2272
+ const create$9 = async ({
2284
2273
  method,
2285
2274
  ...options
2286
2275
  }) => {
@@ -2298,14 +2287,14 @@ const create$a = async ({
2298
2287
  const createRpc = method => {
2299
2288
  let _ipc;
2300
2289
  const listen = async () => {
2301
- const ipc = await create$a({
2290
+ const ipc = await create$9({
2302
2291
  method
2303
2292
  });
2304
2293
  handleIpc(ipc);
2305
2294
  _ipc = ipc;
2306
2295
  };
2307
2296
  const invoke = async (method, ...params) => {
2308
- return invoke$7(_ipc, method, ...params);
2297
+ return invoke$9(_ipc, method, ...params);
2309
2298
  };
2310
2299
  const invokeAndTransfer = async (method, ...params) => {
2311
2300
  return invokeAndTransfer$2(_ipc, method, ...params);
@@ -2319,22 +2308,14 @@ const createRpc = method => {
2319
2308
 
2320
2309
  const {
2321
2310
  listen: listen$4,
2322
- invoke: invoke$3} = createRpc(ExtensionHostWorker);
2311
+ invoke: invoke$5} = createRpc(ExtensionHostWorker);
2323
2312
 
2324
2313
  const ColorPicker$1 = 41;
2325
- const CompletionDetail$1 = 999;
2326
2314
  const EditorCompletion = 9;
2327
2315
  const Empty = 0;
2328
2316
  const FindWidget = 16;
2329
2317
  const FocusEditorHover = 51;
2330
2318
  const FocusEditorRename$1 = 11;
2331
- const FocusFindWidgetCloseButton$1 = 48;
2332
- const FocusFindWidgetNextMatchButton$1 = 49;
2333
- const FocusFindWidgetPreviousMatchButton$1 = 50;
2334
- const FocusFindWidgetReplace$1 = 43;
2335
- const FocusFindWidgetReplaceAllButton$1 = 47;
2336
- const FocusFindWidgetReplaceButton$1 = 46;
2337
- const FocusFindWidgetToggleReplace = 42;
2338
2319
  const SourceActions = 38;
2339
2320
  const FocusCodeGenerator = 52;
2340
2321
 
@@ -2342,7 +2323,6 @@ const measureCharacterWidth = (fontWeight, fontSize, fontFamily, letterSpacing)
2342
2323
  return measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
2343
2324
  };
2344
2325
 
2345
- const OnCompletion = 'onCompletion';
2346
2326
  const OnDiagnostic = 'onDiagnostic';
2347
2327
  const OnHover = 'onHover';
2348
2328
  const OnTabCompletion = 'onTabCompletion';
@@ -2357,7 +2337,7 @@ const execute = async ({
2357
2337
  }) => {
2358
2338
  const fullEvent = `${event}:${editor.languageId}`;
2359
2339
  await activateByEvent(fullEvent);
2360
- const result = await invoke$3(method, editor.uid, ...args);
2340
+ const result = await invoke$5(method, editor.uid, ...args);
2361
2341
  return result;
2362
2342
  };
2363
2343
 
@@ -2424,7 +2404,7 @@ const updateDiagnostics = async newState => {
2424
2404
 
2425
2405
  // TODO don't really need text document sync response
2426
2406
  // could perhaps save a lot of messages by using send instead of invoke
2427
- await invoke$3(TextDocumentSyncFull, newState.uri, newState.id, newState.languageId, content);
2407
+ await invoke$5(TextDocumentSyncFull, newState.uri, newState.id, newState.languageId, content);
2428
2408
  const diagnostics = await executeDiagnosticProvider(newState);
2429
2409
  const latest = get$4(newState.id);
2430
2410
  if (!latest) {
@@ -2437,7 +2417,7 @@ const updateDiagnostics = async newState => {
2437
2417
  decorations
2438
2418
  };
2439
2419
  set$4(newState.id, latest.oldState, newEditor);
2440
- await invoke$5('Editor.rerender', newState.id);
2420
+ await invoke$7('Editor.rerender', newState.id);
2441
2421
  return newEditor;
2442
2422
  } catch (error) {
2443
2423
  // @ts-ignore
@@ -2565,13 +2545,13 @@ const createEditor = async ({
2565
2545
  // TODO avoid creating intermediate editors here
2566
2546
  const newEditor1 = setBounds(editor, x, y, width, height, 9);
2567
2547
  const newEditor2 = setText(newEditor1, content);
2568
- const newEditor3 = setDeltaY$3(newEditor2, 0);
2548
+ const newEditor3 = setDeltaY$2(newEditor2, 0);
2569
2549
  const newEditor4 = {
2570
2550
  ...newEditor3,
2571
2551
  focused: true
2572
2552
  };
2573
2553
  set$4(id, emptyEditor, newEditor4);
2574
- await invoke$3(TextDocumentSyncFull, uri, id, languageId, content);
2554
+ await invoke$5(TextDocumentSyncFull, uri, id, languageId, content);
2575
2555
  if (diagnosticsEnabled) {
2576
2556
  updateDiagnostics(newEditor4);
2577
2557
  }
@@ -2640,7 +2620,7 @@ const applyEdit = async (editor, changes) => {
2640
2620
  return scheduleDocumentAndCursorsSelections(editor, changes);
2641
2621
  };
2642
2622
 
2643
- const handleBlur$1 = editor => {
2623
+ const handleBlur = editor => {
2644
2624
  if (editor.focusKey !== Empty) {
2645
2625
  return editor;
2646
2626
  }
@@ -2700,7 +2680,7 @@ const getAccurateColumnIndexAscii = (line, guess, averageCharWidth, eventX, font
2700
2680
  const supported = () => {
2701
2681
  return 'Segmenter' in Intl;
2702
2682
  };
2703
- const create$9 = () => {
2683
+ const create$8 = () => {
2704
2684
  // @ts-ignore
2705
2685
  const segmenter = new Intl.Segmenter();
2706
2686
  return {
@@ -2738,7 +2718,7 @@ const create$9 = () => {
2738
2718
 
2739
2719
  // @ts-ignore
2740
2720
  const getAccurateColumnIndexUnicode = (line, guess, averageCharWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing) => {
2741
- const segmenter = create$9();
2721
+ const segmenter = create$8();
2742
2722
  const segments = segmenter.getSegments(line);
2743
2723
  const isMonospaceFont = false;
2744
2724
  const charWidth = 0;
@@ -2882,7 +2862,7 @@ const editorShowMessage = async (editor, rowIndex, columnIndex, message, isError
2882
2862
  const x$1 = x(editor, rowIndex, columnIndex);
2883
2863
  const y$1 = y(editor, rowIndex);
2884
2864
  const displayErrorMessage = message;
2885
- await invoke$5('Editor.showOverlayMessage', editor, 'Viewlet.send', editor.uid, 'showOverlayMessage', x$1, y$1, displayErrorMessage);
2865
+ await invoke$7('Editor.showOverlayMessage', editor, 'Viewlet.send', editor.uid, 'showOverlayMessage', x$1, y$1, displayErrorMessage);
2886
2866
  if (!isError) {
2887
2867
  const handleTimeout = () => {
2888
2868
  editorHideMessage(editor);
@@ -2938,7 +2918,7 @@ const braceCompletion = async (editor, text) => {
2938
2918
  try {
2939
2919
  // @ts-ignore
2940
2920
  const offset = offsetAt(editor, editor.cursor);
2941
- const result = await invoke$5('ExtensionHostBraceCompletion.executeBraceCompletionProvider', editor, offset, text);
2921
+ const result = await invoke$7('ExtensionHostBraceCompletion.executeBraceCompletionProvider', editor, offset, text);
2942
2922
  if (result) {
2943
2923
  const closingBrace = getMatchingClosingBrace$1(text);
2944
2924
  const insertText = text + closingBrace;
@@ -3010,24 +2990,6 @@ const closeCodeGenerator = editor => {
3010
2990
  };
3011
2991
  };
3012
2992
 
3013
- const isCompletionWidget = widget => {
3014
- return widget.id === Completion;
3015
- };
3016
- const closeCompletion = editor => {
3017
- const {
3018
- widgets
3019
- } = editor;
3020
- const completionWidgetIndex = widgets.findIndex(isCompletionWidget);
3021
- if (completionWidgetIndex === -1) {
3022
- return editor;
3023
- }
3024
- const newWidgets = removeEditorWidget(widgets, Completion);
3025
- return {
3026
- ...editor,
3027
- widgets: newWidgets
3028
- };
3029
- };
3030
-
3031
2993
  const isMatchingWidget$1 = widget => {
3032
2994
  return widget.id === Find;
3033
2995
  };
@@ -3047,24 +3009,60 @@ const closeFind = editor => {
3047
3009
  };
3048
3010
  };
3049
3011
 
3012
+ const launchRenameWorker = async () => {
3013
+ const name = 'Rename Worker';
3014
+ const {
3015
+ port1,
3016
+ port2
3017
+ } = getPortTuple();
3018
+ await invokeAndTransfer('IpcParent.create', {
3019
+ method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
3020
+ url: 'renameWorkerMain.js',
3021
+ name: name,
3022
+ raw: true,
3023
+ port: port1
3024
+ });
3025
+ const rpc = await MessagePortRpcParent.create({
3026
+ commandMap: {},
3027
+ messagePort: port2,
3028
+ isMessagePortOpen: true
3029
+ });
3030
+ port2.start();
3031
+ return rpc;
3032
+ };
3033
+
3034
+ let workerPromise$2;
3035
+ const getOrCreate$2 = () => {
3036
+ if (!workerPromise$2) {
3037
+ workerPromise$2 = launchRenameWorker();
3038
+ }
3039
+ return workerPromise$2;
3040
+ };
3041
+ const invoke$4 = async (method, ...params) => {
3042
+ const worker = await getOrCreate$2();
3043
+ return await worker.invoke(method, ...params);
3044
+ };
3045
+
3050
3046
  // TODO duplicate code
3051
3047
  const isRenameWidget = widget => {
3052
3048
  return widget.id === Rename;
3053
3049
  };
3054
- const closeRename = editor => {
3050
+ const closeRename = async editor => {
3055
3051
  const {
3056
- widgets
3052
+ widgets,
3053
+ uid
3057
3054
  } = editor;
3058
3055
  const renameWidgetIndex = widgets.findIndex(isRenameWidget);
3059
3056
  if (renameWidgetIndex === -1) {
3060
3057
  return editor;
3061
3058
  }
3062
- const newWidgets = removeEditorWidget(widgets, Rename);
3063
- return {
3064
- ...editor,
3065
- focused: true,
3066
- widgets: newWidgets
3067
- };
3059
+ const renameWidget = widgets[renameWidgetIndex];
3060
+ await invoke$4('Rename.close', renameWidget.newState.uid);
3061
+ const latest = get$4(uid);
3062
+ const {
3063
+ newState
3064
+ } = latest;
3065
+ return newState;
3068
3066
  };
3069
3067
 
3070
3068
  const isMatchingWidget = widget => {
@@ -3095,14 +3093,20 @@ const hasWidget = (widgets, id) => {
3095
3093
  };
3096
3094
 
3097
3095
  const setAdditionalFocus = async focusKey => {
3098
- await invoke$5('Focus.setAdditionalFocus', focusKey);
3096
+ await invoke$7('Focus.setAdditionalFocus', focusKey);
3099
3097
  };
3100
3098
 
3101
3099
  const setFocus = async focusKey => {
3102
3100
  if (!focusKey) {
3103
3101
  return;
3104
3102
  }
3105
- await invoke$5('Focus.setFocus', focusKey);
3103
+ await invoke$7('Focus.setFocus', focusKey);
3104
+ };
3105
+ const unsetAdditionalFocus = async focusKey => {
3106
+ if (!focusKey) {
3107
+ return;
3108
+ }
3109
+ await invoke$7('Focus.removeAdditionalFocus', focusKey);
3106
3110
  };
3107
3111
 
3108
3112
  const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGenerator, fullFocus) => {
@@ -3135,12 +3139,12 @@ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGe
3135
3139
  return newEditor;
3136
3140
  };
3137
3141
 
3138
- const create$8 = () => {
3142
+ const create$7 = () => {
3139
3143
  return Math.random();
3140
3144
  };
3141
3145
 
3142
- const create$7 = () => {
3143
- const completionUid = create$8();
3146
+ const create$6 = () => {
3147
+ const completionUid = create$7();
3144
3148
  const widget = {
3145
3149
  id: ColorPicker,
3146
3150
  oldState: {
@@ -3163,11 +3167,11 @@ const create$7 = () => {
3163
3167
  return widget;
3164
3168
  };
3165
3169
 
3166
- const newStateGenerator$3 = (state, parentUid) => {
3167
- return loadContent$3(state, parentUid);
3170
+ const newStateGenerator$5 = (state, parentUid) => {
3171
+ return loadContent$2(state, parentUid);
3168
3172
  };
3169
3173
  const openColorPicker = async editor => {
3170
- return addWidgetToEditor(ColorPicker, ColorPicker$1, editor, create$7, newStateGenerator$3);
3174
+ return addWidgetToEditor(ColorPicker, ColorPicker$1, editor, create$6, newStateGenerator$5);
3171
3175
  };
3172
3176
 
3173
3177
  const state$6 = {
@@ -3223,7 +3227,7 @@ const compositionEnd = (editor, data) => {
3223
3227
  const writeText = async text => {
3224
3228
  try {
3225
3229
  string(text);
3226
- await invoke$5('ClipBoard.writeText', /* text */text);
3230
+ await invoke$7('ClipBoard.writeText', /* text */text);
3227
3231
  } catch (error) {
3228
3232
  throw new VError(error, 'Failed to write text to clipboard');
3229
3233
  }
@@ -3412,7 +3416,7 @@ const characterLeft = (line, columnIndex) => {
3412
3416
  if (!supported()) {
3413
3417
  return 1;
3414
3418
  }
3415
- const segmenter = create$9();
3419
+ const segmenter = create$8();
3416
3420
  const last = segmenter.at(line, columnIndex - 1);
3417
3421
  return columnIndex - last.index;
3418
3422
  };
@@ -3423,12 +3427,12 @@ const characterRight = (line, columnIndex) => {
3423
3427
  if (!supported()) {
3424
3428
  return 1;
3425
3429
  }
3426
- const segmenter = create$9();
3430
+ const segmenter = create$8();
3427
3431
  const next = segmenter.at(line, columnIndex);
3428
3432
  return next.segment.length;
3429
3433
  };
3430
3434
  const isWhitespace = char => {
3431
- return char === Space$2 || char === Tab$1;
3435
+ return char === Space$1 || char === Tab$1;
3432
3436
  };
3433
3437
  const lineCharacterStart = (line, columnIndex) => {
3434
3438
  if (line.length === 0) {
@@ -3857,7 +3861,7 @@ const deleteWordRight = editor => {
3857
3861
  };
3858
3862
 
3859
3863
  const findAllReferences = async editor => {
3860
- await invoke$5('SideBar.show', 'References', /* focus */true);
3864
+ await invoke$7('SideBar.show', 'References', /* focus */true);
3861
3865
  return editor;
3862
3866
  };
3863
3867
 
@@ -3950,7 +3954,7 @@ const getWordAt$2 = (line, columnIndex) => {
3950
3954
  const matchBefore = before.match(RE_WORD_END$1);
3951
3955
  const after = line.slice(columnIndex);
3952
3956
  const matchAfter = after.match(RE_WORD_START$1);
3953
- let word = EmptyString$1;
3957
+ let word = EmptyString;
3954
3958
  if (matchBefore) {
3955
3959
  word += matchBefore[0];
3956
3960
  }
@@ -3967,7 +3971,7 @@ const getWordBefore$1 = (line, columnIndex) => {
3967
3971
  if (matchBefore) {
3968
3972
  return matchBefore[0];
3969
3973
  }
3970
- return EmptyString$1;
3974
+ return EmptyString;
3971
3975
  };
3972
3976
 
3973
3977
  const getWordAt$1 = (editor, rowIndex, columnIndex) => {
@@ -3987,7 +3991,7 @@ const getWordBefore = (editor, rowIndex, columnIndex) => {
3987
3991
 
3988
3992
  // @ts-ignore
3989
3993
  const getDefinition = async (editor, offset) => {
3990
- const definition = await invoke$5('ExtensionHostDefinition.executeDefinitionProvider', editor, offset);
3994
+ const definition = await invoke$7('ExtensionHostDefinition.executeDefinitionProvider', editor, offset);
3991
3995
  return definition;
3992
3996
  };
3993
3997
 
@@ -4028,7 +4032,6 @@ const MoveLineUp = 'Move Line Up';
4028
4032
  const NoCodeActionsAvailable = 'No code actions available';
4029
4033
  const NoDefinitionFound = 'No definition found';
4030
4034
  const NoDefinitionFoundFor = "No definition found for '{PH1}'";
4031
- const NoResults = 'No Results';
4032
4035
  const NoTypeDefinitionFound = 'No type definition found';
4033
4036
  const NoTypeDefinitionFoundFor = "No type definition found for '{PH1}'";
4034
4037
  const SourceAction = 'Source Action';
@@ -4050,9 +4053,6 @@ const noTypeDefinitionFoundFor = word => {
4050
4053
  const noTypeDefinitionFound = () => {
4051
4054
  return i18nString(NoTypeDefinitionFound);
4052
4055
  };
4053
- const noResults$1 = () => {
4054
- return i18nString(NoResults);
4055
- };
4056
4056
  const sourceAction = () => {
4057
4057
  return i18nString(SourceAction);
4058
4058
  };
@@ -4174,7 +4174,7 @@ const goTo = async ({
4174
4174
  endRowIndex: definition.endRowIndex,
4175
4175
  endColumnIndex: definition.endColumnIndex
4176
4176
  };
4177
- await invoke$5(/* Main.openUri */'Main.openUri', /* uri */uri, /* focus */true, context);
4177
+ await invoke$7(/* Main.openUri */'Main.openUri', /* uri */uri, /* focus */true, context);
4178
4178
  return editor;
4179
4179
  } catch (error) {
4180
4180
  // TODO if editor is already disposed at this point, do nothing
@@ -4251,7 +4251,7 @@ const getNoLocationFoundMessage = info => {
4251
4251
  };
4252
4252
 
4253
4253
  const getTypeDefinition = async (editor, offset) => {
4254
- const definition = await invoke$5('ExtensionHostTypeDefinition.executeTypeDefinitionProvider', editor, offset);
4254
+ const definition = await invoke$7('ExtensionHostTypeDefinition.executeTypeDefinitionProvider', editor, offset);
4255
4255
  return definition;
4256
4256
  };
4257
4257
 
@@ -4291,7 +4291,7 @@ const goToTypeDefinition = async (editor, explicit = true) => {
4291
4291
  const Editor = 3;
4292
4292
 
4293
4293
  const handleContextMenu = async (editor, button, x, y) => {
4294
- await invoke$5(/* ContextMenu.show */'ContextMenu.show', /* x */x, /* y */y, /* id */Editor);
4294
+ await invoke$7(/* ContextMenu.show */'ContextMenu.show', /* x */x, /* y */y, /* id */Editor);
4295
4295
  return editor;
4296
4296
  };
4297
4297
 
@@ -4329,7 +4329,7 @@ const WhenExpressionEditorText = 12;
4329
4329
  const handleFocus = editor => {
4330
4330
  // TODO make change events functional,
4331
4331
  // when rendering, send focus changes to renderer worker
4332
- invoke$5('Focus.setFocus', WhenExpressionEditorText);
4332
+ invoke$7('Focus.setFocus', WhenExpressionEditorText);
4333
4333
  return editor;
4334
4334
  };
4335
4335
 
@@ -4691,7 +4691,6 @@ const getNewPercent$1 = (size, scrollBarSize, relativeX) => {
4691
4691
  return 0;
4692
4692
  }
4693
4693
  // if (relativeY <= editor.scrollBarHeight / 2) {
4694
- // console.log('clicked at top')
4695
4694
  // // clicked at top
4696
4695
  // return 0
4697
4696
  // }
@@ -4777,7 +4776,6 @@ const getNewPercent = (state, relativeY) => {
4777
4776
  scrollBarHeight
4778
4777
  } = state;
4779
4778
  // if (relativeY <= editor.scrollBarHeight / 2) {
4780
- // console.log('clicked at top')
4781
4779
  // // clicked at top
4782
4780
  // return 0
4783
4781
  // }
@@ -4856,7 +4854,6 @@ const handleTouchEnd = (editor, touchEvent) => {
4856
4854
  // EditorCursorSet.cursorSet(editor, position)
4857
4855
  // }
4858
4856
  // } else {
4859
- // console.log('different position')
4860
4857
  // }
4861
4858
  };
4862
4859
 
@@ -4879,8 +4876,8 @@ const handleTouchStart = (editor, touchEvent) => {
4879
4876
  };
4880
4877
 
4881
4878
  // @ts-ignore
4882
- const setDeltaY$1 = (editor, deltaY) => {
4883
- return setDeltaY$2(editor, deltaY);
4879
+ const setDeltaY = (editor, deltaY) => {
4880
+ return setDeltaY$1(editor, deltaY);
4884
4881
  };
4885
4882
 
4886
4883
  // @ts-ignore
@@ -4897,11 +4894,11 @@ const setDelta = (editor, deltaMode, eventDeltaX, eventDeltaY) => {
4897
4894
  const {
4898
4895
  deltaX} = editor;
4899
4896
  if (eventDeltaX === 0) {
4900
- return setDeltaY$1(editor, eventDeltaY);
4897
+ return setDeltaY(editor, eventDeltaY);
4901
4898
  }
4902
4899
  const newDeltaX = clamp(deltaX + eventDeltaX, 0, Number.POSITIVE_INFINITY);
4903
4900
  return {
4904
- ...setDeltaY$1(editor, eventDeltaY),
4901
+ ...setDeltaY(editor, eventDeltaY),
4905
4902
  deltaX: newDeltaX
4906
4903
  };
4907
4904
  };
@@ -4990,7 +4987,7 @@ const indentMore = editor => {
4990
4987
  };
4991
4988
 
4992
4989
  const getLanguageConfiguration = async editor => {
4993
- return invoke$5('Languages.getLanguageConfiguration', {
4990
+ return invoke$7('Languages.getLanguageConfiguration', {
4994
4991
  uri: editor.uri,
4995
4992
  languageId: editor.languageId
4996
4993
  });
@@ -5262,12 +5259,11 @@ const moveSelectionPx = (editor, x, y) => {
5262
5259
  return editorMoveSelection(editor, position);
5263
5260
  };
5264
5261
 
5265
- const User = 1;
5266
5262
  const Script = 2;
5267
5263
  const Unknown$1 = 0;
5268
5264
 
5269
- const create$6 = () => {
5270
- const completionUid = create$8();
5265
+ const create$5 = () => {
5266
+ const completionUid = create$7();
5271
5267
  const widget = {
5272
5268
  id: CodeGenerator,
5273
5269
  oldState: {
@@ -5294,7 +5290,7 @@ const create$6 = () => {
5294
5290
  return widget;
5295
5291
  };
5296
5292
 
5297
- const newStateGenerator$2 = async state => {
5293
+ const newStateGenerator$4 = async state => {
5298
5294
  const latestState = {
5299
5295
  ...state,
5300
5296
  x: 100,
@@ -5306,296 +5302,152 @@ const newStateGenerator$2 = async state => {
5306
5302
  };
5307
5303
  const openCodeGenerator = async editor => {
5308
5304
  const fullFocus = true;
5309
- return addWidgetToEditor(CodeGenerator, FocusCodeGenerator, editor, create$6, newStateGenerator$2, fullFocus);
5305
+ return addWidgetToEditor(CodeGenerator, FocusCodeGenerator, editor, create$5, newStateGenerator$4, fullFocus);
5310
5306
  };
5311
5307
 
5312
- const create$5 = () => {
5313
- const completionUid = create$8();
5308
+ const create$4 = () => {
5309
+ const completionUid = create$7();
5314
5310
  const completionWidget = {
5315
5311
  id: Completion,
5316
5312
  oldState: {
5317
- items: [],
5318
- itemHeight: 20,
5319
- maxHeight: 150,
5320
- minLineY: 0,
5321
- maxLineY: 0,
5322
5313
  uid: completionUid,
5323
- focusedIndex: -1,
5324
5314
  x: 0,
5325
5315
  y: 0,
5326
5316
  width: 0,
5327
5317
  height: 0,
5328
- deltaY: 0,
5329
- finalDeltaY: 0,
5330
- focused: false,
5331
- headerHeight: 0
5318
+ commands: []
5332
5319
  },
5333
5320
  newState: {
5334
- items: [],
5335
- itemHeight: 20,
5336
- maxHeight: 150,
5337
- minLineY: 0,
5338
- maxLineY: 10,
5339
5321
  uid: completionUid,
5340
- focusedIndex: -1,
5341
5322
  x: 0,
5342
5323
  y: 0,
5343
5324
  width: 0,
5344
5325
  height: 0,
5345
- deltaY: 0,
5346
- finalDeltaY: 0,
5347
- headerHeight: 0,
5348
- focused: false
5326
+ commands: []
5349
5327
  }
5350
5328
  };
5351
5329
  return completionWidget;
5352
5330
  };
5353
5331
 
5354
- const executeCompletionProvider = async (editor, offset) => {
5355
- return execute({
5356
- editor,
5357
- event: OnCompletion,
5358
- method: CompletionExecute,
5359
- args: [offset],
5360
- noProviderFoundMessage: 'no completion provider found',
5361
- noProviderFoundResult: []});
5362
- };
5363
- const executeResolveCompletionItem = async (editor, offset, name, completionItem) => {
5364
- return execute({
5365
- editor,
5366
- event: OnCompletion,
5367
- method: CompletionResolveExecute,
5368
- args: [offset, name, completionItem],
5369
- noProviderFoundMessage: 'no completion provider found',
5370
- noProviderFoundResult: []});
5371
- };
5372
-
5373
- const getOffsetAtCursor = editor => {
5332
+ const launchCompletionWorker = async () => {
5333
+ const name = 'Completion Worker';
5374
5334
  const {
5375
- selections
5376
- } = editor;
5377
- const rowIndex = selections[0];
5378
- const columnIndex = selections[1];
5379
- const offset = offsetAt(editor, rowIndex, columnIndex);
5380
- return offset;
5381
- };
5382
-
5383
- // TODO possible to do this with events/state machine instead of promises -> enables canceling operations / concurrent calls
5384
- const getCompletions = async editor => {
5385
- const offset = getOffsetAtCursor(editor);
5386
- const completions = await executeCompletionProvider(editor, offset);
5387
- return completions;
5335
+ port1,
5336
+ port2
5337
+ } = getPortTuple();
5338
+ await invokeAndTransfer('IpcParent.create', {
5339
+ method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
5340
+ url: 'completionWorkerMain.js',
5341
+ name: name,
5342
+ raw: true,
5343
+ port: port1
5344
+ });
5345
+ const rpc = await MessagePortRpcParent.create({
5346
+ commandMap: {},
5347
+ messagePort: port2,
5348
+ isMessagePortOpen: true
5349
+ });
5350
+ port2.start();
5351
+ await rpc.invoke('Completions.initialize');
5352
+ return rpc;
5388
5353
  };
5389
5354
 
5390
- // TODO don't send unnecessary parts of completion item like matches
5391
- const resolveCompletion = async (editor, name, completionItem) => {
5392
- try {
5393
- object(editor);
5394
- string(name);
5395
- object(completionItem);
5396
- const offset = getOffsetAtCursor(editor);
5397
- // @ts-ignore
5398
- const resolvedCompletionItem = await executeResolveCompletionItem(editor, offset, name, completionItem);
5399
- return resolvedCompletionItem;
5400
- } catch {
5401
- return undefined;
5355
+ let workerPromise$1;
5356
+ const getOrCreate$1 = () => {
5357
+ if (!workerPromise$1) {
5358
+ workerPromise$1 = launchCompletionWorker();
5402
5359
  }
5360
+ return workerPromise$1;
5361
+ };
5362
+ const invoke$3 = async (method, ...params) => {
5363
+ const worker = await getOrCreate$1();
5364
+ return await worker.invoke(method, ...params);
5403
5365
  };
5404
5366
 
5405
- const None$1 = 1;
5406
-
5407
- const Diagonal = 1;
5408
- const Left = 2;
5409
-
5410
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
5411
-
5412
- const createTable = size => {
5413
- const table = [];
5414
- for (let i = 0; i < size; i++) {
5415
- const row = new Uint8Array(size);
5416
- table.push(row);
5417
- }
5418
- return table;
5367
+ const newStateGenerator$3 = async (state, parentUid) => {
5368
+ const {
5369
+ uid,
5370
+ x,
5371
+ y,
5372
+ width,
5373
+ height
5374
+ } = state;
5375
+ const editor = get$4(parentUid);
5376
+ const {
5377
+ languageId
5378
+ } = editor;
5379
+ await invoke$3('Completions.create', uid, x, y, width, height, parentUid, languageId);
5380
+ await invoke$3('Completions.loadContent', uid);
5381
+ const diff = await invoke$3('Completions.diff2', uid);
5382
+ const commands = await invoke$3('Completions.render2', uid, diff);
5383
+ return {
5384
+ ...state,
5385
+ commands
5386
+ };
5419
5387
  };
5420
- const EmptyMatches$1 = [];
5421
- const Dash = '-';
5422
- const Dot = '.';
5423
- const EmptyString = '';
5424
- const Space$1 = ' ';
5425
- const Underline = '_';
5426
- const T = 't';
5427
- const isLowerCase = char => {
5428
- return char === char.toLowerCase();
5429
- };
5430
- const isUpperCase = char => {
5431
- return char === char.toUpperCase();
5432
- };
5433
-
5434
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
5435
- const isGap = (columnCharBefore, columnChar) => {
5436
- switch (columnCharBefore) {
5437
- case Dash:
5438
- case Underline:
5439
- case EmptyString:
5440
- case T:
5441
- case Space$1:
5442
- case Dot:
5443
- return true;
5444
- }
5445
- if (isLowerCase(columnCharBefore) && isUpperCase(columnChar)) {
5446
- return true;
5447
- }
5448
- return false;
5388
+ const openCompletion = async editor => {
5389
+ const fullFocus = false;
5390
+ return addWidgetToEditor(Completion, EditorCompletion, editor, create$4, newStateGenerator$3, fullFocus);
5449
5391
  };
5450
5392
 
5451
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
5452
- const getScore = (rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch) => {
5453
- if (rowCharLow !== columnCharLow) {
5454
- return -1;
5455
- }
5456
- const isMatch = rowChar === columnChar;
5457
- if (isMatch) {
5458
- if (isDiagonalMatch) {
5459
- return 8;
5460
- }
5461
- if (isGap(columnCharBefore, columnChar)) {
5462
- return 8;
5393
+ const create$3 = () => {
5394
+ const uid = create$7();
5395
+ const widget = {
5396
+ id: Find,
5397
+ oldState: {
5398
+ uid,
5399
+ x: 0,
5400
+ y: 0,
5401
+ width: 0,
5402
+ height: 0,
5403
+ commands: [],
5404
+ editorUid: 0
5405
+ },
5406
+ newState: {
5407
+ uid,
5408
+ x: 0,
5409
+ y: 0,
5410
+ width: 0,
5411
+ height: 0,
5412
+ commands: [],
5413
+ editorUid: 0
5463
5414
  }
5464
- return 5;
5465
- }
5466
- if (isGap(columnCharBefore, columnChar)) {
5467
- return 8;
5468
- }
5469
- return 5;
5415
+ };
5416
+ return widget;
5470
5417
  };
5471
5418
 
5472
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
5473
-
5474
- const isPatternInWord = (patternLow, patternPos, patternLen, wordLow, wordPos, wordLen) => {
5475
- while (patternPos < patternLen && wordPos < wordLen) {
5476
- if (patternLow[patternPos] === wordLow[wordPos]) {
5477
- patternPos += 1;
5478
- }
5479
- wordPos += 1;
5480
- }
5481
- return patternPos === patternLen; // pattern must be exhausted
5419
+ const launchFindWidgetWorker = async () => {
5420
+ const name = 'Find Widget Worker';
5421
+ const {
5422
+ port1,
5423
+ port2
5424
+ } = getPortTuple();
5425
+ await invokeAndTransfer('IpcParent.create', {
5426
+ method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
5427
+ url: 'findWidgetWorkerMain.js',
5428
+ name: name,
5429
+ raw: true,
5430
+ port: port1
5431
+ });
5432
+ const rpc = await MessagePortRpcParent.create({
5433
+ commandMap: {},
5434
+ messagePort: port2,
5435
+ isMessagePortOpen: true
5436
+ });
5437
+ port2.start();
5438
+ return rpc;
5482
5439
  };
5483
5440
 
5484
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
5485
- const traceHighlights = (table, arrows, patternLength, wordLength) => {
5486
- let row = patternLength;
5487
- let column = wordLength;
5488
- const matches = [];
5489
- while (row >= 1 && column >= 1) {
5490
- const arrow = arrows[row][column];
5491
- if (arrow === Left) {
5492
- column--;
5493
- } else if (arrow === Diagonal) {
5494
- row--;
5495
- column--;
5496
- const start = column + 1;
5497
- while (row >= 1 && column >= 1) {
5498
- const arrow = arrows[row][column];
5499
- if (arrow === Left) {
5500
- break;
5501
- }
5502
- if (arrow === Diagonal) {
5503
- row--;
5504
- column--;
5505
- }
5506
- }
5507
- const end = column;
5508
- matches.unshift(end, start);
5509
- }
5510
- }
5511
- matches.unshift(table[patternLength][wordLength - 1]);
5512
- return matches;
5513
- };
5514
-
5515
- // based on https://github.com/microsoft/vscode/blob/3059063b805ed0ac10a6d9539e213386bfcfb852/src/vs/base/common/filters.ts by Microsoft (License MIT)
5516
- const gridSize = 128;
5517
- const table = createTable(gridSize);
5518
- const arrows = createTable(gridSize);
5519
- const fuzzySearch = (pattern, word) => {
5520
- const patternLength = Math.min(pattern.length, gridSize - 1);
5521
- const wordLength = Math.min(word.length, gridSize - 1);
5522
- const patternLower = pattern.toLowerCase();
5523
- const wordLower = word.toLowerCase();
5524
- if (!isPatternInWord(patternLower, 0, patternLength, wordLower, 0, wordLength)) {
5525
- return EmptyMatches$1;
5526
- }
5527
- let strongMatch = false;
5528
- for (let row = 1; row < patternLength + 1; row++) {
5529
- const rowChar = pattern[row - 1];
5530
- const rowCharLow = patternLower[row - 1];
5531
- for (let column = 1; column < wordLength + 1; column++) {
5532
- const columnChar = word[column - 1];
5533
- const columnCharLow = wordLower[column - 1];
5534
- const columnCharBefore = word[column - 2] || '';
5535
- const isDiagonalMatch = arrows[row - 1][column - 1] === Diagonal;
5536
- const score = getScore(rowCharLow, rowChar, columnCharBefore, columnCharLow, columnChar, isDiagonalMatch);
5537
- if (row === 1 && score > 5) {
5538
- strongMatch = true;
5539
- }
5540
- let diagonalScore = score + table[row - 1][column - 1];
5541
- if (isDiagonalMatch && score !== -1) {
5542
- diagonalScore += 2;
5543
- }
5544
- const leftScore = table[row][column - 1];
5545
- if (leftScore > diagonalScore) {
5546
- table[row][column] = leftScore;
5547
- arrows[row][column] = Left;
5548
- } else {
5549
- table[row][column] = diagonalScore;
5550
- arrows[row][column] = Diagonal;
5551
- }
5552
- }
5553
- }
5554
- if (!strongMatch) {
5555
- return EmptyMatches$1;
5441
+ let workerPromise;
5442
+ const getOrCreate = () => {
5443
+ if (!workerPromise) {
5444
+ workerPromise = launchFindWidgetWorker();
5556
5445
  }
5557
- const highlights = traceHighlights(table, arrows, patternLength, wordLength);
5558
- return highlights;
5559
- };
5560
-
5561
- const Deprecated = 1 << 0;
5562
-
5563
- const EmptyMatches = [];
5564
-
5565
- const addEmptyMatch = item => {
5566
- return {
5567
- ...item,
5568
- matches: EmptyMatches
5569
- };
5446
+ return workerPromise;
5570
5447
  };
5571
- const filterCompletionItems = (completionItems, word) => {
5572
- if (word === EmptyString$1) {
5573
- return completionItems.map(addEmptyMatch);
5574
- }
5575
- const filteredCompletions = [];
5576
- const deprecated = [];
5577
- for (const completionItem of completionItems) {
5578
- const {
5579
- label,
5580
- flags
5581
- } = completionItem;
5582
- const result = fuzzySearch(word, label);
5583
- if (result.length > 0) {
5584
- if (flags & Deprecated) {
5585
- // TODO avoid mutation
5586
- completionItem.matches = EmptyMatches;
5587
- deprecated.push(completionItem);
5588
- } else {
5589
- // TODO avoid mutation
5590
- completionItem.matches = result;
5591
- filteredCompletions.push(completionItem);
5592
- }
5593
- }
5594
- }
5595
- if (deprecated.length > 0) {
5596
- filteredCompletions.push(...deprecated);
5597
- }
5598
- return filteredCompletions;
5448
+ const invoke$2 = async (method, ...params) => {
5449
+ const worker = await getOrCreate();
5450
+ return await worker.invoke(method, ...params);
5599
5451
  };
5600
5452
 
5601
5453
  const getEditor = editorUid => {
@@ -5609,746 +5461,148 @@ const getEditor = editorUid => {
5609
5461
  return newState;
5610
5462
  };
5611
5463
 
5612
- const getFinalDeltaY = (height, itemHeight, itemsLength) => {
5613
- const contentHeight = itemsLength * itemHeight;
5614
- const finalDeltaY = Math.max(contentHeight - height, 0);
5615
- return finalDeltaY;
5616
- };
5617
-
5618
- const getListHeight = (itemsLength, itemHeight, maxHeight) => {
5619
- number(itemsLength);
5620
- number(itemHeight);
5621
- number(maxHeight);
5622
- if (itemsLength === 0) {
5623
- return itemHeight;
5624
- }
5625
- const totalHeight = itemsLength * itemHeight;
5626
- return Math.min(totalHeight, maxHeight);
5627
- };
5628
-
5629
- const getPositionAtCursor$1 = editor => {
5630
- const {
5631
- selections
5632
- } = editor;
5633
- const rowIndex = selections[0];
5634
- const columnIndex = selections[1];
5635
- const x$1 = x(editor, rowIndex, columnIndex);
5636
- const y$1 = y(editor, rowIndex);
5637
- return {
5638
- x: x$1,
5639
- y: y$1,
5640
- rowIndex,
5641
- columnIndex
5642
- };
5643
- };
5644
-
5645
- const RE_WORD = /[\w\-]+$/;
5646
- const getWordAtOffset = editor => {
5647
- const {
5648
- lines,
5649
- selections
5650
- } = editor;
5651
- const rowIndex = selections[0];
5652
- const columnIndex = selections[1];
5653
- const line = lines[rowIndex];
5654
- const part = line.slice(0, columnIndex);
5655
- const wordMatch = part.match(RE_WORD);
5656
- if (wordMatch) {
5657
- return wordMatch[0];
5658
- }
5659
- return '';
5660
- };
5661
-
5662
- const handleEditorType$2 = (editorUid, state, text) => {
5663
- const editor = getEditor(editorUid);
5464
+ const loadContent$1 = async (state, parentUid) => {
5664
5465
  const {
5665
- unfilteredItems,
5666
- itemHeight,
5667
- maxHeight
5466
+ uid
5668
5467
  } = state;
5669
- const rowIndex = editor.selections[0];
5670
- const columnIndex = editor.selections[1];
5671
- const x$1 = x(editor, rowIndex, columnIndex);
5672
- // @ts-ignore
5673
- const y$1 = y(editor, rowIndex);
5674
- const wordAtOffset = getWordAtOffset(editor);
5675
- const items = filterCompletionItems(unfilteredItems, wordAtOffset);
5676
- const newMinLineY = 0;
5677
- const newMaxLineY = Math.min(items.length, 8);
5678
- const height = getListHeight(items.length, itemHeight, maxHeight);
5679
- const finalDeltaY = items.length * itemHeight - height;
5680
- return {
5681
- ...state,
5682
- items,
5683
- x: x$1,
5684
- y: y$1,
5685
- minLineY: newMinLineY,
5686
- maxLineY: newMaxLineY,
5687
- leadingWord: wordAtOffset,
5688
- height,
5689
- finalDeltaY
5690
- };
5691
- };
5692
- const handleEditorDeleteLeft$2 = (editorUid, state) => {
5693
- const editor = getEditor(editorUid);
5468
+ const editor = getEditor(parentUid);
5694
5469
  const {
5695
- unfilteredItems,
5696
- itemHeight,
5697
- maxHeight
5698
- } = state;
5699
- const rowIndex = editor.selections[0];
5700
- const columnIndex = editor.selections[1];
5701
- const x$1 = x(editor, rowIndex, columnIndex);
5702
- // @ts-ignore
5703
- const y$1 = y(editor, rowIndex);
5704
- const wordAtOffset = getWordAtOffset(editor);
5705
- if (!wordAtOffset) {
5706
- editor.completionState = None$1;
5707
- return {
5708
- ...state,
5709
- disposed: true
5710
- };
5711
- }
5712
- const items = filterCompletionItems(unfilteredItems, wordAtOffset);
5713
- const newMaxLineY = Math.min(items.length, 8);
5714
- const height = getListHeight(items.length, itemHeight, maxHeight);
5470
+ x,
5471
+ y,
5472
+ width,
5473
+ height
5474
+ } = editor;
5475
+ await invoke$2('FindWidget.create', uid, x, y, width, height, parentUid);
5476
+ await invoke$2('FindWidget.loadContent', uid);
5477
+ const diff = await invoke$2('FindWidget.diff2', uid);
5478
+ const commands = await invoke$2('FindWidget.render2', uid, diff);
5715
5479
  return {
5716
5480
  ...state,
5717
- items,
5718
- x: x$1,
5719
- y: y$1,
5720
- maxLineY: newMaxLineY,
5721
- leadingWord: wordAtOffset,
5722
- height
5481
+ commands
5723
5482
  };
5724
5483
  };
5725
- const dispose = state => {
5484
+ const close$1 = async state => {
5485
+ // TODO
5486
+ // await Viewlet.closeWidget(uid)
5726
5487
  return {
5727
5488
  ...state,
5728
5489
  disposed: true
5729
5490
  };
5730
5491
  };
5731
- const disposeWithEditor = (state, editor) => {
5732
- editor.completionState = None$1;
5733
- editor.completionUid = 0;
5734
- // Focus.removeAdditionalFocus(FocusKey.EditorCompletion)
5735
- return dispose(state);
5492
+
5493
+ const newStateGenerator$2 = (state, parentUid) => {
5494
+ return loadContent$1(state, parentUid);
5736
5495
  };
5737
- const handleEditorClick = disposeWithEditor;
5738
- const handleEditorBlur = disposeWithEditor;
5739
- const loadContent$2 = async (editorUid, state) => {
5740
- const editor = getEditor(editorUid);
5741
- const {
5742
- itemHeight,
5743
- maxHeight
5744
- } = state;
5745
- const unfilteredItems = await getCompletions(editor);
5746
- const wordAtOffset = getWordAtOffset(editor);
5747
- const items = filterCompletionItems(unfilteredItems, wordAtOffset);
5748
- const {
5749
- rowIndex,
5750
- columnIndex,
5751
- x,
5752
- y
5753
- } = getPositionAtCursor$1(editor);
5754
- const newMaxLineY = Math.min(items.length, 8);
5755
- editor.widgets = editor.widgets || [];
5756
- // editor.widgets.push(ViewletModuleId.EditorCompletion)
5757
- const itemsLength = items.length;
5758
- const newFocusedIndex = itemsLength === 0 ? -1 : 0;
5759
- const total = items.length;
5760
- const height = getListHeight(items.length, itemHeight, maxHeight);
5761
- const finalDeltaY = getFinalDeltaY(height, itemHeight, total);
5762
- return {
5763
- ...state,
5764
- unfilteredItems,
5765
- items,
5766
- x,
5767
- y,
5768
- maxLineY: newMaxLineY,
5769
- focusedIndex: newFocusedIndex,
5770
- finalDeltaY,
5771
- leadingWord: wordAtOffset,
5772
- height,
5773
- rowIndex,
5774
- columnIndex,
5775
- editorUid,
5776
- width: 200
5777
- };
5496
+ const openFind2 = async editor => {
5497
+ const fullFocus = true;
5498
+ return addWidgetToEditor(ColorPicker, FindWidget, editor, create$3, newStateGenerator$2, fullFocus);
5778
5499
  };
5779
- const advance = (state, word) => {
5780
- const filteredItems = filterCompletionItems(state.items, word);
5781
- return {
5782
- ...state,
5783
- filteredItems
5784
- };
5500
+
5501
+ const openFind = async state => {
5502
+ return openFind2(state);
5785
5503
  };
5786
5504
 
5787
- const openCompletion = async editor => {
5505
+ const getPositionAtCursor$1 = editor => {
5788
5506
  const {
5789
- widgets,
5790
- uid
5507
+ selections
5791
5508
  } = editor;
5792
- if (hasWidget(widgets, Completion)) {
5793
- return editor;
5794
- }
5795
- const completionWidget = create$5();
5796
- const newWidgets = [...widgets, completionWidget];
5797
- const newEditor = {
5798
- ...editor,
5799
- widgets: newWidgets
5800
- };
5801
- set$4(uid, editor, newEditor);
5802
- const newCompletionWidget = await loadContent$2(uid, completionWidget.newState);
5803
- const FocusEditorCompletions = EditorCompletion;
5804
- await setAdditionalFocus(FocusEditorCompletions);
5805
- const latestEditor = getEditor(uid);
5806
- if (!latestEditor.widgets.includes(completionWidget)) {
5807
- return editor;
5808
- }
5809
- const index = latestEditor.widgets.indexOf(completionWidget);
5810
- const latestWidgets = [...latestEditor.widgets.slice(0, index), {
5811
- ...completionWidget,
5812
- newState: newCompletionWidget
5813
- }, ...latestEditor.widgets.slice(index + 1)];
5509
+ const rowIndex = selections[0];
5510
+ const columnIndex = selections[1];
5511
+ const x$1 = x(editor, rowIndex, columnIndex);
5512
+ const y$1 = y(editor, rowIndex);
5814
5513
  return {
5815
- ...latestEditor,
5816
- widgets: latestWidgets
5514
+ x: x$1,
5515
+ y: y$1,
5516
+ rowIndex,
5517
+ columnIndex
5817
5518
  };
5818
5519
  };
5819
5520
 
5820
- const create$4 = () => {
5821
- const uid = create$8();
5822
- const widget = {
5823
- id: Find,
5521
+ const create$2 = () => {
5522
+ const completionUid = create$7();
5523
+ const renameWidget = {
5524
+ id: Rename,
5824
5525
  oldState: {
5825
- value: '',
5826
- ariaAnnouncement: '',
5827
- matches: new Uint32Array(),
5828
- matchIndex: -1,
5829
- matchCount: 0,
5830
- uid,
5831
- replaceExpanded: false,
5832
- useRegularExpression: false,
5833
- matchCase: false,
5834
- matchWholeWord: false,
5835
- replacement: '',
5836
- editorUid: 0,
5526
+ uid: completionUid,
5837
5527
  x: 0,
5838
5528
  y: 0,
5839
5529
  width: 0,
5840
5530
  height: 0,
5841
- focused: false,
5842
- focusSource: Unknown$1,
5843
- focus: 0
5531
+ commands: []
5844
5532
  },
5845
5533
  newState: {
5846
- value: '',
5847
- ariaAnnouncement: '',
5848
- matches: new Uint32Array(),
5849
- matchIndex: -1,
5850
- matchCount: 0,
5851
- uid,
5852
- replaceExpanded: false,
5853
- useRegularExpression: false,
5854
- matchCase: false,
5855
- matchWholeWord: false,
5856
- replacement: '',
5857
- editorUid: 0,
5534
+ uid: completionUid,
5858
5535
  x: 0,
5859
5536
  y: 0,
5860
5537
  width: 0,
5861
5538
  height: 0,
5862
- focused: true,
5863
- focusSource: Unknown$1,
5864
- focus: 0
5539
+ commands: []
5865
5540
  }
5866
5541
  };
5867
- return widget;
5542
+ return renameWidget;
5868
5543
  };
5869
5544
 
5870
- const findRegexMatches = (lines, regex) => {
5871
- if (!regex.global) {
5872
- throw new Error('regex must be global');
5873
- }
5545
+ const newStateGenerator$1 = async (state, parentUid) => {
5546
+ // const editor: any = {}
5874
5547
  const {
5875
- length
5876
- } = lines;
5877
- const matches = [];
5878
- for (let i = 0; i < length; i++) {
5879
- const line = lines[i];
5880
- let lastMatch;
5881
- do {
5882
- lastMatch = regex.exec(line);
5883
- if (!lastMatch) {
5884
- break;
5885
- }
5886
- matches.push(i, lastMatch.index);
5887
- } while (true);
5888
- }
5889
- return new Uint32Array(matches);
5890
- };
5891
-
5892
- // copied from https://github.com/microsoft/vscode/tree/main/src/vs/base/common/strings.ts by Microsoft (License MIT)
5893
-
5894
- const RE_ESCAPE = /[\\\{\}\*\+\?\|\^\$\.\[\]\(\)]/g;
5895
- const escapeRegExpCharacters = value => {
5896
- return value.replaceAll(RE_ESCAPE, String.raw`\$&`);
5897
- };
5898
-
5899
- const regexFlags = 'gi';
5900
- const getSearchRegex = searchString => {
5901
- const escaped = escapeRegExpCharacters(searchString);
5902
- return new RegExp(escaped, regexFlags);
5903
- };
5904
-
5905
- const findMatchesCaseInsensitive = (lines, searchString) => {
5906
- if (searchString.length === 0) {
5907
- return new Uint32Array([]);
5908
- }
5909
- const regex = getSearchRegex(searchString);
5910
- return findRegexMatches(lines, regex);
5911
- };
5912
-
5913
- const getMatchCount = matches => {
5914
- return matches.length / 2;
5915
- };
5916
-
5917
- const setFindWidgetFocus = (state, focusKey) => {
5918
- if (state.focus === focusKey) {
5919
- return state;
5920
- }
5548
+ uid,
5549
+ x,
5550
+ y,
5551
+ width,
5552
+ height
5553
+ } = state;
5554
+ await invoke$4('Rename.create', uid, x, y, width, height, parentUid);
5555
+ await invoke$4('Rename.loadContent', uid);
5556
+ const diff = await invoke$4('Rename.diff2', uid);
5557
+ const commands = await invoke$4('Rename.render2', uid, diff);
5921
5558
  return {
5922
5559
  ...state,
5923
- focus: focusKey,
5924
- focusSource: Script
5925
- };
5926
- };
5927
-
5928
- const focusCloseButton = state => {
5929
- return setFindWidgetFocus(state, FocusFindWidgetCloseButton$1);
5930
- };
5931
-
5932
- const focusFind = state => {
5933
- return setFindWidgetFocus(state, FindWidget);
5934
- };
5935
-
5936
- const getWidgetState = (editor, id) => {
5937
- const {
5938
- widgets
5939
- } = editor;
5940
- for (const widget of widgets) {
5941
- if (widget.id === id) {
5942
- return widget.newState;
5943
- }
5944
- }
5945
- return undefined;
5946
- };
5947
-
5948
- const getFindState = editor => {
5949
- return getWidgetState(editor, Find);
5950
- };
5951
-
5952
- const isFind = widget => {
5953
- return widget.id === Find;
5954
- };
5955
- // TODO don't call renderer worker, set editor state
5956
- // TODO this function should be synchronous
5957
- const focusIndex$2 = (editor, index) => {
5958
- const findState = getFindState(editor);
5959
- if (!findState) {
5960
- return editor;
5961
- }
5962
- const {
5963
- value,
5964
- matches,
5965
- matchIndex
5966
- } = findState;
5967
- if (index === matchIndex) {
5968
- return editor;
5969
- }
5970
- const {
5971
- widgets
5972
- } = editor;
5973
- const childIndex = widgets.findIndex(isFind);
5974
- const childWidget = widgets[childIndex];
5975
-
5976
- // TODO find next match and highlight it
5977
- const matchRowIndex = matches[index * 2];
5978
- const matchColumnIndex = matches[index * 2 + 1];
5979
- const newSelections = new Uint32Array([matchRowIndex, matchColumnIndex, matchRowIndex, matchColumnIndex + value.length]);
5980
- const newState = {
5981
- ...findState,
5982
- matchIndex: index
5983
- };
5984
- const newWidget = {
5985
- ...childWidget,
5986
- newState
5987
- };
5988
- const newWidgets = [...widgets.slice(0, childIndex), newWidget, ...widgets.slice(childIndex + 1)];
5989
- return {
5990
- ...editor,
5991
- selections: newSelections,
5992
- widgets: newWidgets
5560
+ commands
5993
5561
  };
5994
5562
  };
5995
- const focusFirst$1 = editor => {
5996
- const findState = getFindState(editor);
5997
- if (!findState) {
5998
- return editor;
5999
- }
6000
- return focusIndex$2(editor, 0);
6001
- };
6002
- const focusLast = editor => {
6003
- const findState = getFindState(editor);
6004
- if (!findState) {
6005
- return editor;
6006
- }
5563
+ const openRename = async editor => {
6007
5564
  const {
6008
- matchCount
6009
- } = findState;
6010
- return focusIndex$2(editor, matchCount - 1);
6011
- };
6012
- const focusNext$2 = editor => {
6013
- const findState = getFindState(editor);
6014
- if (!findState) {
6015
- return editor;
6016
- }
5565
+ rowIndex,
5566
+ columnIndex
5567
+ } = getPositionAtCursor$1(editor);
6017
5568
  const {
6018
- matchIndex,
6019
- matchCount
6020
- } = findState;
6021
- if (matchIndex === matchCount - 1) {
6022
- return focusFirst$1(editor);
6023
- }
6024
- return focusIndex$2(editor, matchIndex + 1);
6025
- };
6026
- const focusPrevious$1 = editor => {
6027
- const findState = getFindState(editor);
6028
- if (!findState) {
5569
+ word
5570
+ } = getWordAt$1(editor, rowIndex, columnIndex);
5571
+ if (!word) {
6029
5572
  return editor;
6030
5573
  }
6031
- const {
6032
- matchIndex
6033
- } = findState;
6034
- if (matchIndex === 0) {
6035
- return focusLast(editor);
6036
- }
6037
- return focusIndex$2(editor, matchIndex - 1);
6038
- };
6039
-
6040
- const focusNextMatchButton = state => {
6041
- return setFindWidgetFocus(state, FocusFindWidgetNextMatchButton$1);
5574
+ const fullFocus = true;
5575
+ return addWidgetToEditor(Rename, FocusEditorRename$1, editor, create$2, newStateGenerator$1, fullFocus);
6042
5576
  };
6043
5577
 
6044
- const focusPreviousMatchButton = state => {
6045
- return setFindWidgetFocus(state, FocusFindWidgetPreviousMatchButton$1);
5578
+ const getOrganizeImportEdits = async editor => {
5579
+ const edits = await execute({
5580
+ editor,
5581
+ event: 'onLanguage',
5582
+ method: 'ExtensionHostOrganizeImports.execute',
5583
+ args: []
5584
+ });
5585
+ return edits;
6046
5586
  };
6047
5587
 
6048
- const focusReplace = state => {
6049
- return setFindWidgetFocus(state, FocusFindWidgetReplace$1);
5588
+ const organizeImports = async editor => {
5589
+ const edits = await getOrganizeImportEdits(editor);
5590
+ return applyDocumentEdits(editor, edits);
6050
5591
  };
6051
5592
 
6052
- const focusReplaceAllButton = state => {
6053
- return setFindWidgetFocus(state, FocusFindWidgetReplaceAllButton$1);
6054
- };
5593
+ // @ts-ignore
6055
5594
 
6056
- const focusReplaceButton = state => {
6057
- return setFindWidgetFocus(state, FocusFindWidgetReplaceButton$1);
5595
+ // @ts-ignore
5596
+ const pasteText = (editor, text) => {
5597
+ const insertedLines = splitLines(text);
5598
+ const changes = editorReplaceSelections(editor, insertedLines, EditorPasteText);
5599
+ return scheduleDocumentAndCursorsSelections(editor, changes);
6058
5600
  };
6059
5601
 
6060
- const focusToggleReplaceButton = state => {
6061
- return setFindWidgetFocus(state, FocusFindWidgetToggleReplace);
6062
- };
6063
-
6064
- const handleBlur = async state => {
6065
- await setFocus(Empty);
6066
- return state;
6067
- };
6068
-
6069
- const refresh$1 = (editor, state, value) => {
6070
- const {
6071
- lines
6072
- } = editor;
6073
- const matches = findMatchesCaseInsensitive(lines, value);
6074
- const matchCount = getMatchCount(matches);
6075
- return {
6076
- ...state,
6077
- matches,
6078
- matchIndex: 0,
6079
- matchCount,
6080
- value
6081
- };
6082
- };
6083
-
6084
- const refresh = (state, value = state.value) => {
6085
- // TODO get focused editor
6086
- const {
6087
- editorUid
6088
- } = state;
6089
- // highlight locations that match value
6090
- const editor = getEditor(editorUid);
6091
- return refresh$1(editor, state, value);
6092
- };
6093
-
6094
- const handleInput = (state, value) => {
6095
- return refresh(state, value);
6096
- };
6097
-
6098
- const handleFindWidgetFocus = (state, focusKey) => {
6099
- if (state.focus === focusKey) {
6100
- return state;
6101
- }
6102
- return {
6103
- ...state,
6104
- focus: focusKey,
6105
- focusSource: User
6106
- };
6107
- };
6108
-
6109
- const handleReplaceAllFocus = state => {
6110
- return handleFindWidgetFocus(state, FocusFindWidgetReplaceAllButton$1);
6111
- };
6112
-
6113
- const handleReplaceFocus = state => {
6114
- return handleFindWidgetFocus(state, FocusFindWidgetReplace$1);
6115
- };
6116
-
6117
- const getFindWidgetHeight = replaceExpanded => {
6118
- const collapsedHeight = 30;
6119
- const expandedHeight = 60;
6120
- const newHeight = replaceExpanded ? expandedHeight : collapsedHeight;
6121
- return newHeight;
6122
- };
6123
-
6124
- const toggleReplace = state => {
6125
- const newExpanded = !state.replaceExpanded;
6126
- const newHeight = getFindWidgetHeight(newExpanded);
6127
- return {
6128
- ...state,
6129
- replaceExpanded: !state.replaceExpanded,
6130
- height: newHeight
6131
- };
6132
- };
6133
-
6134
- const loadContent$1 = editorId => {
6135
- const editor = getEditor(editorId);
6136
- const {
6137
- selections,
6138
- lines
6139
- } = editor;
6140
- const startRowIndex = selections[0];
6141
- const startColumnIndex = selections[1];
6142
- const endColumnIndex = selections[3];
6143
- const line = lines[startRowIndex];
6144
- const value = line.slice(startColumnIndex, endColumnIndex);
6145
- const matches = findMatchesCaseInsensitive(lines, value);
6146
- const matchCount = getMatchCount(matches);
6147
- return {
6148
- value,
6149
- matches,
6150
- matchIndex: 0,
6151
- matchCount,
6152
- editorUid: editor.uid
6153
- };
6154
- };
6155
- const close$1 = async state => {
6156
- // TODO
6157
- // await Viewlet.closeWidget(uid)
6158
- return {
6159
- ...state,
6160
- disposed: true
6161
- };
6162
- };
6163
- const handleToggleReplaceFocus = async state => {
6164
- if (state.focus === FocusFindWidgetToggleReplace) {
6165
- return state;
6166
- }
6167
- await setFocus(FocusFindWidgetToggleReplace);
6168
- return {
6169
- ...state,
6170
- focus: FocusFindWidgetToggleReplace
6171
- };
6172
- };
6173
- const handleReplaceInput = (state, value) => {
6174
- return {
6175
- ...state,
6176
- replacement: value
6177
- };
6178
- };
6179
-
6180
- const getFindWidgetPosition = editor => {
6181
- const width = 300;
6182
- const height = 30;
6183
- const paddingTop = 10;
6184
- const paddingRight = 20;
6185
- const x = editor.x + editor.width - width - paddingRight;
6186
- const y = editor.y + paddingTop;
6187
- return {
6188
- y,
6189
- x,
6190
- width,
6191
- height
6192
- };
6193
- };
6194
-
6195
- const openFind2 = async editor => {
6196
- const newStateGenerator = async state => {
6197
- const {
6198
- value,
6199
- matches,
6200
- matchCount,
6201
- matchIndex
6202
- } = await loadContent$1(editor.uid);
6203
- const {
6204
- x,
6205
- y,
6206
- width,
6207
- height
6208
- } = getFindWidgetPosition(editor);
6209
- const latestState = {
6210
- ...state,
6211
- value,
6212
- matches,
6213
- matchCount,
6214
- matchIndex,
6215
- x,
6216
- y,
6217
- width,
6218
- height,
6219
- editorUid: editor.uid || editor.id,
6220
- focusSource: Script,
6221
- focus: FindWidget
6222
- };
6223
- return latestState;
6224
- };
6225
- const fullFocus = true;
6226
- return addWidgetToEditor(Find, FindWidget, editor, create$4, newStateGenerator, fullFocus);
6227
- };
6228
-
6229
- const openFind = async state => {
6230
- return openFind2(state);
6231
- };
6232
-
6233
- const create$3 = () => {
6234
- const completionUid = create$8();
6235
- const renameWidget = {
6236
- id: Rename,
6237
- oldState: {
6238
- uid: completionUid,
6239
- x: 0,
6240
- y: 0,
6241
- width: 0,
6242
- height: 0,
6243
- commands: []
6244
- },
6245
- newState: {
6246
- uid: completionUid,
6247
- x: 0,
6248
- y: 0,
6249
- width: 0,
6250
- height: 0,
6251
- commands: []
6252
- }
6253
- };
6254
- return renameWidget;
6255
- };
6256
-
6257
- const launchRenameWorker = async () => {
6258
- const name = 'Rename Worker';
6259
- const {
6260
- port1,
6261
- port2
6262
- } = getPortTuple();
6263
- await invokeAndTransfer('IpcParent.create', {
6264
- method: ModuleWorkerAndWorkaroundForChromeDevtoolsBug,
6265
- url: 'renameWorkerMain.js',
6266
- name: name,
6267
- raw: true,
6268
- port: port1
6269
- });
6270
- const rpc = await MessagePortRpcParent.create({
6271
- commandMap: {},
6272
- messagePort: port2,
6273
- isMessagePortOpen: true
6274
- });
6275
- port2.start();
6276
- return rpc;
6277
- };
6278
-
6279
- let workerPromise;
6280
- const getOrCreate = () => {
6281
- if (!workerPromise) {
6282
- workerPromise = launchRenameWorker();
6283
- }
6284
- return workerPromise;
6285
- };
6286
- const invoke$2 = async (method, ...params) => {
6287
- const worker = await getOrCreate();
6288
- return await worker.invoke(method, ...params);
6289
- };
6290
-
6291
- const newStateGenerator$1 = async (state, parentUid) => {
6292
- // const editor: any = {}
6293
- const {
6294
- uid,
6295
- x,
6296
- y,
6297
- width,
6298
- height
6299
- } = state;
6300
- await invoke$2('Rename.create', uid, x, y, width, height, parentUid);
6301
- await invoke$2('Rename.loadContent', uid);
6302
- const diff = await invoke$2('Rename.diff2', uid);
6303
- const commands = await invoke$2('Rename.render2', uid, diff);
6304
- return {
6305
- ...state,
6306
- commands
6307
- };
6308
- };
6309
- const openRename = async editor => {
6310
- const {
6311
- rowIndex,
6312
- columnIndex
6313
- } = getPositionAtCursor$1(editor);
6314
- const {
6315
- word
6316
- } = getWordAt$1(editor, rowIndex, columnIndex);
6317
- if (!word) {
6318
- return editor;
6319
- }
6320
- const fullFocus = true;
6321
- return addWidgetToEditor(Rename, FocusEditorRename$1, editor, create$3, newStateGenerator$1, fullFocus);
6322
- };
6323
-
6324
- const getOrganizeImportEdits = async editor => {
6325
- const edits = await execute({
6326
- editor,
6327
- event: 'onLanguage',
6328
- method: 'ExtensionHostOrganizeImports.execute',
6329
- args: []
6330
- });
6331
- return edits;
6332
- };
6333
-
6334
- const organizeImports = async editor => {
6335
- const edits = await getOrganizeImportEdits(editor);
6336
- return applyDocumentEdits(editor, edits);
6337
- };
6338
-
6339
- // @ts-ignore
6340
-
6341
- // @ts-ignore
6342
- const pasteText = (editor, text) => {
6343
- const insertedLines = splitLines(text);
6344
- const changes = editorReplaceSelections(editor, insertedLines, EditorPasteText);
6345
- return scheduleDocumentAndCursorsSelections(editor, changes);
6346
- };
6347
-
6348
- const paste = async editor => {
6349
- const text = await invoke$5('ClipBoard.readText');
6350
- string(text);
6351
- return pasteText(editor, text);
5602
+ const paste = async editor => {
5603
+ const text = await invoke$7('ClipBoard.readText');
5604
+ string(text);
5605
+ return pasteText(editor, text);
6352
5606
  };
6353
5607
 
6354
5608
  const getErrorMessage$1 = error => {
@@ -6488,7 +5742,7 @@ const save = async editor => {
6488
5742
  } = editor;
6489
5743
  const newEditor = await getNewEditor(editor);
6490
5744
  const content = getText$1(newEditor);
6491
- await invoke$5('FileSystem.writeFile', uri, content);
5745
+ await invoke$7('FileSystem.writeFile', uri, content);
6492
5746
  return newEditor;
6493
5747
  } catch (error) {
6494
5748
  // @ts-ignore
@@ -6794,7 +6048,7 @@ const selectInsideString = editor => {
6794
6048
  // import * as ExtensionHostSelection from '../ExtensionHost/ExtensionHostSelection.ts'
6795
6049
 
6796
6050
  const getNewSelections = async (editor, selections) => {
6797
- const newSelections = await invoke$5('ExtensionHostSelection.executeGrowSelection', editor, selections);
6051
+ const newSelections = await invoke$7('ExtensionHostSelection.executeGrowSelection', editor, selections);
6798
6052
  if (newSelections.length === 0) {
6799
6053
  return selections;
6800
6054
  }
@@ -7223,8 +6477,8 @@ const setSelections = (editor, selections) => {
7223
6477
  };
7224
6478
  };
7225
6479
 
7226
- const create$2 = () => {
7227
- const uid = create$8();
6480
+ const create$1 = () => {
6481
+ const uid = create$7();
7228
6482
  const widget = {
7229
6483
  id: Hover,
7230
6484
  oldState: {
@@ -7277,14 +6531,14 @@ const getHover = async (editor, offset) => {
7277
6531
 
7278
6532
  let _ipc;
7279
6533
  const listen$2 = async () => {
7280
- const ipc = await create$a({
6534
+ const ipc = await create$9({
7281
6535
  method: RendererProcess
7282
6536
  });
7283
6537
  handleIpc(ipc);
7284
6538
  _ipc = ipc;
7285
6539
  };
7286
6540
  const invoke = async (method, ...args) => {
7287
- return invoke$7(_ipc, method, ...args);
6541
+ return invoke$9(_ipc, method, ...args);
7288
6542
  };
7289
6543
 
7290
6544
  const measureTextBlockHeight = async (text, fontFamily, fontSize, lineHeight, width) => {
@@ -7494,18 +6748,18 @@ const newStateGenerator = async state => {
7494
6748
  return loadHoverContent(state);
7495
6749
  };
7496
6750
  const showHover2 = async editor => {
7497
- return addWidgetToEditor(Hover, FocusEditorHover, editor, create$2, newStateGenerator);
6751
+ return addWidgetToEditor(Hover, FocusEditorHover, editor, create$1, newStateGenerator);
7498
6752
  };
7499
6753
 
7500
6754
  const EditorHover = 'EditorHover';
7501
6755
  const showHover = async state => {
7502
- await invoke$5('Viewlet.openWidget', EditorHover);
6756
+ await invoke$7('Viewlet.openWidget', EditorHover);
7503
6757
  return state;
7504
6758
  };
7505
6759
 
7506
6760
  // TODO ask extension host worker instead
7507
6761
  const getEditorSourceActions = async () => {
7508
- const sourceActions = await invoke$5('GetEditorSourceActions.getEditorSourceActions');
6762
+ const sourceActions = await invoke$7('GetEditorSourceActions.getEditorSourceActions');
7509
6763
  return sourceActions;
7510
6764
  };
7511
6765
 
@@ -7557,8 +6811,8 @@ const loadSourceActions = async (editor, state) => {
7557
6811
  };
7558
6812
  };
7559
6813
 
7560
- const create$1 = () => {
7561
- const completionUid = create$8();
6814
+ const create = () => {
6815
+ const completionUid = create$7();
7562
6816
  const widget = {
7563
6817
  id: SourceAction$1,
7564
6818
  oldState: {
@@ -7589,7 +6843,7 @@ const showSourceActions = async editor => {
7589
6843
  const newStateGenerator = async state => {
7590
6844
  return loadSourceActions(editor, state);
7591
6845
  };
7592
- return addWidgetToEditor(SourceAction$1, SourceActions, editor, create$1, newStateGenerator);
6846
+ return addWidgetToEditor(SourceAction$1, SourceActions, editor, create, newStateGenerator);
7593
6847
  };
7594
6848
 
7595
6849
  const compareString = (a, b) => {
@@ -7662,6 +6916,16 @@ const executeTabCompletionProvider = async (editor, offset) => {
7662
6916
  });
7663
6917
  };
7664
6918
 
6919
+ const getOffsetAtCursor = editor => {
6920
+ const {
6921
+ selections
6922
+ } = editor;
6923
+ const rowIndex = selections[0];
6924
+ const columnIndex = selections[1];
6925
+ const offset = offsetAt(editor, rowIndex, columnIndex);
6926
+ return offset;
6927
+ };
6928
+
7665
6929
  const getTabCompletion = async editor => {
7666
6930
  const offset = getOffsetAtCursor(editor);
7667
6931
  const completions = await executeTabCompletionProvider(editor, offset);
@@ -8155,7 +7419,7 @@ const typeWithAutoClosingQuote = (editor, text) => {
8155
7419
 
8156
7420
  const typeWithAutoClosingTag = async (editor, text) => {
8157
7421
  const offset = offsetAt(editor, editor.selections[0], editor.selections[1]);
8158
- const result = await invoke$5('ExtensionHostClosingTagCompletion.executeClosingTagProvider', editor, offset, text);
7422
+ const result = await invoke$7('ExtensionHostClosingTagCompletion.executeClosingTagProvider', editor, offset, text);
8159
7423
  if (!result) {
8160
7424
  const changes = editorReplaceSelections(editor, [text], EditorType);
8161
7425
  return scheduleDocumentAndCursorsSelections(editor, changes);
@@ -8208,7 +7472,6 @@ const typeWithAutoClosing = async (editor, text) => {
8208
7472
 
8209
7473
  return newEditor;
8210
7474
  // if (isBrace(text)) {
8211
- // console.log('is brace')
8212
7475
  // return editorTypeWithBraceCompletion(editor, text)
8213
7476
  // }
8214
7477
  // if (isSlash(text)) {
@@ -8372,230 +7635,151 @@ const editorUnindent = editor => {
8372
7635
 
8373
7636
  // editor.lines //?
8374
7637
 
8375
- const isCompletionDetailWidget = widget => {
8376
- return widget.id === CompletionDetail;
7638
+ const isFunctional = widgetId => {
7639
+ switch (widgetId) {
7640
+ case ColorPicker:
7641
+ case Rename:
7642
+ case Completion:
7643
+ case Find:
7644
+ return true;
7645
+ default:
7646
+ return false;
7647
+ }
8377
7648
  };
8378
- const closeDetails = editor => {
7649
+ const addWidget$1 = (widget, id, render) => {
7650
+ const commands = render(widget);
7651
+ // TODO how to generate a unique integer id
7652
+ // that doesn't collide with ids created in renderer worker?
7653
+ // @ts-ignore
8379
7654
  const {
8380
- widgets
8381
- } = editor;
8382
- const index = widgets.findIndex(isCompletionDetailWidget);
8383
- if (index === -1) {
8384
- return editor;
7655
+ uid
7656
+ } = widget.newState;
7657
+ const allCommands = [];
7658
+ allCommands.push(['Viewlet.createFunctionalRoot', id, uid, isFunctional(widget.id)]);
7659
+ allCommands.push(...commands);
7660
+ if (isFunctional(widget.id)) {
7661
+ allCommands.push(['Viewlet.appendToBody', uid]);
7662
+ } else {
7663
+ allCommands.push(['Viewlet.send', uid, 'appendWidget']);
8385
7664
  }
8386
- const newWidgets = [...widgets.slice(0, index), ...widgets.slice(index + 1)];
8387
- return {
8388
- ...editor,
8389
- widgets: newWidgets
8390
- };
8391
- };
8392
-
8393
- const focusIndex$1 = (state, index) => {
8394
- const newState = {
8395
- ...state,
8396
- focusedIndex: index,
8397
- focused: true
8398
- };
8399
- return newState;
8400
- };
8401
-
8402
- const focusFirst = state => {
8403
- const firstIndex = 0;
8404
- return focusIndex$1(state, firstIndex);
8405
- };
8406
-
8407
- const focusNext$1 = state => {
8408
- const nextIndex = state.focusedIndex + 1;
8409
- return focusIndex$1(state, nextIndex);
8410
- };
8411
-
8412
- const focusPrevious = state => {
8413
- const previousIndex = state.focusedIndex - 1;
8414
- return focusIndex$1(state, previousIndex);
8415
- };
8416
-
8417
- // TODO optimize this function to return the minimum number
8418
- // of visible items needed, e.g. when not scrolled 5 items with
8419
- // 20px fill 100px but when scrolled 6 items are needed
8420
- const getNumberOfVisibleItems = (listHeight, itemHeight) => {
8421
- return Math.ceil(listHeight / itemHeight) + 1;
8422
- };
8423
-
8424
- const setDeltaY = (state, value) => {
8425
- object(state);
8426
- number(value);
8427
- const {
8428
- itemHeight,
8429
- finalDeltaY,
8430
- deltaY,
8431
- height,
8432
- headerHeight
8433
- } = state;
8434
- const listHeight = height - headerHeight;
8435
- const newDeltaY = clamp(value, 0, finalDeltaY);
8436
- if (deltaY === newDeltaY) {
8437
- return state;
7665
+ const focusCommandIndex = allCommands.findIndex(command => {
7666
+ return command[2] === 'focus' || command[0] === 'Viewlet.focusSelector';
7667
+ });
7668
+ // TODO have separate rendering functions, e.g.
7669
+ // 1. renderDom
7670
+ // 2. renderAriaAnnouncement
7671
+ // 3. renderFocus
7672
+ // to ensure that focus is always after the element is added to the dom
7673
+ if (focusCommandIndex !== -1) {
7674
+ const command = allCommands[focusCommandIndex];
7675
+ allCommands.splice(focusCommandIndex, 1);
7676
+ allCommands.push(command);
8438
7677
  }
8439
- // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
8440
- const minLineY = Math.floor(newDeltaY / itemHeight);
8441
- const maxLineY = minLineY + getNumberOfVisibleItems(listHeight, itemHeight);
8442
- return {
8443
- ...state,
8444
- deltaY: newDeltaY,
8445
- minLineY,
8446
- maxLineY
8447
- };
7678
+ return allCommands;
8448
7679
  };
8449
7680
 
8450
- const handleWheel$1 = (state, deltaMode, deltaY) => {
8451
- number(deltaMode);
8452
- number(deltaY);
8453
- return setDeltaY(state, state.deltaY + deltaY);
8454
- };
7681
+ const AppendToBody = 'Viewlet.appendToBody';
7682
+ const Focus = 'focus';
7683
+ const RegisterEventListeners = 'Viewlet.registerEventListeners';
7684
+ const SetSelectionByName = 'Viewlet.setSelectionByName';
7685
+ const SetValueByName = 'Viewlet.setValueByName';
7686
+ const SetFocusContext = 'Viewlet.setFocusContext';
7687
+ const SetBounds = 'setBounds';
7688
+ const SetBounds2 = 'Viewlet.setBounds';
7689
+ const SetCss = 'Viewlet.setCss';
7690
+ const SetDom2 = 'Viewlet.setDom2';
7691
+ const SetUid = 'Viewlet.setUid';
8455
7692
 
8456
- const handleWheel = (state, deltaMode, deltaY) => {
8457
- const newState = handleWheel$1(state, deltaMode, deltaY);
8458
- return newState;
7693
+ const renderFull$4 = (oldState, newState) => {
7694
+ const commands = [...newState.commands];
7695
+ // @ts-ignore
7696
+ newState.commands = [];
7697
+ return commands;
8459
7698
  };
8460
7699
 
8461
- const create = () => {
8462
- const completionUid = create$8();
8463
- const completionWidget = {
8464
- id: CompletionDetail,
8465
- oldState: {
8466
- content: '',
8467
- uid: completionUid,
8468
- x: 0,
8469
- y: 0,
8470
- width: 0,
8471
- height: 0,
8472
- borderSize: 1
8473
- },
8474
- newState: {
8475
- content: '',
8476
- uid: completionUid,
8477
- x: 0,
8478
- y: 0,
8479
- width: 0,
8480
- height: 0,
8481
- borderSize: 1
7700
+ const render$c = widget => {
7701
+ const commands = renderFull$4(widget.oldState, widget.newState);
7702
+ const wrappedCommands = [];
7703
+ const {
7704
+ uid
7705
+ } = widget.newState;
7706
+ for (const command of commands) {
7707
+ if (command[0] === SetDom2 || command[0] === SetCss || command[0] === AppendToBody || command[0] === SetBounds2 || command[0] === RegisterEventListeners || command[0] === SetSelectionByName || command[0] === SetValueByName || command[0] === SetFocusContext || command[0] === SetUid || command[0] === 'Viewlet.focusSelector') {
7708
+ wrappedCommands.push(command);
7709
+ } else {
7710
+ wrappedCommands.push(['Viewlet.send', uid, ...command]);
8482
7711
  }
8483
- };
8484
- return completionWidget;
7712
+ }
7713
+ return wrappedCommands;
8485
7714
  };
8486
-
8487
- const getCompletionDetailBounds = (completionBounds, borderSize) => {
8488
- return {
8489
- x: completionBounds.x + completionBounds.width - borderSize,
8490
- y: completionBounds.y,
8491
- width: 100,
8492
- height: 100
8493
- };
7715
+ const add$7 = widget => {
7716
+ return addWidget$1(widget, 'EditorRename', render$c);
8494
7717
  };
8495
-
8496
- const getCompletionState = editor => {
8497
- return getWidgetState(editor, Completion);
7718
+ const remove$7 = widget => {
7719
+ return [['Viewlet.dispose', widget.newState.uid]];
8498
7720
  };
8499
-
8500
- const openDetails = editor => {
8501
- const child = getCompletionState(editor);
8502
- if (!child) {
8503
- return editor;
8504
- }
8505
- // TODO avoid closure
8506
- const newStateGenerator = state => {
8507
- const borderSize = 1;
8508
- const newestState = {
7721
+ const createFn = key => {
7722
+ const fn = async state => {
7723
+ const {
7724
+ uid
7725
+ } = state;
7726
+ await invoke$3(`Completions.${key}`, uid);
7727
+ const diff = await invoke$3('Completions.diff2', uid);
7728
+ const commands = await invoke$3('Completions.render2', uid, diff);
7729
+ return {
8509
7730
  ...state,
8510
- content: 'abc',
8511
- ...getCompletionDetailBounds(child, borderSize)
7731
+ commands
8512
7732
  };
8513
- return newestState;
8514
- };
8515
- return addWidgetToEditor(CompletionDetail, CompletionDetail$1, editor, create, newStateGenerator);
8516
- };
8517
-
8518
- const getEdits = async (editor, completionItem) => {
8519
- const child = getCompletionState(editor);
8520
- // @ts-ignore
8521
- const {
8522
- leadingWord} = child;
8523
- const word = completionItem.label;
8524
- const resolvedItem = await resolveCompletion(editor, word, completionItem);
8525
- const inserted = resolvedItem ? resolvedItem.snippet : word;
8526
- // TODO type and dispose commands should be sent to renderer process at the same time
8527
- const {
8528
- selections
8529
- } = editor;
8530
- const [startRowIndex, startColumnIndex] = selections;
8531
- const leadingWordLength = leadingWord.length;
8532
- const replaceRange$1 = new Uint32Array([startRowIndex, startColumnIndex - leadingWordLength, startRowIndex, startColumnIndex]);
8533
- const changes = replaceRange(editor, replaceRange$1, [inserted], '');
8534
- return changes;
8535
- };
8536
- const select = async (editor, completionItem) => {
8537
- const changes = await getEdits(editor, completionItem);
8538
- const index = editor.widgets.indexOf
8539
- // ViewletModuleId.EditorCompletion
8540
- ();
8541
- if (index !== -1) {
8542
- editor.widgets.splice(index, 1);
8543
- editor.completionState = None$1;
8544
- editor.completionUid = 0;
8545
- }
8546
- // TODO dispose completion widget
8547
- // TODO apply edit in editor worker instead of asking renderer worker
8548
- // await RendererWorker.invoke('Viewlet.dispose', state.uid)
8549
- const {
8550
- widgets
8551
- } = editor;
8552
- const newWidgets = removeEditorWidget(widgets, Completion);
8553
- const intermediateEditor = await applyEdit(editor, changes);
8554
- return {
8555
- ...intermediateEditor,
8556
- widgets: newWidgets
8557
7733
  };
7734
+ return fn;
8558
7735
  };
8559
- const selectIndex = (editor, index) => {
8560
- const child = getCompletionState(editor);
8561
- if (!child) {
8562
- return editor;
8563
- }
8564
- const {
8565
- items
8566
- } = child;
8567
- if (index === -1) {
8568
- return editor;
8569
- }
8570
- if (index > items.length) {
8571
- throw new Error('index too large');
8572
- }
8573
- const actualIndex = index;
8574
- const completionItem = items[actualIndex];
8575
- return select(editor, completionItem);
8576
- };
8577
-
8578
- const selectCurrent = editor => {
8579
- const child = getCompletionState(editor);
8580
- if (!child) {
8581
- return editor;
7736
+ const createFns = keys => {
7737
+ const fns = Object.create(null);
7738
+ for (const key of keys) {
7739
+ fns[key] = createFn(key);
8582
7740
  }
8583
- const {
8584
- focusedIndex
8585
- } = child;
8586
- return selectIndex(editor, focusedIndex);
8587
- };
8588
-
8589
- const getCompletionDetailState = editor => {
8590
- return getWidgetState(editor, CompletionDetail);
7741
+ return fns;
8591
7742
  };
7743
+ const {
7744
+ focusFirst,
7745
+ focusIndex: focusIndex$1,
7746
+ focusLast,
7747
+ focusNext: focusNext$1,
7748
+ focusPrevious,
7749
+ handleEditorBlur,
7750
+ handleEditorClick,
7751
+ handleEditorDeleteLeft: handleEditorDeleteLeft$1,
7752
+ handleEditorType: handleEditorType$1,
7753
+ openDetails,
7754
+ selectCurrent,
7755
+ selectIndex,
7756
+ toggleDetails,
7757
+ closeDetails,
7758
+ handleWheel,
7759
+ close
7760
+ } = createFns(['handleEditorType', 'focusFirst', 'focusNext', 'focusPrevious', 'focusLast', 'handleEditorDeleteLeft', 'openDetails', 'focusIndex', 'handleEditorBlur', 'handleEditorClick', 'openDetails', 'selectCurrent', 'selectIndex', 'toggleDetails', 'closeDetails', 'handleWheel', 'close']);
8592
7761
 
8593
- const toggleDetails = editor => {
8594
- const child = getCompletionDetailState(editor);
8595
- if (!child) {
8596
- return openDetails(editor);
8597
- }
8598
- return closeDetails(editor);
7762
+ const EditorCompletionWidget = {
7763
+ __proto__: null,
7764
+ add: add$7,
7765
+ close,
7766
+ closeDetails,
7767
+ focusFirst,
7768
+ focusIndex: focusIndex$1,
7769
+ focusLast,
7770
+ focusNext: focusNext$1,
7771
+ focusPrevious,
7772
+ handleEditorBlur,
7773
+ handleEditorClick,
7774
+ handleEditorDeleteLeft: handleEditorDeleteLeft$1,
7775
+ handleEditorType: handleEditorType$1,
7776
+ handleWheel,
7777
+ openDetails,
7778
+ remove: remove$7,
7779
+ render: render$c,
7780
+ selectCurrent,
7781
+ selectIndex,
7782
+ toggleDetails
8599
7783
  };
8600
7784
 
8601
7785
  const loadContent = async (editorUid, state, position) => {
@@ -8640,45 +7824,26 @@ const handleSashPointerUp = (state, eventX, eventY) => {
8640
7824
  const CodeGeneratorInput$1 = 'CodeGeneratorInput';
8641
7825
  const CodeGeneratorMessage = 'CodeGeneratorMessage';
8642
7826
  const CodeGeneratorWidget = 'CodeGeneratorWidget';
8643
- const ColoredMaskIcon = 'ColoredMaskIcon';
8644
7827
  const DiagnosticError = 'DiagnosticError';
8645
7828
  const DiagnosticWarning = 'DiagnosticWarning';
8646
7829
  const CompletionDetailCloseButton = 'CompletionDetailCloseButton';
8647
7830
  const CompletionDetailContent = 'CompletionDetailContent';
8648
7831
  const Diagnostic = 'Diagnostic';
8649
- const EditorCompletionItem = 'EditorCompletionItem';
8650
- const EditorCompletionItemDeprecated = 'EditorCompletionItemDeprecated';
8651
- const EditorCompletionItemFocused = 'EditorCompletionItemFocused';
8652
- const EditorCompletionItemHighlight = 'EditorCompletionItemHighlight';
8653
7832
  const EditorCursor = 'EditorCursor';
8654
7833
  const EditorRow = 'EditorRow';
8655
7834
  const EditorSelection = 'EditorSelection';
8656
7835
  const EditorSourceActions = 'EditorSourceActions';
8657
7836
  const EditorSourceActionsList = 'EditorSourceActionsList';
8658
- const FileIcon = 'FileIcon';
8659
- const FindWidgetFind = 'FindWidgetFind';
8660
- const FindWidgetMatchCount = 'FindWidgetMatchCount';
8661
- const FindWidgetMatchCountEmpty = 'FindWidgetMatchCountEmpty';
8662
- const FindWidgetReplace = 'FindWidgetReplace';
8663
- const FindWidgetRight = 'FindWidgetRight';
8664
7837
  const HoverDisplayString = 'HoverDisplayString';
8665
7838
  const HoverDocumentation = 'HoverDocumentation';
8666
7839
  const HoverEditorRow = 'HoverEditorRow';
8667
7840
  const HoverProblem = 'HoverProblem';
8668
7841
  const HoverProblemDetail = 'HoverProblemDetail';
8669
7842
  const HoverProblemMessage = 'HoverProblemMessage';
8670
- const IconButton = 'IconButton';
8671
- const IconButtonDisabled = 'IconButtonDisabled';
8672
7843
  const IconClose = 'IconClose';
8673
7844
  const InputBox = 'InputBox';
8674
- const Label = 'Label';
8675
7845
  const MaskIcon = 'MaskIcon';
8676
7846
  const MaskIconSymbolFile = 'MaskIconSymbolFile';
8677
- const MultilineInputBox = 'MultilineInputBox';
8678
- const SearchField = 'SearchField';
8679
- const SearchFieldButton = 'SearchFieldButton';
8680
- const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
8681
- const SearchFieldButtons = 'SearchFieldButtons';
8682
7847
  const SourceActionHeading = 'SourceActionHeading';
8683
7848
  const SourceActionIcon = 'SourceActionIcon';
8684
7849
  const SourceActionItem = 'SourceActionItem';
@@ -8688,11 +7853,6 @@ const Viewlet = 'Viewlet';
8688
7853
  const HandleBeforeInput = 'handleBeforeInput';
8689
7854
  const HandleBlur = 'handleBlur';
8690
7855
  const HandleClick = 'handleClick';
8691
- const HandleClickClose = 'handleClickClose';
8692
- const HandleClickNextMatch = 'handleClickNextMatch';
8693
- const HandleClickPreviousMatch = 'handleClickPreviousMatch';
8694
- const HandleClickReplace = 'handleClickReplace';
8695
- const HandleClickReplaceAll = 'handleClickReplaceAll';
8696
7856
  const HandleClose = 'handleClose';
8697
7857
  const HandleCompositionEnd = 'handleCompositionEnd';
8698
7858
  const HandleCompositionStart = 'handleCompositionStart';
@@ -8701,20 +7861,14 @@ const HandleContextMenu = 'handleContextMenu';
8701
7861
  const HandleCut = 'handleCut';
8702
7862
  const HandleFocus = 'handleFocus';
8703
7863
  const HandleFocusIn = 'handleFocusIn';
8704
- const HandleInput = 'handleInput';
8705
7864
  const HandleMouseMove = 'handleMouseMove';
8706
- const HandleReplaceFocus = 'handleReplaceFocus';
8707
- const HandleReplaceInput = 'handleReplaceInput';
8708
7865
  const HandleSashPointerDown = 'handleSashPointerDown';
8709
7866
  const HandleWheel = 'handleWheel';
8710
7867
 
8711
- const Button = 1;
8712
7868
  const Div = 4;
8713
7869
  const Input = 6;
8714
7870
  const Span = 8;
8715
7871
  const Text = 12;
8716
- const Img = 17;
8717
- const TextArea = 62;
8718
7872
 
8719
7873
  const text = data => {
8720
7874
  return {
@@ -8800,22 +7954,6 @@ const getHoverVirtualDom = (lineInfos, documentation, diagnostics) => {
8800
7954
  return dom;
8801
7955
  };
8802
7956
 
8803
- const AppendToBody = 'Viewlet.appendToBody';
8804
- const Focus = 'focus';
8805
- const RegisterEventListeners = 'Viewlet.registerEventListeners';
8806
- const SetSelectionByName = 'Viewlet.setSelectionByName';
8807
- const SetValueByName = 'Viewlet.setValueByName';
8808
- const SetFocusContext = 'Viewlet.setFocusContext';
8809
- const SetBounds = 'setBounds';
8810
- const SetBounds2 = 'Viewlet.setBounds';
8811
- const SetContentHeight = 'setContentHeight';
8812
- const SetCss = 'Viewlet.setCss';
8813
- const SetDom2 = 'Viewlet.setDom2';
8814
- const SetNegativeMargin = 'setNegativeMargin';
8815
- const SetScrollBar = 'setScrollBar';
8816
- const SetValue = 'setValue';
8817
- const SetUid = 'Viewlet.setUid';
8818
-
8819
7957
  const renderHoverDom = {
8820
7958
  isEqual(oldState, newState) {
8821
7959
  return oldState.lineInfos === newState.lineInfos && oldState.documentation === newState.documentation && oldState.diagnostics === newState.diagnostics;
@@ -8825,7 +7963,7 @@ const renderHoverDom = {
8825
7963
  return [/* method */SetDom2, dom];
8826
7964
  }
8827
7965
  };
8828
- const renderBounds$5 = {
7966
+ const renderBounds$3 = {
8829
7967
  isEqual(oldState, newState) {
8830
7968
  return oldState.x === newState.x && oldState.y === newState.y;
8831
7969
  },
@@ -8839,10 +7977,10 @@ const renderBounds$5 = {
8839
7977
  return [SetBounds, x, y, width, height];
8840
7978
  }
8841
7979
  };
8842
- const render$e = [renderHoverDom, renderBounds$5];
7980
+ const render$b = [renderHoverDom, renderBounds$3];
8843
7981
  const renderHover = (oldState, newState) => {
8844
7982
  const commands = [];
8845
- for (const item of render$e) {
7983
+ for (const item of render$b) {
8846
7984
  if (!item.isEqual(oldState, newState)) {
8847
7985
  commands.push(item.apply(oldState, newState));
8848
7986
  }
@@ -8868,6 +8006,21 @@ const focusNext = state => {
8868
8006
  return focusIndex(state, nextIndex);
8869
8007
  };
8870
8008
 
8009
+ const getWidgetInvoke = widgetId => {
8010
+ switch (widgetId) {
8011
+ case ColorPicker:
8012
+ return invoke$6;
8013
+ case Completion:
8014
+ return invoke$3;
8015
+ case Find:
8016
+ return invoke$2;
8017
+ case Rename:
8018
+ return invoke$4;
8019
+ default:
8020
+ return undefined;
8021
+ }
8022
+ };
8023
+
8871
8024
  const updateWidget = (editor, widgetId, newState) => {
8872
8025
  // TODO avoid closure
8873
8026
  const isWidget = widget => {
@@ -8888,28 +8041,72 @@ const updateWidget = (editor, widgetId, newState) => {
8888
8041
  };
8889
8042
  };
8890
8043
 
8891
- const getInvoke = () => {
8892
- return invoke$4;
8893
- };
8894
- const executeWidgetCommand = async (editor, name, method, uid, widgetId, ...params) => {
8895
- const invoke = getInvoke();
8044
+ const executeWidgetCommand = async (editor, name, method, _uid, widgetId, ...params) => {
8045
+ const invoke = getWidgetInvoke(widgetId);
8896
8046
  const actualMethod = method.slice(name.length + 1);
8047
+ const widget = editor.widgets.find(widget => widget.id === widgetId);
8048
+ if (!widget) {
8049
+ return editor;
8050
+ }
8051
+ const {
8052
+ uid
8053
+ } = widget.newState;
8054
+ number(uid);
8897
8055
  await invoke(`${name}.${actualMethod}`, uid, ...params);
8898
- const diff = await invoke(`${name}.diff2`, uid);
8899
- const commands = await invoke(`${name}.render2`, uid, diff);
8900
8056
  const isWidget = widget => {
8901
8057
  return widget.id === widgetId;
8902
8058
  };
8059
+ const latestEditor = getEditor(editor.uid);
8060
+ const childIndex1 = latestEditor.widgets.findIndex(isWidget);
8061
+ if (childIndex1 === -1) {
8062
+ return latestEditor;
8063
+ }
8064
+ const diff = await invoke(`${name}.diff2`, uid);
8065
+ const commands = await invoke(`${name}.render2`, uid, diff);
8903
8066
  const childIndex = editor.widgets.findIndex(isWidget);
8904
- const childWidget = editor.widgets[childIndex];
8067
+ if (childIndex === -1) {
8068
+ return latestEditor;
8069
+ }
8070
+ const childWidget = latestEditor.widgets[childIndex];
8905
8071
  const newState = {
8906
- ...childWidget.state,
8072
+ ...childWidget.newState,
8907
8073
  commands
8908
8074
  };
8909
- const newEditor = updateWidget(editor, widgetId, newState);
8075
+ const newEditor = updateWidget(latestEditor, widgetId, newState);
8910
8076
  return newEditor;
8911
8077
  };
8912
8078
 
8079
+ const RE_WORD = /[\w\-]+$/;
8080
+ const getWordAtOffset = editor => {
8081
+ const {
8082
+ lines,
8083
+ selections
8084
+ } = editor;
8085
+ const rowIndex = selections[0];
8086
+ const columnIndex = selections[1];
8087
+ const line = lines[rowIndex];
8088
+ const part = line.slice(0, columnIndex);
8089
+ const wordMatch = part.match(RE_WORD);
8090
+ if (wordMatch) {
8091
+ return wordMatch[0];
8092
+ }
8093
+ return '';
8094
+ };
8095
+
8096
+ const FocusEditor = 12;
8097
+ const FocusEditorCompletions = 9;
8098
+ const FocusEditorRename = 11;
8099
+ const FocusEditorText = 12;
8100
+ const FocusFindWidget = 16;
8101
+ const FocusSourceActions = 38;
8102
+ const FocusFindWidgetReplace = 43;
8103
+ const FocusFindWidgetReplaceButton = 46;
8104
+ const FocusFindWidgetReplaceAllButton = 47;
8105
+ const FocusFindWidgetCloseButton = 48;
8106
+ const FocusFindWidgetNextMatchButton = 49;
8107
+ const FocusFindWidgetPreviousMatchButton = 50;
8108
+ const FocusEditorCodeGenerator = 52;
8109
+
8913
8110
  const getPositionAtCursor = editorUid => {
8914
8111
  const editor = getEditor(editorUid);
8915
8112
  return getPositionAtCursor$1(editor);
@@ -8921,35 +8118,60 @@ const getWordAt = (editorUid, rowIndex, columnIndex) => {
8921
8118
  } = getWordAt$1(editor, rowIndex, columnIndex);
8922
8119
  return word;
8923
8120
  };
8924
-
8925
- const replaceTextOccurrences = (editor, matches, oldValue, newValue) => {
8926
- const ranges = [];
8927
- const oldValueLength = oldValue.length;
8928
- for (let i = 0; i < matches.length; i += 2) {
8929
- const startRowIndex = matches[i];
8930
- const startColumnIndex = matches[i + 1];
8931
- const endRowIndex = matches[i];
8932
- const endColumnIndex = matches[i] + oldValueLength;
8933
- ranges.push(startRowIndex, startColumnIndex, endRowIndex, endColumnIndex);
8934
- }
8935
- return replaceRange(editor, ranges, [newValue], ReplaceAll$2);
8121
+ const getWordAtOffset2 = editorUid => {
8122
+ const editor = getEditor(editorUid);
8123
+ const word = getWordAtOffset(editor);
8124
+ return word;
8936
8125
  };
8937
-
8938
- const replaceAll$1 = async editor => {
8939
- const state = getFindState(editor);
8940
- if (!state) {
8941
- return editor;
8942
- }
8126
+ const getWordBefore2 = (editorUid, rowIndex, columnIndex) => {
8127
+ const editor = getEditor(editorUid);
8128
+ const word = getWordBefore(editor, rowIndex, columnIndex);
8129
+ return word;
8130
+ };
8131
+ const getLines2 = editorUid => {
8132
+ const editor = getEditor(editorUid);
8943
8133
  const {
8944
- matches,
8945
- value,
8946
- replacement
8947
- } = state;
8948
- const edits = replaceTextOccurrences(editor, matches, value, replacement);
8134
+ lines
8135
+ } = editor;
8136
+ return lines;
8137
+ };
8138
+ const getSelections2 = editorUid => {
8139
+ const editor = getEditor(editorUid);
8140
+ const {
8141
+ selections
8142
+ } = editor;
8143
+ return selections;
8144
+ };
8145
+ const closeWidget2 = async (editorUid, widgetId, widgetName, unsetAdditionalFocus$1) => {
8146
+ const editor = getEditor(editorUid);
8147
+ const invoke = getWidgetInvoke(widgetId);
8148
+ const {
8149
+ widgets
8150
+ } = editor;
8151
+ const index = widgets.findIndex(widget => widget.id === widgetId);
8152
+ if (index === -1) {
8153
+ return;
8154
+ }
8155
+ await invoke(`${widgetName}.dispose`);
8156
+ const newWidgets = [...widgets.slice(0, index), ...widgets.slice(index + 1)];
8157
+ const newEditor = {
8158
+ ...editor,
8159
+ widgets: newWidgets,
8160
+ focused: true
8161
+ };
8162
+ set$4(editorUid, editor, newEditor);
8163
+ await setFocus(FocusEditorText);
8164
+ if (unsetAdditionalFocus$1) {
8165
+ await unsetAdditionalFocus(unsetAdditionalFocus$1);
8166
+ }
8167
+ };
8168
+ const closeFind2 = async editorUid => {
8169
+ await closeWidget2(editorUid, Find, 'FindWidget', 0);
8170
+ };
8171
+ const applyEdits2 = async (editorUid, edits) => {
8172
+ const editor = getEditor(editorUid);
8949
8173
  const newEditor = await applyEdit(editor, edits);
8950
- const newState = refresh$1(newEditor, state, value);
8951
- const newestEditor = updateWidget(newEditor, Find, newState);
8952
- return newestEditor;
8174
+ set$4(editorUid, editor, newEditor);
8953
8175
  };
8954
8176
 
8955
8177
  const pending = Object.create(null);
@@ -9046,20 +8268,6 @@ const CtrlCmd = 1 << 11 >>> 0;
9046
8268
  const Shift = 1 << 10 >>> 0;
9047
8269
  const Alt = 1 << 9 >>> 0;
9048
8270
 
9049
- const FocusEditor = 12;
9050
- const FocusEditorCompletions = 9;
9051
- const FocusEditorRename = 11;
9052
- const FocusEditorText = 12;
9053
- const FocusFindWidget = 16;
9054
- const FocusSourceActions = 38;
9055
- const FocusFindWidgetReplace = 43;
9056
- const FocusFindWidgetReplaceButton = 46;
9057
- const FocusFindWidgetReplaceAllButton = 47;
9058
- const FocusFindWidgetCloseButton = 48;
9059
- const FocusFindWidgetNextMatchButton = 49;
9060
- const FocusFindWidgetPreviousMatchButton = 50;
9061
- const FocusEditorCodeGenerator = 52;
9062
-
9063
8271
  const getKeyBindings = () => {
9064
8272
  return [{
9065
8273
  key: Escape,
@@ -9167,7 +8375,7 @@ const getKeyBindings = () => {
9167
8375
  when: FocusEditorCompletions
9168
8376
  }, {
9169
8377
  key: Escape,
9170
- command: 'Editor.closeCompletion',
8378
+ command: 'EditorCompletion.close',
9171
8379
  when: FocusEditorCompletions
9172
8380
  }, {
9173
8381
  key: End,
@@ -9600,7 +8808,7 @@ const moveLineUp = editor => {
9600
8808
  };
9601
8809
 
9602
8810
  const Link$1 = 'Link';
9603
- const Function$1 = 'Function';
8811
+ const Function = 'Function';
9604
8812
  const Parameter = 'Parameter';
9605
8813
  const Type = 'Type';
9606
8814
  const VariableName = 'VariableName';
@@ -9659,7 +8867,7 @@ const getDecorationClassName = type => {
9659
8867
  case Ts3073:
9660
8868
  case Ts3077:
9661
8869
  case Ts3088:
9662
- return Function$1;
8870
+ return Function;
9663
8871
  case Ts1792:
9664
8872
  case Ts1793:
9665
8873
  return Parameter;
@@ -9982,7 +9190,6 @@ const getLineInfoDefault = (line, tokenResults, embeddedResults, decorations, To
9982
9190
  const decorationType = decorations[++decorationIndex];
9983
9191
  // @ts-ignore
9984
9192
  decorations[++decorationIndex];
9985
- // console.log('MATCHING DECORATION', {
9986
9193
  // decorationIndex,
9987
9194
  // decorationLength,
9988
9195
  // decorationType,
@@ -10218,7 +9425,7 @@ const getSelectionsVirtualDom = selections => {
10218
9425
  return dom;
10219
9426
  };
10220
9427
 
10221
- const addWidget$1 = widget => {
9428
+ const addWidget = widget => {
10222
9429
  const module = get$5(widget.id);
10223
9430
  if (!module) {
10224
9431
  throw new Error('unsupported widget');
@@ -10294,7 +9501,7 @@ const renderScrollBarX = {
10294
9501
  return [/* method */'setScrollBarHorizontal', /* scrollBarX */scrollBarX, /* scrollBarWidth */scrollBarWidth, /* deltaX */newState.deltaX];
10295
9502
  }
10296
9503
  };
10297
- const renderFocus$2 = {
9504
+ const renderFocus$1 = {
10298
9505
  isEqual(oldState, newState) {
10299
9506
  return oldState.focused === newState.focused;
10300
9507
  },
@@ -10302,7 +9509,7 @@ const renderFocus$2 = {
10302
9509
  // TODO avoid side effect
10303
9510
  if (newState.focused) {
10304
9511
  const FocusEditorText = 12;
10305
- invoke$5('Focus.setFocus', FocusEditorText);
9512
+ invoke$7('Focus.setFocus', FocusEditorText);
10306
9513
  }
10307
9514
  return [/* method */'setFocused', newState.focused];
10308
9515
  }
@@ -10368,7 +9575,7 @@ const renderWidgets = {
10368
9575
  }
10369
9576
  const addCommands = [];
10370
9577
  for (const addedWidget of addedWidgets) {
10371
- const childCommands = addWidget$1(addedWidget);
9578
+ const childCommands = addWidget(addedWidget);
10372
9579
  if (childCommands.length > 0) {
10373
9580
  addCommands.push(...childCommands);
10374
9581
  }
@@ -10392,7 +9599,7 @@ const renderWidgets = {
10392
9599
  },
10393
9600
  multiple: true
10394
9601
  };
10395
- const render$d = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus$2, renderDecorations, renderGutterInfo, renderWidgets];
9602
+ const render$a = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus$1, renderDecorations, renderGutterInfo, renderWidgets];
10396
9603
  const renderEditor = async id => {
10397
9604
  const instance = get$4(id);
10398
9605
  if (!instance) {
@@ -10404,7 +9611,7 @@ const renderEditor = async id => {
10404
9611
  } = instance;
10405
9612
  const commands = [];
10406
9613
  set$4(id, newState, newState);
10407
- for (const item of render$d) {
9614
+ for (const item of render$a) {
10408
9615
  if (!item.isEqual(oldState, newState)) {
10409
9616
  const result = await item.apply(oldState, newState);
10410
9617
  // @ts-ignore
@@ -10470,7 +9677,7 @@ const keep = [
10470
9677
  // 'ColorPicker.handleSliderPointerDown',
10471
9678
  // 'ColorPicker.handleSliderPointerMove',
10472
9679
  // 'ColorPicker.loadContent',
10473
- 'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render', 'Editor.getKeyBindings', 'Editor.getPositionAtCursor', 'Editor.getWordAt2', 'Editor.getWordAtOffset2', 'Editor.getQuickPickMenuEntries',
9680
+ 'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render', 'Editor.getKeyBindings', 'Editor.getPositionAtCursor', 'Editor.getWordAt2', 'Editor.getWordAtOffset2', 'Editor.getWordBefore2', 'Editor.getLines2', 'Editor.applyEdit2', 'Editor.applyEdits2', 'Editor.closeFind2', 'Editor.closeWidget2', 'Editor.getSelections2', 'Editor.getQuickPickMenuEntries',
10474
9681
  // 'ColorPicker.render',
10475
9682
  'Editor.getText', 'Editor.getSelections', 'Font.ensure', 'SendMessagePortToExtensionHostWorker.sendMessagePortToExtensionHostWorker', 'Hover.getHoverInfo', 'Hover.handleSashPointerDown', 'Hover.handleSashPointerMove', 'Hover.handleSashPointerUp', 'Hover.loadContent', 'Hover.render', 'Initialize.initialize', 'ActivateByEvent.activateByEvent'];
10476
9683
 
@@ -10554,14 +9761,13 @@ const wrapCommands = commands => {
10554
9761
  const commandMap = {
10555
9762
  'ActivateByEvent.activateByEvent': activateByEvent,
10556
9763
  'CodeGenerator.accept': codeGeneratorAccept,
10557
- 'ColorPicker.loadContent': loadContent$3,
9764
+ 'ColorPicker.loadContent': loadContent$2,
10558
9765
  'Editor.addCursorAbove': addCursorAbove,
10559
9766
  'Editor.addCursorBelow': addCursorBelow,
10560
9767
  'Editor.applyEdit': applyEdit,
10561
9768
  'Editor.braceCompletion': braceCompletion,
10562
9769
  'Editor.cancelSelection': cancelSelection,
10563
9770
  'Editor.closeCodeGenerator': closeCodeGenerator,
10564
- 'Editor.closeCompletion': closeCompletion,
10565
9771
  'Editor.closeFind': closeFind,
10566
9772
  'Editor.closeRename': closeRename,
10567
9773
  'Editor.closeSourceAction': closeSourceAction,
@@ -10596,25 +9802,31 @@ const commandMap = {
10596
9802
  'Editor.deleteRight': deleteCharacterRight,
10597
9803
  'Editor.deleteWordLeft': deleteWordLeft,
10598
9804
  'Editor.deleteWordPartLeft': deleteWordPartLeft,
9805
+ 'Editor.applyEdit2': applyEdits2,
9806
+ 'Editor.closeFind2': closeFind2,
9807
+ 'Editor.closeWidget2': closeWidget2,
10599
9808
  'Editor.deleteWordPartRight': deleteWordPartRight,
10600
9809
  'Editor.deleteWordRight': deleteWordRight,
10601
9810
  'Editor.executeWidgetCommand': executeWidgetCommand,
10602
9811
  'Editor.findAllReferences': findAllReferences,
10603
9812
  'Editor.format': format,
10604
9813
  'Editor.getKeyBindings': getKeyBindings,
9814
+ 'Editor.getLines2': getLines2,
10605
9815
  'Editor.getPositionAtCursor': getPositionAtCursor,
10606
9816
  'Editor.getQuickPickMenuEntries': getQuickPickMenuEntries,
10607
9817
  'Editor.getSelections': getSelections,
9818
+ 'Editor.getSelections2': getSelections2,
10608
9819
  'Editor.getText': getText,
10609
9820
  'Editor.getWordAt': getWordAt$1,
10610
9821
  'Editor.getWordAt2': getWordAt,
10611
- 'Editor.getWordAtOffset2': getWordAt,
9822
+ 'Editor.getWordAtOffset2': getWordAtOffset2,
10612
9823
  'Editor.getWordBefore': getWordBefore,
9824
+ 'Editor.getWordBefore2': getWordBefore2,
10613
9825
  'Editor.goToDefinition': goToDefinition,
10614
9826
  'Editor.goToTypeDefinition': goToTypeDefinition,
10615
9827
  'Editor.handleBeforeInput': handleBeforeInput,
10616
9828
  'Editor.handleBeforeInputFromContentEditable': handleBeforeInputFromContentEditable,
10617
- 'Editor.handleBlur': handleBlur$1,
9829
+ 'Editor.handleBlur': handleBlur,
10618
9830
  'Editor.handleContextMenu': handleContextMenu,
10619
9831
  'Editor.handleDoubleClick': handleDoubleClick,
10620
9832
  'Editor.handleFocus': handleFocus,
@@ -10650,6 +9862,21 @@ const commandMap = {
10650
9862
  'Editor.openCodeGenerator': openCodeGenerator,
10651
9863
  'Editor.openColorPicker': openColorPicker,
10652
9864
  'Editor.openCompletion': openCompletion,
9865
+ 'EditorCompletion.closeDetails': closeDetails,
9866
+ 'EditorCompletion.focusFirst': focusFirst,
9867
+ 'EditorCompletion.focusIndex': focusIndex$1,
9868
+ 'EditorCompletion.focusNext': focusNext$1,
9869
+ 'EditorCompletion.focusPrevious': focusPrevious,
9870
+ 'EditorCompletion.handleEditorBlur': handleEditorBlur,
9871
+ 'EditorCompletion.handleEditorClick': handleEditorClick,
9872
+ 'EditorCompletion.handleEditorDeleteLeft': handleEditorDeleteLeft$1,
9873
+ 'EditorCompletion.handleEditorType': handleEditorType$1,
9874
+ 'EditorCompletion.handleWheel': handleWheel,
9875
+ 'EditorCompletion.openDetails': openDetails,
9876
+ 'EditorCompletion.selectCurrent': selectCurrent,
9877
+ 'EditorCompletion.close': close,
9878
+ 'EditorCompletion.selectIndex': selectIndex,
9879
+ 'EditorCompletion.toggleDetails': toggleDetails,
10653
9880
  'Editor.openFind': openFind,
10654
9881
  'Editor.openFind2': openFind2,
10655
9882
  'Editor.openRename': openRename,
@@ -10679,7 +9906,7 @@ const commandMap = {
10679
9906
  'Editor.selectWordRight': selectWordRight,
10680
9907
  'Editor.setDecorations': setDecorations,
10681
9908
  'Editor.setDelta': setDelta,
10682
- 'Editor.setDeltaY': setDeltaY$1,
9909
+ 'Editor.setDeltaY': setDeltaY,
10683
9910
  'Editor.setLanguageId': setLanguageId,
10684
9911
  'Editor.setSelections': setSelections,
10685
9912
  'Editor.showHover': showHover,
@@ -10696,47 +9923,9 @@ const commandMap = {
10696
9923
  'Editor.undo': undo,
10697
9924
  'Editor.unIndent': editorUnindent,
10698
9925
  'Editor.updateDiagnostics': updateDiagnostics,
10699
- 'EditorCompletion.advance': advance,
10700
- 'EditorCompletion.closeDetails': closeDetails,
10701
- 'EditorCompletion.focusFirst': focusFirst,
10702
- 'EditorCompletion.focusIndex': focusIndex$1,
10703
- 'EditorCompletion.focusNext': focusNext$1,
10704
- 'EditorCompletion.focusPrevious': focusPrevious,
10705
- 'EditorCompletion.handleEditorBlur': handleEditorBlur,
10706
- 'EditorCompletion.handleEditorClick': handleEditorClick,
10707
- 'EditorCompletion.handleEditorDeleteLeft': handleEditorDeleteLeft$2,
10708
- 'EditorCompletion.handleEditorType': handleEditorType$2,
10709
- 'EditorCompletion.handleWheel': handleWheel,
10710
- 'EditorCompletion.loadContent': loadContent$2,
10711
- 'EditorCompletion.openDetails': openDetails,
10712
- 'EditorCompletion.selectCurrent': selectCurrent,
10713
- 'EditorCompletion.selectIndex': selectIndex,
10714
- 'EditorCompletion.toggleDetails': toggleDetails,
10715
9926
  'EditorSourceActions.focusNext': focusNext,
10716
9927
  'FindWidget.close': close$1,
10717
- 'FindWidget.focusCloseButton': focusCloseButton,
10718
- 'FindWidget.focusFind': focusFind,
10719
- 'FindWidget.focusFirst': focusFirst$1,
10720
- 'FindWidget.focusIndex': focusIndex$2,
10721
- 'FindWidget.focusLast': focusLast,
10722
- 'FindWidget.focusNext': focusNext$2,
10723
- 'FindWidget.focusNextMatchButton': focusNextMatchButton,
10724
- 'FindWidget.focusPrevious': focusPrevious$1,
10725
- 'FindWidget.focusPreviousMatchButton': focusPreviousMatchButton,
10726
- 'FindWidget.focusReplace': focusReplace,
10727
- 'FindWidget.focusReplaceAllButton': focusReplaceAllButton,
10728
- 'FindWidget.focusReplaceButton': focusReplaceButton,
10729
- 'FindWidget.focusToggleReplace': focusToggleReplaceButton,
10730
- 'FindWidget.handleBlur': handleBlur,
10731
- 'FindWidget.handleFocus': handleFindWidgetFocus,
10732
- 'FindWidget.handleInput': handleInput,
10733
- 'FindWidget.handleReplaceAllFocus': handleReplaceAllFocus,
10734
- 'FindWidget.handleReplaceFocus': handleReplaceFocus,
10735
- 'FindWidget.handleReplaceInput': handleReplaceInput,
10736
- 'FindWidget.handleToggleReplaceFocus': handleToggleReplaceFocus,
10737
9928
  'FindWidget.loadContent': loadContent$1,
10738
- 'FindWidget.replaceAll': replaceAll$1,
10739
- 'FindWidget.toggleReplace': toggleReplace,
10740
9929
  'Font.ensure': ensure,
10741
9930
  'Hover.getHoverInfo': getEditorHoverInfo,
10742
9931
  'Hover.handleSashPointerDown': handleSashPointerDown,
@@ -10804,55 +9993,12 @@ const listen = async () => {
10804
9993
  listen$5(ipc);
10805
9994
  };
10806
9995
 
10807
- const isFunctional = widgetId => {
10808
- switch (widgetId) {
10809
- case ColorPicker:
10810
- case Rename:
10811
- // case WidgetId.Completion:
10812
- return true;
10813
- default:
10814
- return false;
10815
- }
10816
- };
10817
- const addWidget = (widget, id, render) => {
10818
- const commands = render(widget);
10819
- // TODO how to generate a unique integer id
10820
- // that doesn't collide with ids created in renderer worker?
10821
- // @ts-ignore
10822
- const {
10823
- uid
10824
- } = widget.newState;
10825
- const allCommands = [];
10826
- allCommands.push(['Viewlet.createFunctionalRoot', id, uid, isFunctional(widget.id)]);
10827
- allCommands.push(...commands);
10828
- if (isFunctional(widget.id)) {
10829
- allCommands.push(['Viewlet.appendToBody', uid]);
10830
- } else {
10831
- allCommands.push(['Viewlet.send', uid, 'appendWidget']);
10832
- }
10833
- const focusCommandIndex = allCommands.findIndex(command => {
10834
- return command[2] === 'focus' || command[0] === 'Viewlet.focusSelector';
10835
- });
10836
- // TODO have separate rendering functions, e.g.
10837
- // 1. renderDom
10838
- // 2. renderAriaAnnouncement
10839
- // 3. renderFocus
10840
- // to ensure that focus is always after the element is added to the dom
10841
- if (focusCommandIndex !== -1) {
10842
- const command = allCommands[focusCommandIndex];
10843
- allCommands.splice(focusCommandIndex, 1);
10844
- allCommands.push(command);
10845
- }
10846
- return allCommands;
10847
- };
10848
-
10849
9996
  const removeWidget = widget => {
10850
9997
  // @ts-ignore
10851
9998
  return [['Viewlet.send', widget.newState.uid, 'dispose']];
10852
9999
  };
10853
10000
 
10854
10001
  const CodeGeneratorInput = 'CodeGeneratorInput';
10855
- const ToggleReplace$1 = 'ToggleReplace';
10856
10002
 
10857
10003
  const getCodeGeneratorVirtualDom = state => {
10858
10004
  const escapeToClose$1 = escapeToClose();
@@ -10883,425 +10029,9 @@ const renderContent$1 = {
10883
10029
  return [SetDom2, newState.uid, dom];
10884
10030
  }
10885
10031
  };
10886
- const renderBounds$4 = {
10887
- isEqual(oldState, newState) {
10888
- return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
10889
- },
10890
- apply(oldState, newState) {
10891
- const {
10892
- x,
10893
- y,
10894
- width,
10895
- height
10896
- } = newState;
10897
- return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
10898
- }
10899
- };
10900
- const renderFocus$1 = {
10901
- isEqual(oldState, newState) {
10902
- return oldState.focused === newState.focused && oldState.focusSource === newState.focusSource;
10903
- },
10904
- apply(oldState, newState) {
10905
- return [Focus, '.CodeGeneratorInput', newState.focusSource];
10906
- }
10907
- };
10908
- const render$c = [renderContent$1, renderBounds$4, renderFocus$1];
10909
- const renderFull$3 = (oldState, newState) => {
10910
- const commands = [];
10911
- for (const item of render$c) {
10912
- if (!item.isEqual(oldState, newState)) {
10913
- commands.push(item.apply(oldState, newState));
10914
- }
10915
- }
10916
- return commands;
10917
- };
10918
-
10919
- const render$b = widget => {
10920
- const commands = renderFull$3(widget.oldState, widget.newState);
10921
- const wrappedCommands = [];
10922
- const {
10923
- uid
10924
- } = widget.newState;
10925
- for (const command of commands) {
10926
- if (command[0] === SetDom2) {
10927
- wrappedCommands.push(command);
10928
- } else {
10929
- // @ts-ignore
10930
- wrappedCommands.push(['Viewlet.send', uid, ...command]);
10931
- }
10932
- }
10933
- return wrappedCommands;
10934
- };
10935
- const add$7 = widget => {
10936
- return addWidget(widget, 'EditorCodeGenerator', render$b);
10937
- };
10938
- const remove$7 = removeWidget;
10939
-
10940
- const EditorCodeGeneratorWidget = {
10941
- __proto__: null,
10942
- add: add$7,
10943
- remove: remove$7,
10944
- render: render$b
10945
- };
10946
-
10947
- const renderFull$2 = (oldState, newState) => {
10948
- const commands = [...newState.commands];
10949
- // @ts-ignore
10950
- newState.commands = [];
10951
- return commands;
10952
- };
10953
-
10954
- const render$a = widget => {
10955
- const commands = renderFull$2(widget.oldState, widget.newState);
10956
- const wrappedCommands = [];
10957
- const {
10958
- uid
10959
- } = widget.newState;
10960
- for (const command of commands) {
10961
- if (command[0] === SetDom2 || command[0] === SetCss || command[0] === AppendToBody || command[0] === SetBounds2 || command[0] === RegisterEventListeners || command[0] === SetUid) {
10962
- wrappedCommands.push(command);
10963
- } else {
10964
- wrappedCommands.push(['Viewlet.send', uid, ...command]);
10965
- }
10966
- }
10967
- return wrappedCommands;
10968
- };
10969
- const add$6 = widget => {
10970
- return addWidget(widget, 'ColorPicker', render$a);
10971
- };
10972
- const remove$6 = removeWidget;
10973
- const Commands$1 = {};
10974
-
10975
- const EditorColorPickerWidget = {
10976
- __proto__: null,
10977
- Commands: Commands$1,
10978
- add: add$6,
10979
- remove: remove$6,
10980
- render: render$a
10981
- };
10982
-
10983
- const getCompletionDetailVirtualDom = content => {
10984
- const dom = [{
10985
- type: Div,
10986
- className: 'Viewlet EditorCompletionDetails',
10987
- childCount: 2
10988
- }, {
10989
- type: Div,
10990
- className: CompletionDetailContent,
10991
- childCount: 1
10992
- }, text(content), {
10993
- type: Div,
10994
- className: CompletionDetailCloseButton,
10995
- onClick: HandleClose,
10996
- childCount: 1
10997
- }, {
10998
- type: Div,
10999
- className: `${MaskIcon} ${IconClose}`,
11000
- childCount: 0
11001
- }];
11002
- return dom;
11003
- };
11004
-
11005
- const renderParts = (render, oldState, newState) => {
11006
- const commands = [];
11007
- for (const item of render) {
11008
- if (!item.isEqual(oldState, newState)) {
11009
- commands.push(item.apply(oldState, newState));
11010
- }
11011
- }
11012
- return commands;
11013
- };
11014
-
11015
- const renderContent = {
11016
- isEqual(oldState, newState) {
11017
- return oldState.content === newState.content;
11018
- },
11019
- apply(oldState, newState) {
11020
- const dom = getCompletionDetailVirtualDom(newState.content);
11021
- return [SetDom2, newState.uid, dom];
11022
- }
11023
- };
11024
- const renderBounds$3 = {
11025
- isEqual(oldState, newState) {
11026
- return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
11027
- },
11028
- apply(oldState, newState) {
11029
- const {
11030
- x,
11031
- y,
11032
- width,
11033
- height
11034
- } = newState;
11035
- return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
11036
- }
11037
- };
11038
- const render$9 = [renderContent, renderBounds$3];
11039
- const renderFull$1 = (oldState, newState) => {
11040
- return renderParts(render$9, oldState, newState);
11041
- };
11042
-
11043
- const render$8 = widget => {
11044
- const commands = renderFull$1(widget.oldState, widget.newState);
11045
- const wrappedCommands = [];
11046
- const {
11047
- uid
11048
- } = widget.newState;
11049
- for (const command of commands) {
11050
- if (command[0] === SetDom2) {
11051
- wrappedCommands.push(command);
11052
- } else {
11053
- wrappedCommands.push(['Viewlet.send', uid, ...command]);
11054
- }
11055
- }
11056
- return wrappedCommands;
11057
- };
11058
- const add$5 = widget => {
11059
- return addWidget(widget, 'EditorCompletionDetails', render$8);
11060
- };
11061
- const remove$5 = removeWidget;
11062
- const handleEditorType$1 = (editor, state) => {
11063
- const completionState = getCompletionState(editor);
11064
- if (!completionState) {
11065
- return editor;
11066
- }
11067
- const {
11068
- x
11069
- } = getPositionAtCursor$1(editor);
11070
- const detailX = x + completionState.width - state.borderSize;
11071
- return {
11072
- ...state,
11073
- x: detailX
11074
- };
11075
- };
11076
- const handleEditorDeleteLeft$1 = (editor, state) => {
11077
- const completionState = getCompletionState(editor);
11078
- if (!completionState) {
11079
- return editor;
11080
- }
11081
- const {
11082
- x
11083
- } = getPositionAtCursor$1(editor);
11084
- const detailX = x + completionState.width - state.borderSize;
11085
- return {
11086
- ...state,
11087
- x: detailX
11088
- };
11089
- };
11090
-
11091
- const EditorCompletionDetailWidget = {
11092
- __proto__: null,
11093
- add: add$5,
11094
- handleEditorDeleteLeft: handleEditorDeleteLeft$1,
11095
- handleEditorType: handleEditorType$1,
11096
- remove: remove$5,
11097
- render: render$8
11098
- };
11099
-
11100
- const CheckBox = 'checkbox';
11101
- const Group = 'group';
11102
- const None = 'none';
11103
- const Option = 'option';
11104
-
11105
- const getFileIconVirtualDom = icon => {
11106
- return {
11107
- type: Img,
11108
- className: FileIcon,
11109
- src: icon,
11110
- role: None,
11111
- childCount: 0
11112
- };
11113
- };
11114
-
11115
- const getIconDom = (fileIcon, symbolName) => {
11116
- if (fileIcon) {
11117
- return getFileIconVirtualDom(fileIcon);
11118
- }
11119
- return {
11120
- type: Div,
11121
- className: `${ColoredMaskIcon} ${symbolName}`,
11122
- childCount: 0
11123
- };
11124
- };
11125
-
11126
- const label1 = {
11127
- type: Div,
11128
- className: Label,
11129
- childCount: 1
11130
- };
11131
- const completionHighlight = {
11132
- type: Span,
11133
- className: EditorCompletionItemHighlight,
11134
- childCount: 1
11135
- };
11136
- const getHighlightedLabelDom = (label, highlights) => {
11137
- if (highlights.length === 0) {
11138
- return [label1, text(label)];
11139
- }
11140
- const dom = [];
11141
- const labelDom = {
11142
- type: Div,
11143
- className: Label,
11144
- childCount: 0
11145
- };
11146
- dom.push(labelDom);
11147
- let position = 0;
11148
- for (let i = 0; i < highlights.length; i += 2) {
11149
- const highlightStart = highlights[i];
11150
- const highlightEnd = highlights[i + 1];
11151
- if (position < highlightStart) {
11152
- const beforeText = label.slice(position, highlightStart);
11153
- labelDom.childCount++;
11154
- dom.push(text(beforeText));
11155
- }
11156
- const highlightText = label.slice(highlightStart, highlightEnd);
11157
- labelDom.childCount++;
11158
- dom.push(completionHighlight, text(highlightText));
11159
- position = highlightEnd;
11160
- }
11161
- if (position < label.length) {
11162
- const afterText = label.slice(position);
11163
- labelDom.childCount++;
11164
- dom.push(text(afterText));
11165
- }
11166
- return dom;
11167
- };
11168
-
11169
- const getCompletionItemVirtualDom = visibleItem => {
11170
- const {
11171
- top,
11172
- label,
11173
- symbolName,
11174
- highlights,
11175
- focused,
11176
- deprecated,
11177
- fileIcon
11178
- } = visibleItem;
11179
- let className = EditorCompletionItem;
11180
- if (focused) {
11181
- className += ' ' + EditorCompletionItemFocused;
11182
- }
11183
- if (deprecated) {
11184
- className += ' ' + EditorCompletionItemDeprecated;
11185
- }
11186
- return [{
11187
- type: Div,
11188
- role: Option,
11189
- className,
11190
- top,
11191
- childCount: 2
11192
- }, getIconDom(fileIcon, symbolName), ...getHighlightedLabelDom(label, highlights)];
11193
- };
11194
-
11195
- const getCompletionItemsVirtualDom = visibleItems => {
11196
- if (visibleItems.length === 0) {
11197
- return [{
11198
- type: Div,
11199
- childCount: 1
11200
- }, text(noResults$1())];
11201
- }
11202
- const root = {
11203
- type: Div,
11204
- childCount: visibleItems.length
11205
- };
11206
- const dom = [root, ...visibleItems.flatMap(getCompletionItemVirtualDom)];
11207
- return dom;
11208
- };
11209
-
11210
- const Property = 1;
11211
- const Value = 2;
11212
- const Function = 3;
11213
- const Variable = 4;
11214
- const Keyword = 5;
11215
- const Folder = 6;
11216
- const File = 7;
11217
- const Field = 8;
11218
-
11219
- const SymbolProperty = 'SymbolProperty';
11220
- const SymbolValue = 'SymbolValue';
11221
- const SymbolFunction = 'SymbolFunction';
11222
- const SymbolVariable = 'SymbolVariable';
11223
- const SymbolKeyword = 'SymbolKeyword';
11224
- const SymbolDefault = 'SymbolDefault';
11225
- const SymbolField = 'SymbolField';
11226
- const SymbolNone = '';
11227
-
11228
- const getSymbolName = kind => {
11229
- switch (kind) {
11230
- case Property:
11231
- return SymbolProperty;
11232
- case Value:
11233
- return SymbolValue;
11234
- case Function:
11235
- return SymbolFunction;
11236
- case Variable:
11237
- return SymbolVariable;
11238
- case Keyword:
11239
- return SymbolKeyword;
11240
- case Field:
11241
- return SymbolField;
11242
- case File:
11243
- return SymbolNone;
11244
- default:
11245
- return SymbolDefault;
11246
- }
11247
- };
11248
-
11249
- // TODO
11250
- const getCompletionFileIcon = kind => {
11251
- switch (kind) {
11252
- case File:
11253
- return EmptyString$1;
11254
- case Folder:
11255
- return EmptyString$1;
11256
- default:
11257
- return EmptyString$1;
11258
- }
11259
- };
11260
-
11261
- const getHighlights = item => {
11262
- const {
11263
- matches
11264
- } = item;
11265
- return matches.slice(1);
11266
- };
11267
-
11268
- const getLabel = item => {
11269
- return item.label;
11270
- };
11271
- const getVisibleIem = (item, itemHeight, leadingWord, i, focusedIndex) => {
11272
- return {
11273
- label: getLabel(item),
11274
- symbolName: getSymbolName(item.kind),
11275
- top: i * itemHeight,
11276
- highlights: getHighlights(item),
11277
- focused: i === focusedIndex,
11278
- deprecated: item.flags & Deprecated,
11279
- fileIcon: getCompletionFileIcon(item.kind)
11280
- };
11281
- };
11282
-
11283
- const getVisibleItems = (filteredItems, itemHeight, leadingWord, minLineY, maxLineY, focusedIndex) => {
11284
- const visibleItems = [];
11285
- for (let i = minLineY; i < maxLineY; i++) {
11286
- const filteredItem = filteredItems[i];
11287
- visibleItems.push(getVisibleIem(filteredItem, itemHeight, leadingWord, i, focusedIndex));
11288
- }
11289
- return visibleItems;
11290
- };
11291
-
11292
- const renderItems = {
11293
- isEqual(oldState, newState) {
11294
- return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex;
11295
- },
11296
- apply(oldState, newState) {
11297
- const visibleItems = getVisibleItems(newState.items, newState.itemHeight, newState.leadingWord, newState.minLineY, newState.maxLineY, newState.focusedIndex);
11298
- const dom = getCompletionItemsVirtualDom(visibleItems);
11299
- return ['setDom', dom];
11300
- }
11301
- };
11302
10032
  const renderBounds$2 = {
11303
10033
  isEqual(oldState, newState) {
11304
- return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.x === newState.x && oldState.y === newState.y;
10034
+ return oldState.x === newState.x && oldState.y === newState.y && oldState.width === newState.width && oldState.height === newState.height;
11305
10035
  },
11306
10036
  apply(oldState, newState) {
11307
10037
  const {
@@ -11313,478 +10043,128 @@ const renderBounds$2 = {
11313
10043
  return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
11314
10044
  }
11315
10045
  };
11316
- const renderHeight = {
11317
- isEqual(oldState, newState) {
11318
- return oldState.items.length === newState.items.length;
11319
- },
11320
- apply(oldState, newState) {
11321
- const {
11322
- itemHeight
11323
- } = newState;
11324
- const contentHeight = newState.items.length * itemHeight;
11325
- return [/* method */SetContentHeight, /* contentHeight */contentHeight];
11326
- }
11327
- };
11328
- const renderNegativeMargin = {
11329
- isEqual(oldState, newState) {
11330
- return oldState.deltaY === newState.deltaY;
11331
- },
11332
- apply(oldState, newState) {
11333
- return [/* method */SetNegativeMargin, /* negativeMargin */-newState.deltaY];
11334
- }
11335
- };
11336
- const renderScrollBar = {
10046
+ const renderFocus = {
11337
10047
  isEqual(oldState, newState) {
11338
- return oldState.negativeMargin === newState.negativeMargin && oldState.deltaY === newState.deltaY && oldState.height === newState.height && oldState.finalDeltaY === newState.finalDeltaY && oldState.items.length === newState.items.length;
11339
- },
11340
- apply(oldState, newState) {
11341
- const total = newState.items.length;
11342
- const contentHeight = total * newState.itemHeight;
11343
- const scrollBarHeight = getScrollBarSize(newState.height, contentHeight, newState.minimumSliderSize);
11344
- const scrollBarY = getScrollBarY(newState.deltaY, newState.finalDeltaY, newState.height - newState.headerHeight, scrollBarHeight);
11345
- return [/* method */SetScrollBar, /* scrollBarY */scrollBarY, /* scrollBarHeight */scrollBarHeight];
11346
- }
11347
- };
11348
- const render$7 = [renderItems, renderBounds$2, renderHeight, renderNegativeMargin, renderScrollBar];
11349
- const renderCompletion = (oldState, newState) => {
11350
- const commands = [];
11351
- for (const item of render$7) {
11352
- if (!item.isEqual(oldState, newState)) {
11353
- commands.push(item.apply(oldState, newState));
11354
- }
11355
- }
11356
- return commands;
11357
- };
11358
-
11359
- const render$6 = widget => {
11360
- const commands = renderCompletion(widget.oldState, widget.newState);
11361
- const wrappedCommands = [];
11362
- const {
11363
- uid
11364
- } = widget.newState;
11365
- for (const command of commands) {
11366
- wrappedCommands.push(['Viewlet.send', uid, ...command]);
11367
- }
11368
- return wrappedCommands;
11369
- };
11370
- const add$4 = widget => {
11371
- const commands = render$6(widget);
11372
- const id = 'EditorCompletion';
11373
- // TODO how to generate a unique integer id
11374
- // that doesn't collide with ids created in renderer worker?
11375
- const {
11376
- uid
11377
- } = widget.newState;
11378
- const allCommands = [];
11379
- allCommands.push(['Viewlet.create', id, uid]);
11380
- allCommands.push(...commands);
11381
- return allCommands;
11382
- };
11383
- const remove$4 = removeWidget;
11384
- const handleEditorType = (editor, state) => {
11385
- const {
11386
- unfilteredItems,
11387
- itemHeight,
11388
- maxHeight
11389
- } = state;
11390
- const {
11391
- x,
11392
- y,
11393
- rowIndex,
11394
- columnIndex
11395
- } = getPositionAtCursor$1(editor);
11396
- const wordAtOffset = getWordBefore(editor, rowIndex, columnIndex);
11397
- const items = filterCompletionItems(unfilteredItems, wordAtOffset);
11398
- const newMinLineY = 0;
11399
- const newMaxLineY = Math.min(items.length, 8);
11400
- const height = getListHeight(items.length, itemHeight, maxHeight);
11401
- const finalDeltaY = items.length * itemHeight - height;
11402
- return {
11403
- ...state,
11404
- items,
11405
- x,
11406
- y,
11407
- minLineY: newMinLineY,
11408
- maxLineY: newMaxLineY,
11409
- leadingWord: wordAtOffset,
11410
- height,
11411
- finalDeltaY
11412
- };
11413
- };
11414
- const handleEditorDeleteLeft = (editor, state) => {
11415
- const {
11416
- unfilteredItems,
11417
- itemHeight,
11418
- maxHeight
11419
- } = state;
11420
- const {
11421
- x,
11422
- y,
11423
- rowIndex,
11424
- columnIndex
11425
- } = getPositionAtCursor$1(editor);
11426
- const wordAtOffset = getWordBefore(editor, rowIndex, columnIndex);
11427
- if (!wordAtOffset) {
11428
- return undefined;
11429
- }
11430
- const items = filterCompletionItems(unfilteredItems, wordAtOffset);
11431
- const newMaxLineY = Math.min(items.length, 8);
11432
- const height = getListHeight(items.length, itemHeight, maxHeight);
11433
- return {
11434
- ...state,
11435
- items,
11436
- x,
11437
- y,
11438
- maxLineY: newMaxLineY,
11439
- leadingWord: wordAtOffset,
11440
- height
11441
- };
11442
- };
11443
-
11444
- const EditorCompletionWidget = {
11445
- __proto__: null,
11446
- add: add$4,
11447
- handleEditorDeleteLeft,
11448
- handleEditorType,
11449
- remove: remove$4,
11450
- render: render$6
11451
- };
11452
-
11453
- /**
11454
- * @enum {string}
11455
- */
11456
- const UiStrings = {
11457
- MatchOf: '{PH1} of {PH2}',
11458
- NoResults: 'No Results',
11459
- Close: 'Close',
11460
- PreviousMatch: 'Previous Match',
11461
- NextMatch: 'Next Match',
11462
- Find: 'Find',
11463
- Replace: 'Replace',
11464
- ReplaceAll: 'Replace All'
11465
- };
11466
- const noResults = () => {
11467
- return i18nString(UiStrings.NoResults);
11468
- };
11469
- const matchOf = (matchIndex, matchCount) => {
11470
- return i18nString(UiStrings.MatchOf, {
11471
- PH1: matchIndex,
11472
- PH2: matchCount
11473
- });
11474
- };
11475
- const previousMatch = () => {
11476
- return i18nString(UiStrings.PreviousMatch);
11477
- };
11478
- const nextMatch = () => {
11479
- return i18nString(UiStrings.NextMatch);
11480
- };
11481
- const close = () => {
11482
- return i18nString(UiStrings.Close);
11483
- };
11484
- const find = () => {
11485
- return i18nString(UiStrings.Find);
11486
- };
11487
- const replace = () => {
11488
- return i18nString(UiStrings.Replace);
10048
+ return oldState.focused === newState.focused && oldState.focusSource === newState.focusSource;
10049
+ },
10050
+ apply(oldState, newState) {
10051
+ return [Focus, '.CodeGeneratorInput', newState.focusSource];
10052
+ }
11489
10053
  };
11490
- const replaceAll = () => {
11491
- return i18nString(UiStrings.ReplaceAll);
10054
+ const render$9 = [renderContent$1, renderBounds$2, renderFocus];
10055
+ const renderFull$3 = (oldState, newState) => {
10056
+ const commands = [];
10057
+ for (const item of render$9) {
10058
+ if (!item.isEqual(oldState, newState)) {
10059
+ commands.push(item.apply(oldState, newState));
10060
+ }
10061
+ }
10062
+ return commands;
11492
10063
  };
11493
10064
 
11494
- const ArrowDown = 'ArrowDown';
11495
- const ArrowUp = 'ArrowUp';
11496
- const Close$1 = 'Close';
11497
- const Replace$1 = 'Replace';
11498
- const ReplaceAll$1 = 'ReplaceAll';
11499
-
11500
- const SearchValue = 'search-value';
11501
- const ReplaceValue = 'replace-value';
11502
- const ReplaceAll = 'ReplaceAll';
11503
- const Close = 'Close';
11504
- const ToggleReplace = 'ToggleReplace';
11505
- const FocusNext = 'FocusNext';
11506
- const FocusPrevious = 'FocusPrevious';
11507
- const Replace = 'Replace';
11508
-
11509
- const getFindWidgetButtons = (findButtonsEnabled, replaceButtonsEnabled) => {
11510
- const findButtons = [{
11511
- label: previousMatch(),
11512
- icon: ArrowUp,
11513
- disabled: !findButtonsEnabled,
11514
- onClick: HandleClickPreviousMatch,
11515
- name: FocusPrevious
11516
- }, {
11517
- label: nextMatch(),
11518
- icon: ArrowDown,
11519
- disabled: !findButtonsEnabled,
11520
- onClick: HandleClickNextMatch,
11521
- name: FocusNext
11522
- }, {
11523
- label: close(),
11524
- icon: Close$1,
11525
- disabled: false,
11526
- onClick: HandleClickClose,
11527
- name: Close
11528
- }];
11529
- const replaceButtons = [{
11530
- label: replace(),
11531
- icon: Replace$1,
11532
- disabled: !replaceButtonsEnabled,
11533
- onClick: HandleClickReplace,
11534
- name: Replace
11535
- }, {
11536
- label: replaceAll(),
11537
- icon: ReplaceAll$1,
11538
- disabled: !replaceButtonsEnabled,
11539
- onClick: HandleClickReplaceAll,
11540
- name: ReplaceAll
11541
- }];
11542
- return {
11543
- findButtons,
11544
- replaceButtons
11545
- };
10065
+ const render$8 = widget => {
10066
+ const commands = renderFull$3(widget.oldState, widget.newState);
10067
+ const wrappedCommands = [];
10068
+ const {
10069
+ uid
10070
+ } = widget.newState;
10071
+ for (const command of commands) {
10072
+ if (command[0] === SetDom2) {
10073
+ wrappedCommands.push(command);
10074
+ } else {
10075
+ // @ts-ignore
10076
+ wrappedCommands.push(['Viewlet.send', uid, ...command]);
10077
+ }
10078
+ }
10079
+ return wrappedCommands;
11546
10080
  };
10081
+ const add$6 = widget => {
10082
+ return addWidget$1(widget, 'EditorCodeGenerator', render$8);
10083
+ };
10084
+ const remove$6 = removeWidget;
11547
10085
 
11548
- const getFindWidgetButtonsEnabled = (matchCount, value) => {
11549
- const findButtonsEnabled = matchCount > 0;
11550
- const replaceButtonsEnabled = value.length > 0;
11551
- return {
11552
- findButtonsEnabled,
11553
- replaceButtonsEnabled
11554
- };
10086
+ const EditorCodeGeneratorWidget = {
10087
+ __proto__: null,
10088
+ add: add$6,
10089
+ remove: remove$6,
10090
+ render: render$8
11555
10091
  };
11556
10092
 
11557
- // TODO always focus element by name
11558
- const getFindWidgetFocusSelector = focus => {
11559
- switch (focus) {
11560
- case FindWidget:
11561
- {
11562
- return `[name="${SearchValue}"]`;
11563
- }
11564
- case FocusFindWidgetReplace$1:
11565
- {
11566
- return `[name="${ReplaceValue}"]`;
11567
- }
11568
- case FocusFindWidgetReplaceAllButton$1:
11569
- {
11570
- return `[name="${ReplaceAll}"]`;
11571
- }
11572
- case FocusFindWidgetCloseButton$1:
11573
- {
11574
- return `[name="${Close}"]`;
11575
- }
11576
- case FocusFindWidgetToggleReplace:
11577
- {
11578
- return `[name="${ToggleReplace}"]`;
11579
- }
11580
- case FocusFindWidgetNextMatchButton$1:
11581
- {
11582
- return `[name="${FocusNext}"]`;
11583
- }
11584
- case FocusFindWidgetPreviousMatchButton$1:
11585
- {
11586
- return `[name="${FocusPrevious}"]`;
11587
- }
11588
- case FocusFindWidgetReplaceButton$1:
11589
- {
11590
- return `[name="${Replace}"]`;
11591
- }
11592
- default:
11593
- {
11594
- return '';
11595
- }
11596
- }
10093
+ const renderFull$2 = (oldState, newState) => {
10094
+ const commands = [...newState.commands];
10095
+ // @ts-ignore
10096
+ newState.commands = [];
10097
+ return commands;
11597
10098
  };
11598
10099
 
11599
- const getFindMatchCountClassName = (matchCount, value) => {
11600
- if (value && matchCount === 0) {
11601
- return mergeClassNames(FindWidgetMatchCount, FindWidgetMatchCountEmpty);
10100
+ const render$7 = widget => {
10101
+ const commands = renderFull$2(widget.oldState, widget.newState);
10102
+ const wrappedCommands = [];
10103
+ const {
10104
+ uid
10105
+ } = widget.newState;
10106
+ for (const command of commands) {
10107
+ if (command[0] === SetDom2 || command[0] === SetCss || command[0] === AppendToBody || command[0] === SetBounds2 || command[0] === RegisterEventListeners || command[0] === SetUid) {
10108
+ wrappedCommands.push(command);
10109
+ } else {
10110
+ wrappedCommands.push(['Viewlet.send', uid, ...command]);
10111
+ }
11602
10112
  }
11603
- return FindWidgetMatchCount;
10113
+ return wrappedCommands;
11604
10114
  };
11605
-
11606
- const getIconVirtualDom = (icon, type = Div) => {
11607
- return {
11608
- type,
11609
- className: `MaskIcon MaskIcon${icon}`,
11610
- role: None,
11611
- childCount: 0
11612
- };
10115
+ const add$5 = widget => {
10116
+ return addWidget$1(widget, 'ColorPicker', render$7);
11613
10117
  };
10118
+ const remove$5 = removeWidget;
10119
+ const Commands$1 = {};
11614
10120
 
11615
- const getIconButtonVirtualDom = iconButton => {
11616
- const {
11617
- label,
11618
- icon,
11619
- disabled,
11620
- name,
11621
- onClick
11622
- } = iconButton;
11623
- let className = IconButton;
11624
- if (disabled) {
11625
- className += ' ' + IconButtonDisabled;
11626
- }
11627
- return [{
11628
- type: Button,
11629
- className,
11630
- title: label,
11631
- ariaLabel: label,
11632
- childCount: 1,
11633
- disabled: disabled ? true : undefined,
11634
- onClick: onClick,
11635
- name: name
11636
- }, getIconVirtualDom(icon)];
11637
- };
11638
-
11639
- const getSearchFieldButtonVirtualDom = button => {
11640
- const {
11641
- icon,
11642
- checked,
11643
- title
11644
- } = button;
11645
- return [{
11646
- type: Div,
11647
- className: mergeClassNames(SearchFieldButton, checked ? SearchFieldButtonChecked : ''),
11648
- title,
11649
- role: CheckBox,
11650
- ariaChecked: checked,
11651
- tabIndex: 0,
11652
- childCount: 1
11653
- }, {
11654
- type: Div,
11655
- className: mergeClassNames(MaskIcon, icon),
11656
- childCount: 0
11657
- }];
10121
+ const EditorColorPickerWidget = {
10122
+ __proto__: null,
10123
+ Commands: Commands$1,
10124
+ add: add$5,
10125
+ remove: remove$5,
10126
+ render: render$7
11658
10127
  };
11659
10128
 
11660
- const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '') => {
10129
+ const getCompletionDetailVirtualDom = content => {
11661
10130
  const dom = [{
11662
10131
  type: Div,
11663
- className: SearchField,
11664
- role: None,
10132
+ className: 'Viewlet EditorCompletionDetails',
11665
10133
  childCount: 2
11666
10134
  }, {
11667
- type: TextArea,
11668
- className: MultilineInputBox,
11669
- spellcheck: false,
11670
- autocapitalize: 'off',
11671
- autocorrect: 'off',
11672
- placeholder,
11673
- name,
11674
- onInput,
11675
- onFocus,
11676
- childCount: 0
11677
- }, {
11678
- type: Div,
11679
- className: SearchFieldButtons,
11680
- childCount: insideButtons.length
11681
- }, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom)];
11682
- if (outsideButtons.length > 0) {
11683
- throw new Error('outsideButtons are deprecated');
11684
- }
11685
- return dom;
11686
- };
11687
-
11688
- const getFindWidgetFindVirtualDom = (matchCountText, buttons, matchCount, value) => {
11689
- const dom = [];
11690
- dom.push({
11691
10135
  type: Div,
11692
- className: FindWidgetFind,
11693
- childCount: 5
11694
- });
11695
- dom.push(...getSearchFieldVirtualDom('search-value', find(), HandleInput, [], [], HandleFocus));
11696
- const findClassName = getFindMatchCountClassName(matchCount, value);
11697
- dom.push({
10136
+ className: CompletionDetailContent,
10137
+ childCount: 1
10138
+ }, text(content), {
11698
10139
  type: Div,
11699
- className: findClassName,
10140
+ className: CompletionDetailCloseButton,
10141
+ onClick: HandleClose,
11700
10142
  childCount: 1
11701
- }, text(matchCountText), ...buttons.flatMap(getIconButtonVirtualDom));
11702
- return dom;
11703
- };
11704
-
11705
- const getFindWidgetReplaceVirtualDom = (replaceExpanded, replaceButtons) => {
11706
- const dom = [];
11707
- if (replaceExpanded) {
11708
- dom.push({
11709
- type: Div,
11710
- className: FindWidgetReplace,
11711
- childCount: 1 + replaceButtons.length
11712
- }, ...getSearchFieldVirtualDom('replace-value', replace(), HandleReplaceInput, [], [], HandleReplaceFocus), ...replaceButtons.flatMap(getIconButtonVirtualDom));
11713
- }
11714
- return dom;
11715
- };
11716
-
11717
- const getSearchToggleButtonVirtualDom = (replaceExpanded, onClick = '') => {
11718
- return [{
11719
- type: Button,
11720
- className: `IconButton SearchToggleButton ${replaceExpanded ? 'SearchToggleButtonExpanded' : ''}`,
11721
- title: 'Toggle Replace',
11722
- ariaLabel: 'Toggle Replace',
11723
- ariaExpanded: replaceExpanded,
11724
- name: ToggleReplace$1,
11725
- childCount: 1,
11726
- 'data-command': 'toggleReplace',
11727
- onClick,
11728
- onFocus: 'handleToggleReplaceFocus'
11729
10143
  }, {
11730
10144
  type: Div,
11731
- className: `MaskIcon ${replaceExpanded ? 'MaskIconChevronDown' : 'MaskIconChevronRight'}`,
10145
+ className: `${MaskIcon} ${IconClose}`,
11732
10146
  childCount: 0
11733
10147
  }];
11734
- };
11735
-
11736
- const getFindWidgetVirtualDom = (matchCountText, replaceExpanded, findButtons, replaceButtons, matchCase, matchWholeWord, useRegularExpression, matchCount, value) => {
11737
- const dom = [];
11738
- dom.push({
11739
- type: Div,
11740
- className: 'Viewlet ViewletFind ViewletFindWidget FindWidget',
11741
- childCount: 2,
11742
- role: Group
11743
- });
11744
- dom.push(...getSearchToggleButtonVirtualDom(replaceExpanded, 'handleClickToggleReplace'));
11745
- dom.push({
11746
- type: Div,
11747
- className: FindWidgetRight,
11748
- childCount: replaceExpanded ? 2 : 1
11749
- });
11750
- dom.push(...getFindWidgetFindVirtualDom(matchCountText, findButtons, matchCount, value));
11751
- if (replaceExpanded) {
11752
- dom.push(...getFindWidgetReplaceVirtualDom(replaceExpanded, replaceButtons));
11753
- }
11754
10148
  return dom;
11755
10149
  };
11756
10150
 
11757
- const getMatchCountText = (matchIndex, matchCount) => {
11758
- if (matchCount === 0) {
11759
- return noResults();
10151
+ const renderParts = (render, oldState, newState) => {
10152
+ const commands = [];
10153
+ for (const item of render) {
10154
+ if (!item.isEqual(oldState, newState)) {
10155
+ commands.push(item.apply(oldState, newState));
10156
+ }
11760
10157
  }
11761
- return matchOf(matchIndex + 1, matchCount);
10158
+ return commands;
11762
10159
  };
11763
10160
 
11764
- const renderValue = {
11765
- isEqual(oldState, newState) {
11766
- return oldState.value === newState.value;
11767
- },
11768
- apply(oldState, newState) {
11769
- return [SetValue, /* value */newState.value];
11770
- }
11771
- };
11772
- const renderDetails = {
10161
+ const renderContent = {
11773
10162
  isEqual(oldState, newState) {
11774
- return oldState.matchIndex === newState.matchIndex && oldState.matchCount === newState.matchCount && oldState.replaceExpanded === newState.replaceExpanded && oldState.value === newState.value;
10163
+ return oldState.content === newState.content;
11775
10164
  },
11776
10165
  apply(oldState, newState) {
11777
- const matchCountText = getMatchCountText(newState.matchIndex, newState.matchCount);
11778
- const {
11779
- findButtonsEnabled,
11780
- replaceButtonsEnabled
11781
- } = getFindWidgetButtonsEnabled(newState.matchCount, newState.value);
11782
- const {
11783
- findButtons,
11784
- replaceButtons
11785
- } = getFindWidgetButtons(findButtonsEnabled, replaceButtonsEnabled);
11786
- const dom = getFindWidgetVirtualDom(matchCountText, newState.replaceExpanded, findButtons, replaceButtons, newState.matchCase, newState.matchWholeWord, newState.useRegularExpression, newState.matchCount, newState.value);
11787
- return [SetDom2, dom];
10166
+ const dom = getCompletionDetailVirtualDom(newState.content);
10167
+ return [SetDom2, newState.uid, dom];
11788
10168
  }
11789
10169
  };
11790
10170
  const renderBounds$1 = {
@@ -11801,53 +10181,100 @@ const renderBounds$1 = {
11801
10181
  return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
11802
10182
  }
11803
10183
  };
11804
- const renderFocus = {
11805
- isEqual(oldState, newState) {
11806
- return oldState.focused === newState.focused && oldState.focus === newState.focus && oldState.focusSource === newState.focusSource;
11807
- },
11808
- apply(oldState, newState) {
11809
- const key = getFindWidgetFocusSelector(newState.focus);
11810
- return [Focus, key, newState.focusSource];
10184
+ const render$6 = [renderContent, renderBounds$1];
10185
+ const renderFull$1 = (oldState, newState) => {
10186
+ return renderParts(render$6, oldState, newState);
10187
+ };
10188
+
10189
+ const getWidgetState = (editor, id) => {
10190
+ const {
10191
+ widgets
10192
+ } = editor;
10193
+ for (const widget of widgets) {
10194
+ if (widget.id === id) {
10195
+ return widget.newState;
10196
+ }
11811
10197
  }
10198
+ return undefined;
11812
10199
  };
11813
- // const getAriaLabel = (state: FindWidgetState) => {
11814
- // const { matchIndex, matchCount, value } = state
11815
- // return FindStrings.matchesFoundFor(matchIndex, matchCount, value)
11816
- // }
11817
10200
 
11818
- // const renderAriaAnnouncement = {
11819
- // isEqual(oldState: FindWidgetState, newState: FindWidgetState) {
11820
- // return (
11821
- // oldState.ariaAnnouncement === newState.ariaAnnouncement &&
11822
- // oldState.matchIndex === newState.matchIndex &&
11823
- // oldState.matchCount === newState.matchCount &&
11824
- // oldState.value === newState.value
11825
- // )
11826
- // },
11827
- // apply(oldState: FindWidgetState, newState: FindWidgetState) {
11828
- // const ariaLabel = getAriaLabel(newState)
11829
- // return [/* Viewlet.invoke */ 'Viewlet.ariaAnnounce', /* text */ ariaLabel]
11830
- // },
11831
- // }
10201
+ const getCompletionState = editor => {
10202
+ return getWidgetState(editor, Completion);
10203
+ };
11832
10204
 
11833
- const render$5 = [renderDetails, renderBounds$1, renderValue, renderFocus];
11834
- const apply = (oldState, newState) => {
11835
- // TODO avoid side effect
11836
- if (oldState.focus !== newState.focus) {
11837
- setFocus(newState.focus);
10205
+ const render$5 = widget => {
10206
+ const commands = renderFull$1(widget.oldState, widget.newState);
10207
+ const wrappedCommands = [];
10208
+ const {
10209
+ uid
10210
+ } = widget.newState;
10211
+ for (const command of commands) {
10212
+ if (command[0] === SetDom2) {
10213
+ wrappedCommands.push(command);
10214
+ } else {
10215
+ wrappedCommands.push(['Viewlet.send', uid, ...command]);
10216
+ }
10217
+ }
10218
+ return wrappedCommands;
10219
+ };
10220
+ const add$4 = widget => {
10221
+ return addWidget$1(widget, 'EditorCompletionDetails', render$5);
10222
+ };
10223
+ const remove$4 = removeWidget;
10224
+ const handleEditorType = (editor, state) => {
10225
+ const completionState = getCompletionState(editor);
10226
+ if (!completionState) {
10227
+ return editor;
10228
+ }
10229
+ const {
10230
+ x
10231
+ } = getPositionAtCursor$1(editor);
10232
+ const detailX = x + completionState.width - state.borderSize;
10233
+ return {
10234
+ ...state,
10235
+ x: detailX
10236
+ };
10237
+ };
10238
+ const handleEditorDeleteLeft = (editor, state) => {
10239
+ const completionState = getCompletionState(editor);
10240
+ if (!completionState) {
10241
+ return editor;
11838
10242
  }
11839
- return renderParts(render$5, oldState, newState);
10243
+ const {
10244
+ x
10245
+ } = getPositionAtCursor$1(editor);
10246
+ const detailX = x + completionState.width - state.borderSize;
10247
+ return {
10248
+ ...state,
10249
+ x: detailX
10250
+ };
10251
+ };
10252
+
10253
+ const EditorCompletionDetailWidget = {
10254
+ __proto__: null,
10255
+ add: add$4,
10256
+ handleEditorDeleteLeft,
10257
+ handleEditorType,
10258
+ remove: remove$4,
10259
+ render: render$5
10260
+ };
10261
+
10262
+ const renderFull = (oldState, newState) => {
10263
+ const commands = [...newState.commands];
10264
+ // @ts-ignore
10265
+ newState.commands = [];
10266
+ return commands;
11840
10267
  };
11841
10268
 
11842
10269
  const render$4 = widget => {
11843
- const commands = apply(widget.oldState, widget.newState);
10270
+ const commands = renderFull(widget.oldState, widget.newState);
11844
10271
  const wrappedCommands = [];
11845
10272
  const {
11846
10273
  uid
11847
10274
  } = widget.newState;
11848
10275
  for (const command of commands) {
11849
- if (command[0] === SetDom2) {
11850
- wrappedCommands.push([command[0], uid, ...command.slice(1)]);
10276
+ if (command[0] === SetDom2 || command[0] === SetCss || command[0] === AppendToBody || command[0] === SetBounds2 || command[0] === RegisterEventListeners || command[0] === SetSelectionByName || command[0] === SetValueByName || command[0] === SetFocusContext || command[0] === SetUid || command[0] === 'Viewlet.focusSelector') {
10277
+ wrappedCommands.push(command);
11851
10278
  } else {
11852
10279
  wrappedCommands.push(['Viewlet.send', uid, ...command]);
11853
10280
  }
@@ -11855,19 +10282,12 @@ const render$4 = widget => {
11855
10282
  return wrappedCommands;
11856
10283
  };
11857
10284
  const add$3 = widget => {
11858
- return addWidget(widget, 'FindWidget', render$4);
10285
+ return addWidget$1(widget, 'FindWidget', render$4);
11859
10286
  };
11860
- const remove$3 = removeWidget;
11861
- const Commands = {
11862
- 'FindWidget.close': close$1,
11863
- 'FindWidget.focusNext': focusNext$2,
11864
- 'FindWidget.focusPrevious': focusPrevious$1,
11865
- 'FindWidget.focusIndex': focusIndex$2,
11866
- 'FindWidget.focusLast': focusLast,
11867
- 'FindWidget.toggleReplace': toggleReplace,
11868
- 'FindWidget.handleFocus': focusFind,
11869
- 'FindWidget.handleBlur': handleBlur
10287
+ const remove$3 = widget => {
10288
+ return [['Viewlet.dispose', widget.newState.uid]];
11870
10289
  };
10290
+ const Commands = {};
11871
10291
 
11872
10292
  const EditorFindWidget = {
11873
10293
  __proto__: null,
@@ -11893,7 +10313,7 @@ const render$3 = widget => {
11893
10313
  return wrappedCommands;
11894
10314
  };
11895
10315
  const add$2 = widget => {
11896
- return addWidget(widget, 'EditorHover', render$3);
10316
+ return addWidget$1(widget, 'EditorHover', render$3);
11897
10317
  };
11898
10318
  const remove$2 = removeWidget;
11899
10319
 
@@ -11904,18 +10324,8 @@ const EditorHoverWidget = {
11904
10324
  render: render$3
11905
10325
  };
11906
10326
 
11907
- const renderFull = (oldState, newState) => {
11908
- const commands = [...newState.commands];
11909
- // @ts-ignore
11910
- newState.commands = [];
11911
- console.log({
11912
- commands
11913
- });
11914
- return commands;
11915
- };
11916
-
11917
10327
  const render$2 = widget => {
11918
- const commands = renderFull(widget.oldState, widget.newState);
10328
+ const commands = renderFull$4(widget.oldState, widget.newState);
11919
10329
  const wrappedCommands = [];
11920
10330
  const {
11921
10331
  uid
@@ -11930,7 +10340,7 @@ const render$2 = widget => {
11930
10340
  return wrappedCommands;
11931
10341
  };
11932
10342
  const add$1 = widget => {
11933
- return addWidget(widget, 'EditorRename', render$2);
10343
+ return addWidget$1(widget, 'EditorRename', render$2);
11934
10344
  };
11935
10345
  const remove$1 = removeWidget;
11936
10346
 
@@ -12066,7 +10476,7 @@ const render = widget => {
12066
10476
  return wrappedCommands;
12067
10477
  };
12068
10478
  const add = widget => {
12069
- return addWidget(widget, 'EditorSourceActions', render);
10479
+ return addWidget$1(widget, 'EditorSourceActions', render);
12070
10480
  };
12071
10481
  const remove = removeWidget;
12072
10482