@lvce-editor/editor-worker 4.4.0 → 4.6.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.
@@ -1736,9 +1736,26 @@ const {
1736
1736
  const CompletionExecute = 'ExtensionHostCompletion.execute';
1737
1737
  const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
1738
1738
  const HoverExecute = 'ExtensionHostHover.execute';
1739
+ const RenameExecuteRename = 'ExtensionHostRename.executeRenameProvider';
1739
1740
  const TabCompletionExecuteTabCompletionProvider = 'ExtensionHost.executeTabCompletionProvider';
1740
1741
  const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
1741
1742
 
1743
+ const ColorPicker$2 = 41;
1744
+ const CompletionDetail$1 = 999;
1745
+ const EditorCompletion = 9;
1746
+ const Empty = 0;
1747
+ const FindWidget = 16;
1748
+ const FocusEditorHover = 51;
1749
+ const FocusEditorRename = 11;
1750
+ const FocusFindWidgetCloseButton = 48;
1751
+ const FocusFindWidgetNextMatchButton = 49;
1752
+ const FocusFindWidgetPreviousMatchButton = 50;
1753
+ const FocusFindWidgetReplace = 43;
1754
+ const FocusFindWidgetReplaceAllButton = 47;
1755
+ const FocusFindWidgetReplaceButton = 46;
1756
+ const FocusFindWidgetToggleReplace = 42;
1757
+ const SourceActions = 38;
1758
+
1742
1759
  const measureCharacterWidth = (fontWeight, fontSize, fontFamily, letterSpacing) => {
1743
1760
  return measureTextWidth('a', fontWeight, fontSize, fontFamily, letterSpacing, false, 0);
1744
1761
  };
@@ -1852,7 +1869,8 @@ const createEditor = async ({
1852
1869
  charWidth,
1853
1870
  uid: id,
1854
1871
  id,
1855
- widgets: []
1872
+ widgets: [],
1873
+ focusKey: Empty
1856
1874
  };
1857
1875
  // TODO avoid creating intermediate editors here
1858
1876
  const newEditor1 = setBounds(editor, x, y, width, height, 9);
@@ -1930,14 +1948,13 @@ const applyEdit = async (editor, changes) => {
1930
1948
  };
1931
1949
 
1932
1950
  const handleBlur$2 = editor => {
1933
- // for (const listener of state.blurListeners) {
1934
- // listener(editor)
1935
- // }
1936
- // TODO save on blur
1937
- // Command.execute(/* Main.save */ 89)
1951
+ if (editor.focusKey !== Empty) {
1952
+ return editor;
1953
+ }
1938
1954
  const newEditor = {
1939
1955
  ...editor,
1940
- focused: false
1956
+ focused: false,
1957
+ focusKey: Empty
1941
1958
  };
1942
1959
  return newEditor;
1943
1960
  };
@@ -2257,10 +2274,25 @@ const cancelSelection = editor => {
2257
2274
  return scheduleSelections(editor, newSelections);
2258
2275
  };
2259
2276
 
2277
+ const getIndex = (widgets, id) => {
2278
+ for (let i = 0; i < widgets.length; i++) {
2279
+ const widget = widgets[i];
2280
+ if (widget.id === id) {
2281
+ return i;
2282
+ }
2283
+ }
2284
+ return -1;
2285
+ };
2286
+ const removeEditorWidget = (widgets, id) => {
2287
+ const index = getIndex(widgets, id);
2288
+ const newWidgets = [...widgets.slice(0, index), ...widgets.slice(index + 1)];
2289
+ return newWidgets;
2290
+ };
2291
+
2260
2292
  // TODO use numeric widget id
2261
- const ColorPicker$2 = 'colorPicker';
2293
+ const ColorPicker$1 = 'colorPicker';
2262
2294
  const Completion = 'completion';
2263
- const CompletionDetail$1 = 'completionDetail';
2295
+ const CompletionDetail = 'completionDetail';
2264
2296
  const Find = 'find';
2265
2297
  const Hover = 'hover';
2266
2298
  const Rename = 'rename';
@@ -2277,7 +2309,7 @@ const closeCompletion = editor => {
2277
2309
  if (completionWidgetIndex === -1) {
2278
2310
  return editor;
2279
2311
  }
2280
- const newWidgets = [...widgets.slice(0, completionWidgetIndex), ...widgets.slice(completionWidgetIndex + 1)];
2312
+ const newWidgets = removeEditorWidget(widgets, Completion);
2281
2313
  return {
2282
2314
  ...editor,
2283
2315
  widgets: newWidgets
@@ -2295,7 +2327,7 @@ const closeFind = editor => {
2295
2327
  if (index === -1) {
2296
2328
  return editor;
2297
2329
  }
2298
- const newWidgets = [...widgets.slice(0, index), ...widgets.slice(index + 1)];
2330
+ const newWidgets = removeEditorWidget(widgets, Find);
2299
2331
  return {
2300
2332
  ...editor,
2301
2333
  widgets: newWidgets
@@ -2314,9 +2346,10 @@ const closeRename = editor => {
2314
2346
  if (renameWidgetIndex === -1) {
2315
2347
  return editor;
2316
2348
  }
2317
- const newWidgets = [...widgets.slice(0, renameWidgetIndex), ...widgets.slice(renameWidgetIndex + 1)];
2349
+ const newWidgets = removeEditorWidget(widgets, Rename);
2318
2350
  return {
2319
2351
  ...editor,
2352
+ focused: true,
2320
2353
  widgets: newWidgets
2321
2354
  };
2322
2355
  };
@@ -2332,7 +2365,7 @@ const closeSourceAction = editor => {
2332
2365
  if (index === -1) {
2333
2366
  return editor;
2334
2367
  }
2335
- const newWidgets = [...widgets.slice(0, index), ...widgets.slice(index + 1)];
2368
+ const newWidgets = removeEditorWidget(widgets, SourceAction);
2336
2369
  return {
2337
2370
  ...editor,
2338
2371
  widgets: newWidgets
@@ -2383,9 +2416,12 @@ const addWidgetToEditor = async (widgetId, focusKey, editor, factory, newStateGe
2383
2416
  } else {
2384
2417
  await setAdditionalFocus(focusKey);
2385
2418
  }
2419
+ const newFocus = fullFocus ? false : true;
2386
2420
  const newEditor = {
2387
2421
  ...editor,
2388
- widgets: newWidgets
2422
+ widgets: newWidgets,
2423
+ focusKey,
2424
+ focused: newFocus
2389
2425
  };
2390
2426
  return newEditor;
2391
2427
  };
@@ -2397,7 +2433,7 @@ const create$7 = () => {
2397
2433
  const create$6 = () => {
2398
2434
  const completionUid = create$7();
2399
2435
  const widget = {
2400
- id: ColorPicker$2,
2436
+ id: ColorPicker$1,
2401
2437
  oldState: {
2402
2438
  color: '',
2403
2439
  offsetX: 0,
@@ -2424,27 +2460,11 @@ const create$6 = () => {
2424
2460
  return widget;
2425
2461
  };
2426
2462
 
2427
- const ColorPicker$1 = 41;
2428
- const CompletionDetail = 999;
2429
- const EditorCompletion = 9;
2430
- const Empty = 0;
2431
- const FindWidget = 16;
2432
- const FocusEditorHover = 51;
2433
- const FocusEditorRename = 11;
2434
- const FocusFindWidgetCloseButton = 48;
2435
- const FocusFindWidgetNextMatchButton = 49;
2436
- const FocusFindWidgetPreviousMatchButton = 50;
2437
- const FocusFindWidgetReplace = 43;
2438
- const FocusFindWidgetReplaceAllButton = 47;
2439
- const FocusFindWidgetReplaceButton = 46;
2440
- const FocusFindWidgetToggleReplace = 42;
2441
- const SourceActions = 38;
2442
-
2443
2463
  const newStateGenerator$1 = state => {
2444
2464
  return loadContent$3(state);
2445
2465
  };
2446
2466
  const openColorPicker = async editor => {
2447
- return addWidgetToEditor(ColorPicker$2, ColorPicker$1, editor, create$6, newStateGenerator$1);
2467
+ return addWidgetToEditor(ColorPicker$1, ColorPicker$2, editor, create$6, newStateGenerator$1);
2448
2468
  };
2449
2469
 
2450
2470
  const state$6 = {
@@ -4542,6 +4562,7 @@ const create$5 = () => {
4542
4562
  return completionWidget;
4543
4563
  };
4544
4564
 
4565
+ const OnRename = 'onRename';
4545
4566
  const OnCompletion = 'onCompletion';
4546
4567
  const OnHover = 'onHover';
4547
4568
  const OnTabCompletion = 'onTabCompletion';
@@ -4565,7 +4586,7 @@ const execute = async ({
4565
4586
  return result;
4566
4587
  };
4567
4588
 
4568
- const combineResults$1 = results => {
4589
+ const combineResults$2 = results => {
4569
4590
  return results[0] ?? [];
4570
4591
  };
4571
4592
  const executeCompletionProvider = (editor, offset) => {
@@ -4576,7 +4597,7 @@ const executeCompletionProvider = (editor, offset) => {
4576
4597
  args: [offset],
4577
4598
  noProviderFoundMessage: 'no completion provider found',
4578
4599
  noProviderFoundResult: [],
4579
- combineResults: combineResults$1
4600
+ combineResults: combineResults$2
4580
4601
  });
4581
4602
  };
4582
4603
  const combineResultsResolve = items => {
@@ -5181,7 +5202,7 @@ const isFind = widget => {
5181
5202
  };
5182
5203
  // TODO don't call renderer worker, set editor state
5183
5204
  // TODO this function should be synchronous
5184
- const focusIndex$1 = (editor, index) => {
5205
+ const focusIndex$2 = (editor, index) => {
5185
5206
  const findState = getFindState(editor);
5186
5207
  if (!findState) {
5187
5208
  return editor;
@@ -5224,7 +5245,7 @@ const focusFirst$1 = editor => {
5224
5245
  if (!findState) {
5225
5246
  return editor;
5226
5247
  }
5227
- return focusIndex$1(editor, 0);
5248
+ return focusIndex$2(editor, 0);
5228
5249
  };
5229
5250
  const focusLast = editor => {
5230
5251
  const findState = getFindState(editor);
@@ -5234,9 +5255,9 @@ const focusLast = editor => {
5234
5255
  const {
5235
5256
  matchCount
5236
5257
  } = findState;
5237
- return focusIndex$1(editor, matchCount - 1);
5258
+ return focusIndex$2(editor, matchCount - 1);
5238
5259
  };
5239
- const focusNext$1 = editor => {
5260
+ const focusNext$2 = editor => {
5240
5261
  const findState = getFindState(editor);
5241
5262
  if (!findState) {
5242
5263
  return editor;
@@ -5248,7 +5269,7 @@ const focusNext$1 = editor => {
5248
5269
  if (matchIndex === matchCount - 1) {
5249
5270
  return focusFirst$1(editor);
5250
5271
  }
5251
- return focusIndex$1(editor, matchIndex + 1);
5272
+ return focusIndex$2(editor, matchIndex + 1);
5252
5273
  };
5253
5274
  const focusPrevious$1 = editor => {
5254
5275
  const findState = getFindState(editor);
@@ -5261,7 +5282,7 @@ const focusPrevious$1 = editor => {
5261
5282
  if (matchIndex === 0) {
5262
5283
  return focusLast(editor);
5263
5284
  }
5264
- return focusIndex$1(editor, matchIndex - 1);
5285
+ return focusIndex$2(editor, matchIndex - 1);
5265
5286
  };
5266
5287
 
5267
5288
  const focusNextMatchButton = state => {
@@ -6831,7 +6852,7 @@ const sortLinesAscending = editor => {
6831
6852
  return scheduleDocumentAndCursorsSelections(editor, changes);
6832
6853
  };
6833
6854
 
6834
- const combineResults = results => {
6855
+ const combineResults$1 = results => {
6835
6856
  return results[0];
6836
6857
  };
6837
6858
  const executeTabCompletionProvider = (editor, offset) => {
@@ -6841,7 +6862,7 @@ const executeTabCompletionProvider = (editor, offset) => {
6841
6862
  method: TabCompletionExecuteTabCompletionProvider,
6842
6863
  args: [offset],
6843
6864
  noProviderFoundMessage: 'No tab completion provider found',
6844
- combineResults,
6865
+ combineResults: combineResults$1,
6845
6866
  noProviderFoundResult: undefined
6846
6867
  });
6847
6868
  };
@@ -7561,7 +7582,7 @@ const editorUnindent = editor => {
7561
7582
  // editor.lines //?
7562
7583
 
7563
7584
  const isCompletionDetailWidget = widget => {
7564
- return widget.id === CompletionDetail$1;
7585
+ return widget.id === CompletionDetail;
7565
7586
  };
7566
7587
  const closeDetails = editor => {
7567
7588
  const {
@@ -7578,7 +7599,7 @@ const closeDetails = editor => {
7578
7599
  };
7579
7600
  };
7580
7601
 
7581
- const focusIndex = (state, index) => {
7602
+ const focusIndex$1 = (state, index) => {
7582
7603
  const newState = {
7583
7604
  ...state,
7584
7605
  focusedIndex: index,
@@ -7589,17 +7610,17 @@ const focusIndex = (state, index) => {
7589
7610
 
7590
7611
  const focusFirst = state => {
7591
7612
  const firstIndex = 0;
7592
- return focusIndex(state, firstIndex);
7613
+ return focusIndex$1(state, firstIndex);
7593
7614
  };
7594
7615
 
7595
- const focusNext = state => {
7616
+ const focusNext$1 = state => {
7596
7617
  const nextIndex = state.focusedIndex + 1;
7597
- return focusIndex(state, nextIndex);
7618
+ return focusIndex$1(state, nextIndex);
7598
7619
  };
7599
7620
 
7600
7621
  const focusPrevious = state => {
7601
7622
  const previousIndex = state.focusedIndex - 1;
7602
- return focusIndex(state, previousIndex);
7623
+ return focusIndex$1(state, previousIndex);
7603
7624
  };
7604
7625
 
7605
7626
  // TODO optimize this function to return the minimum number
@@ -7649,7 +7670,7 @@ const handelWheel = (state, deltaMode, deltaY) => {
7649
7670
  const create = () => {
7650
7671
  const completionUid = create$7();
7651
7672
  const completionWidget = {
7652
- id: CompletionDetail$1,
7673
+ id: CompletionDetail,
7653
7674
  oldState: {
7654
7675
  content: '',
7655
7676
  uid: completionUid,
@@ -7700,7 +7721,7 @@ const openDetails = editor => {
7700
7721
  };
7701
7722
  return newestState;
7702
7723
  };
7703
- return addWidgetToEditor(CompletionDetail$1, CompletionDetail, editor, create, newStateGenerator);
7724
+ return addWidgetToEditor(CompletionDetail, CompletionDetail$1, editor, create, newStateGenerator);
7704
7725
  };
7705
7726
 
7706
7727
  const getEdits = async (editor, completionItem) => {
@@ -7723,9 +7744,6 @@ const getEdits = async (editor, completionItem) => {
7723
7744
  const changes = replaceRange(editor, replaceRange$1, [inserted], '');
7724
7745
  return changes;
7725
7746
  };
7726
- const isCompletion = widget => {
7727
- return widget.id === Completion;
7728
- };
7729
7747
  const select = async (editor, completionItem) => {
7730
7748
  const changes = await getEdits(editor, completionItem);
7731
7749
  const index = editor.widgets.indexOf
@@ -7742,8 +7760,7 @@ const select = async (editor, completionItem) => {
7742
7760
  const {
7743
7761
  widgets
7744
7762
  } = editor;
7745
- const completionWidgetIndex = editor.widgets.findIndex(isCompletion);
7746
- const newWidgets = [...widgets.slice(0, completionWidgetIndex), ...widgets.slice(completionWidgetIndex + 1)];
7763
+ const newWidgets = removeEditorWidget(widgets, Completion);
7747
7764
  const intermediateEditor = await applyEdit(editor, changes);
7748
7765
  return {
7749
7766
  ...intermediateEditor,
@@ -7781,7 +7798,7 @@ const selectCurrent = editor => {
7781
7798
  };
7782
7799
 
7783
7800
  const getCompletionDetailState = editor => {
7784
- return getWidgetState(editor, CompletionDetail$1);
7801
+ return getWidgetState(editor, CompletionDetail);
7785
7802
  };
7786
7803
 
7787
7804
  const toggleDetails = editor => {
@@ -8017,10 +8034,67 @@ const renderHover = (oldState, newState) => {
8017
8034
  return commands;
8018
8035
  };
8019
8036
 
8037
+ const combineResults = results => {
8038
+ return results[0] ?? [];
8039
+ };
8040
+ const executeRenameProvider = (editor, offset, newName) => {
8041
+ return execute({
8042
+ editor,
8043
+ event: OnRename,
8044
+ method: RenameExecuteRename,
8045
+ args: [offset, newName],
8046
+ noProviderFoundMessage: 'no rename provider found',
8047
+ noProviderFoundResult: [],
8048
+ combineResults
8049
+ });
8050
+ };
8051
+
8052
+ const getRenameState = editor => {
8053
+ return getWidgetState(editor, Rename);
8054
+ };
8055
+
8056
+ const accept = async editor => {
8057
+ const child = getRenameState(editor);
8058
+ if (!child) {
8059
+ return editor;
8060
+ }
8061
+ const {
8062
+ widgets
8063
+ } = editor;
8064
+ const newWidgets = removeEditorWidget(widgets, Rename);
8065
+ // TODO
8066
+ const offset = getOffsetAtCursor(editor);
8067
+ const result = await executeRenameProvider(editor, offset, child.newValue);
8068
+ console.log({
8069
+ result
8070
+ });
8071
+ // 1. ask extension host for rename edits
8072
+ // 2. apply rename edit across editor (and whole workspace)
8073
+ // 3. close rename widget
8074
+ return {
8075
+ ...editor,
8076
+ focused: true,
8077
+ widgets: newWidgets
8078
+ };
8079
+ };
8080
+
8020
8081
  const handleBlur = editor => {
8021
8082
  return closeRename(editor);
8022
8083
  };
8023
8084
 
8085
+ const focusIndex = (state, index) => {
8086
+ const newState = {
8087
+ ...state,
8088
+ focusedIndex: index
8089
+ };
8090
+ return newState;
8091
+ };
8092
+
8093
+ const focusNext = state => {
8094
+ const nextIndex = state.focusedIndex + 1;
8095
+ return focusIndex(state, nextIndex);
8096
+ };
8097
+
8024
8098
  const replaceTextOccurrences = (editor, matches, oldValue, newValue) => {
8025
8099
  const ranges = [];
8026
8100
  const oldValueLength = oldValue.length;
@@ -9076,8 +9150,8 @@ const wrapWidgetCommand = (widgetId, fn) => {
9076
9150
  };
9077
9151
 
9078
9152
  const widgetCommands = {
9079
- 'ColorPicker.handleSliderPointerDown': ColorPicker$2,
9080
- 'ColorPicker.handleSliderPointerMove': ColorPicker$2,
9153
+ 'ColorPicker.handleSliderPointerDown': ColorPicker$1,
9154
+ 'ColorPicker.handleSliderPointerMove': ColorPicker$1,
9081
9155
  // 'FindWidget.focusNext': WidgetId.Find,
9082
9156
  // 'FindWidget.focusPrevious': WidgetId.Find,
9083
9157
  'FindWidget.close': Find,
@@ -9267,8 +9341,8 @@ const commandMap = {
9267
9341
  'EditorCompletion.advance': advance,
9268
9342
  'EditorCompletion.closeDetails': closeDetails,
9269
9343
  'EditorCompletion.focusFirst': focusFirst,
9270
- 'EditorCompletion.focusIndex': focusIndex,
9271
- 'EditorCompletion.focusNext': focusNext,
9344
+ 'EditorCompletion.focusIndex': focusIndex$1,
9345
+ 'EditorCompletion.focusNext': focusNext$1,
9272
9346
  'EditorCompletion.focusPrevious': focusPrevious,
9273
9347
  'EditorCompletion.handleEditorBlur': handleEditorBlur,
9274
9348
  'EditorCompletion.handleEditorClick': handleEditorClick,
@@ -9280,14 +9354,16 @@ const commandMap = {
9280
9354
  'EditorCompletion.selectCurrent': selectCurrent,
9281
9355
  'EditorCompletion.selectIndex': selectIndex,
9282
9356
  'EditorCompletion.toggleDetails': toggleDetails,
9357
+ 'EditorRename.accept': accept,
9283
9358
  'EditorRename.handleBlur': handleBlur,
9359
+ 'EditorSourceActions.focusNext': focusNext,
9284
9360
  'FindWidget.close': close$1,
9285
9361
  'FindWidget.focusCloseButton': focusCloseButton,
9286
9362
  'FindWidget.focusFind': focusFind,
9287
9363
  'FindWidget.focusFirst': focusFirst$1,
9288
- 'FindWidget.focusIndex': focusIndex$1,
9364
+ 'FindWidget.focusIndex': focusIndex$2,
9289
9365
  'FindWidget.focusLast': focusLast,
9290
- 'FindWidget.focusNext': focusNext$1,
9366
+ 'FindWidget.focusNext': focusNext$2,
9291
9367
  'FindWidget.focusNextMatchButton': focusNextMatchButton,
9292
9368
  'FindWidget.focusPrevious': focusPrevious$1,
9293
9369
  'FindWidget.focusPreviousMatchButton': focusPreviousMatchButton,
@@ -10783,9 +10859,9 @@ const add$3 = widget => {
10783
10859
  const remove$3 = removeWidget;
10784
10860
  const Commands = {
10785
10861
  'FindWidget.close': close$1,
10786
- 'FindWidget.focusNext': focusNext$1,
10862
+ 'FindWidget.focusNext': focusNext$2,
10787
10863
  'FindWidget.focusPrevious': focusPrevious$1,
10788
- 'FindWidget.focusIndex': focusIndex$1,
10864
+ 'FindWidget.focusIndex': focusIndex$2,
10789
10865
  'FindWidget.focusLast': focusLast,
10790
10866
  'FindWidget.toggleReplace': toggleReplace,
10791
10867
  'FindWidget.handleFocus': focusFind,
@@ -11012,9 +11088,9 @@ const EditorSourceActionWidget = {
11012
11088
  };
11013
11089
 
11014
11090
  const registerWidgets = () => {
11015
- set$7(ColorPicker$2, EditorColorPickerWidget);
11091
+ set$7(ColorPicker$1, EditorColorPickerWidget);
11016
11092
  set$7(Completion, EditorCompletionWidget);
11017
- set$7(CompletionDetail$1, EditorCompletionDetailWidget);
11093
+ set$7(CompletionDetail, EditorCompletionDetailWidget);
11018
11094
  set$7(Find, EditorFindWidget);
11019
11095
  set$7(Hover, EditorHoverWidget);
11020
11096
  set$7(Rename, EditorRenameWidget);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "4.4.0",
3
+ "version": "4.6.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",