@lvce-editor/editor-worker 3.29.0 → 3.31.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,6 +1736,7 @@ const {
1736
1736
  const CompletionExecute = 'ExtensionHostCompletion.execute';
1737
1737
  const CompletionResolveExecute = 'ExtensionHostCompletion.executeResolve';
1738
1738
  const HoverExecute = 'ExtensionHostHover.execute';
1739
+ const TabCompletionExecuteTabCompletionProvider = 'ExtensionHost.executeTabCompletionProvider';
1739
1740
  const TextDocumentSyncFull = 'ExtensionHostTextDocument.syncFull';
1740
1741
 
1741
1742
  const measureCharacterWidth = (fontWeight, fontSize, fontFamily, letterSpacing) => {
@@ -2999,7 +3000,7 @@ const cut = editor => {
2999
3000
 
3000
3001
  // TODO optimize this function by profiling and not allocating too many objects
3001
3002
  // @ts-ignore
3002
- const getChanges$6 = (lines, selections, getDelta) => {
3003
+ const getChanges$5 = (lines, selections, getDelta) => {
3003
3004
  const changes = [];
3004
3005
  // TODO avoid closure
3005
3006
  const deleteSelection = (selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) => {
@@ -3063,7 +3064,7 @@ const deleteLeftWithAutoClose = editor => {
3063
3064
  selections[i + 1]++;
3064
3065
  selections[i + 3]++;
3065
3066
  }
3066
- const changes = getChanges$6(lines, selections, twoCharactersLeft);
3067
+ const changes = getChanges$5(lines, selections, twoCharactersLeft);
3067
3068
  return scheduleDocumentAndCursorsSelections(editor, changes);
3068
3069
  };
3069
3070
  const editorDeleteHorizontalLeft = (editor, getDelta) => {
@@ -3076,7 +3077,7 @@ const editorDeleteHorizontalLeft = (editor, getDelta) => {
3076
3077
  return deleteLeftWithAutoClose(editor);
3077
3078
  }
3078
3079
  if (isEverySelectionEmpty(selections)) {
3079
- const changes = getChanges$6(lines, selections, getDelta);
3080
+ const changes = getChanges$5(lines, selections, getDelta);
3080
3081
  return scheduleDocumentAndCursorsSelections(editor, changes);
3081
3082
  }
3082
3083
  const changes = editorReplaceSelections(editor, [''], DeleteLeft);
@@ -3091,7 +3092,7 @@ const deleteAllLeft = editor => {
3091
3092
  // @ts-ignore
3092
3093
 
3093
3094
  // @ts-ignore
3094
- const getChanges$5 = (editor, getDelta) => {
3095
+ const getChanges$4 = (editor, getDelta) => {
3095
3096
  const selections = editor.selections;
3096
3097
  if (isEverySelectionEmpty(selections)) {
3097
3098
  const changes = [];
@@ -3121,7 +3122,7 @@ const getChanges$5 = (editor, getDelta) => {
3121
3122
  return changes;
3122
3123
  };
3123
3124
  const editorDeleteHorizontalRight = (editor, getDelta) => {
3124
- const changes = getChanges$5(editor, getDelta);
3125
+ const changes = getChanges$4(editor, getDelta);
3125
3126
  return scheduleDocumentAndCursorsSelections(editor, changes);
3126
3127
  };
3127
3128
 
@@ -3817,7 +3818,7 @@ const getSelectionFromNativeRange = (editor, range) => {
3817
3818
  };
3818
3819
 
3819
3820
  // @ts-ignore
3820
- const getChanges$4 = (editor, data, range) => {
3821
+ const getChanges$3 = (editor, data, range) => {
3821
3822
  const selection = getSelectionFromNativeRange(editor, range);
3822
3823
  const selectionRange = {
3823
3824
  start: {
@@ -3839,7 +3840,7 @@ const getChanges$4 = (editor, data, range) => {
3839
3840
  return changes;
3840
3841
  };
3841
3842
  const handleBeforeInputFromContentEditable = (editor, data, range) => {
3842
- const changes = getChanges$4(editor, data, range);
3843
+ const changes = getChanges$3(editor, data, range);
3843
3844
  return scheduleDocumentAndCursorsSelections(editor, changes);
3844
3845
  };
3845
3846
 
@@ -4195,7 +4196,7 @@ const handleTouchMove = (editor, touchEvent) => {
4195
4196
  };
4196
4197
 
4197
4198
  // @ts-ignore
4198
- const getChanges$3 = selections => {
4199
+ const getChanges$2 = selections => {
4199
4200
  const changes = [];
4200
4201
  const rowsToIndentLess = [];
4201
4202
  for (let i = 0; i < selections.length; i += 4) {
@@ -4226,11 +4227,11 @@ const getChanges$3 = selections => {
4226
4227
  // @ts-ignore
4227
4228
  const indentLess = editor => {
4228
4229
  const selections = editor.selections;
4229
- const changes = getChanges$3(selections);
4230
+ const changes = getChanges$2(selections);
4230
4231
  return scheduleDocumentAndCursorsSelections(editor, changes);
4231
4232
  };
4232
4233
 
4233
- const getChanges$2 = selections => {
4234
+ const getChanges$1 = selections => {
4234
4235
  const rowsToIndent = [];
4235
4236
  for (let i = 0; i < selections.length; i += 4) {
4236
4237
  const selectionStartRow = selections[i];
@@ -4261,7 +4262,7 @@ const indentMore = editor => {
4261
4262
  const {
4262
4263
  selections
4263
4264
  } = editor;
4264
- const changes = getChanges$2(selections);
4265
+ const changes = getChanges$1(selections);
4265
4266
  return scheduleDocumentAndCursorsSelections(editor, changes);
4266
4267
  };
4267
4268
 
@@ -4285,7 +4286,7 @@ const shouldIncreaseIndent = (before, increaseIndentRegex) => {
4285
4286
  }
4286
4287
  return increaseIndentRegex.test(before);
4287
4288
  };
4288
- const getChanges$1 = (lines, selections, languageConfiguration) => {
4289
+ const getChanges = (lines, selections, languageConfiguration) => {
4289
4290
  const changes = [];
4290
4291
  const selectionChanges = [];
4291
4292
  const increaseIndentRegex = getIncreaseIndentRegex(languageConfiguration);
@@ -4357,7 +4358,7 @@ const insertLineBreak = async editor => {
4357
4358
  const {
4358
4359
  changes,
4359
4360
  selectionChanges
4360
- } = getChanges$1(lines, selections, languageConfiguration);
4361
+ } = getChanges(lines, selections, languageConfiguration);
4361
4362
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
4362
4363
  };
4363
4364
 
@@ -4525,6 +4526,7 @@ const create$4 = () => {
4525
4526
 
4526
4527
  const OnCompletion = 'onCompletion';
4527
4528
  const OnHover = 'onHover';
4529
+ const OnTabCompletion = 'onTabCompletion';
4528
4530
 
4529
4531
  // TODO add tests for this
4530
4532
  const activateByEvent = async event => {
@@ -4545,7 +4547,7 @@ const execute = async ({
4545
4547
  return result;
4546
4548
  };
4547
4549
 
4548
- const combineResults = results => {
4550
+ const combineResults$1 = results => {
4549
4551
  return results[0] ?? [];
4550
4552
  };
4551
4553
  const executeCompletionProvider = (editor, offset) => {
@@ -4556,7 +4558,7 @@ const executeCompletionProvider = (editor, offset) => {
4556
4558
  args: [offset],
4557
4559
  noProviderFoundMessage: 'no completion provider found',
4558
4560
  noProviderFoundResult: [],
4559
- combineResults
4561
+ combineResults: combineResults$1
4560
4562
  });
4561
4563
  };
4562
4564
  const combineResultsResolve = items => {
@@ -4574,15 +4576,19 @@ const executeResolveCompletionItem = (editor, offset, name, completionItem) => {
4574
4576
  });
4575
4577
  };
4576
4578
 
4577
- // TODO possible to do this with events/state machine instead of promises -> enables canceling operations / concurrent calls
4578
- const getCompletions = async editor => {
4579
+ const getOffsetAtCursor = editor => {
4579
4580
  const {
4580
4581
  selections
4581
4582
  } = editor;
4582
4583
  const rowIndex = selections[0];
4583
4584
  const columnIndex = selections[1];
4584
- // Editor.sync(editor)
4585
- const offset = await offsetAt(editor, rowIndex, columnIndex);
4585
+ const offset = offsetAt(editor, rowIndex, columnIndex);
4586
+ return offset;
4587
+ };
4588
+
4589
+ // TODO possible to do this with events/state machine instead of promises -> enables canceling operations / concurrent calls
4590
+ const getCompletions = async editor => {
4591
+ const offset = getOffsetAtCursor(editor);
4586
4592
  const completions = await executeCompletionProvider(editor, offset);
4587
4593
  return completions;
4588
4594
  };
@@ -4593,9 +4599,7 @@ const resolveCompletion = async (editor, name, completionItem) => {
4593
4599
  object(editor);
4594
4600
  string(name);
4595
4601
  object(completionItem);
4596
- const rowIndex = editor.selections[0];
4597
- const columnIndex = editor.selections[1];
4598
- const offset = await offsetAt(editor, rowIndex, columnIndex);
4602
+ const offset = getOffsetAtCursor(editor);
4599
4603
  // @ts-ignore
4600
4604
  const resolvedCompletionItem = await executeResolveCompletionItem(editor, offset, name, completionItem);
4601
4605
  return resolvedCompletionItem;
@@ -5254,6 +5258,35 @@ const handleBlur = async state => {
5254
5258
  return state;
5255
5259
  };
5256
5260
 
5261
+ const refresh$1 = (editor, state, value) => {
5262
+ const {
5263
+ lines
5264
+ } = editor;
5265
+ const matches = findMatchesCaseInsensitive(lines, value);
5266
+ const matchCount = getMatchCount(matches);
5267
+ return {
5268
+ ...state,
5269
+ matches,
5270
+ matchIndex: 0,
5271
+ matchCount,
5272
+ value
5273
+ };
5274
+ };
5275
+
5276
+ const refresh = (state, value = state.value) => {
5277
+ // TODO get focused editor
5278
+ const {
5279
+ editorUid
5280
+ } = state;
5281
+ // highlight locations that match value
5282
+ const editor = getEditor(editorUid);
5283
+ return refresh$1(editor, state, value);
5284
+ };
5285
+
5286
+ const handleInput = (state, value) => {
5287
+ return refresh(state, value);
5288
+ };
5289
+
5257
5290
  const handleFindWidgetFocus = (state, focusKey) => {
5258
5291
  if (state.focus === focusKey) {
5259
5292
  return state;
@@ -5311,29 +5344,6 @@ const loadContent$1 = editorId => {
5311
5344
  editorUid: editor.uid
5312
5345
  };
5313
5346
  };
5314
- const refresh = (state, value = state.value) => {
5315
- // TODO get focused editor
5316
- const {
5317
- editorUid
5318
- } = state;
5319
- // highlight locations that match value
5320
- const editor = getEditor(editorUid);
5321
- const {
5322
- lines
5323
- } = editor;
5324
- const matches = findMatchesCaseInsensitive(lines, value);
5325
- const matchCount = getMatchCount(matches);
5326
- return {
5327
- ...state,
5328
- matches,
5329
- matchIndex: 0,
5330
- matchCount,
5331
- value
5332
- };
5333
- };
5334
- const handleInput = (state, value) => {
5335
- return refresh(state, value);
5336
- };
5337
5347
  const close$1 = async state => {
5338
5348
  // TODO
5339
5349
  // await Viewlet.closeWidget(uid)
@@ -6699,18 +6709,28 @@ const sortLinesAscending = editor => {
6699
6709
  return scheduleDocumentAndCursorsSelections(editor, changes);
6700
6710
  };
6701
6711
 
6712
+ const combineResults = results => {
6713
+ return results[0];
6714
+ };
6715
+ const executeTabCompletionProvider = (editor, offset) => {
6716
+ return execute({
6717
+ editor,
6718
+ event: OnTabCompletion,
6719
+ method: TabCompletionExecuteTabCompletionProvider,
6720
+ args: [offset],
6721
+ noProviderFoundMessage: 'No tab completion provider found',
6722
+ combineResults,
6723
+ noProviderFoundResult: undefined
6724
+ });
6725
+ };
6726
+
6702
6727
  const getTabCompletion = async editor => {
6703
- const {
6704
- selections
6705
- } = editor;
6706
- const rowIndex = selections[0];
6707
- const columnIndex = selections[1];
6708
- const offset = offsetAt(editor, rowIndex, columnIndex);
6709
- const tabCompletion = await invoke$3('ExtensionHostTabCompletion.executeTabCompletionProvider', editor, offset);
6710
- return tabCompletion;
6728
+ const offset = getOffsetAtCursor(editor);
6729
+ const completions = await executeTabCompletionProvider(editor, offset);
6730
+ return completions;
6711
6731
  };
6712
6732
 
6713
- const getChanges = (lines, selections, snippet) => {
6733
+ const getSnippetChanges = (lines, selections, snippet) => {
6714
6734
  // TODO verify that deleted fits in the line
6715
6735
  const insertedLines = splitLines$2(snippet.inserted);
6716
6736
  const changes = [];
@@ -6802,7 +6822,7 @@ const editorSnippet = (editor, snippet) => {
6802
6822
  const {
6803
6823
  changes,
6804
6824
  selectionChanges
6805
- } = getChanges(lines, selections, snippet);
6825
+ } = getSnippetChanges(lines, selections, snippet);
6806
6826
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
6807
6827
  };
6808
6828
 
@@ -7887,6 +7907,26 @@ const replaceTextOccurrences = (editor, matches, oldValue, newValue) => {
7887
7907
  return replaceRange(editor, ranges, [newValue], ReplaceAll$2);
7888
7908
  };
7889
7909
 
7910
+ const updateWidget = (editor, widgetId, newState) => {
7911
+ // TODO avoid closure
7912
+ const isWidget = widget => {
7913
+ return widget.id === widgetId;
7914
+ };
7915
+ const childIndex = editor.widgets.findIndex(isWidget);
7916
+ // TODO scroll up/down if necessary
7917
+ const childWidget = editor.widgets[childIndex];
7918
+ const newWidget = {
7919
+ ...childWidget,
7920
+ oldState: childWidget.newState,
7921
+ newState
7922
+ };
7923
+ const newWidgets = [...editor.widgets.slice(0, childIndex), newWidget, ...editor.widgets.slice(childIndex + 1)];
7924
+ return {
7925
+ ...editor,
7926
+ widgets: newWidgets
7927
+ };
7928
+ };
7929
+
7890
7930
  const replaceAll$1 = async editor => {
7891
7931
  const state = getFindState(editor);
7892
7932
  if (!state) {
@@ -7899,7 +7939,9 @@ const replaceAll$1 = async editor => {
7899
7939
  } = state;
7900
7940
  const edits = replaceTextOccurrences(editor, matches, value, replacement);
7901
7941
  const newEditor = await applyEdit(editor, edits);
7902
- return newEditor;
7942
+ const newState = refresh$1(newEditor, state, value);
7943
+ const newestEditor = updateWidget(newEditor, Find, newState);
7944
+ return newestEditor;
7903
7945
  };
7904
7946
 
7905
7947
  const pending = Object.create(null);
@@ -7989,6 +8031,19 @@ const handleBeforeInput = (editor, inputType, data) => {
7989
8031
  }
7990
8032
  };
7991
8033
 
8034
+ const applyTabCompletion = (editor, result) => {
8035
+ return editorSnippet(editor, result);
8036
+ };
8037
+
8038
+ const handleTab = async editor => {
8039
+ const result = await getTabCompletion(editor);
8040
+ if (!result) {
8041
+ // TODO enter tab or two spaces
8042
+ return editor;
8043
+ }
8044
+ return applyTabCompletion(editor, result);
8045
+ };
8046
+
7992
8047
  let enabled = false;
7993
8048
  const setEnabled = value => {
7994
8049
  enabled = value;
@@ -8887,16 +8942,8 @@ const wrapWidgetCommand = (widgetId, fn) => {
8887
8942
  // TODO scroll up/down if necessary
8888
8943
  const childWidget = editor.widgets[childIndex];
8889
8944
  const newState = await fn(childWidget.newState, ...args);
8890
- const newWidget = {
8891
- ...childWidget,
8892
- oldState: childWidget.newState,
8893
- newState
8894
- };
8895
- const newWidgets = [...editor.widgets.slice(0, childIndex), newWidget, ...editor.widgets.slice(childIndex + 1)];
8896
- return {
8897
- ...editor,
8898
- widgets: newWidgets
8899
- };
8945
+ const newEditor = updateWidget(editor, widgetId, newState);
8946
+ return newEditor;
8900
8947
  };
8901
8948
  return wrapped;
8902
8949
  };
@@ -8962,6 +9009,7 @@ const commandMap = {
8962
9009
  'ColorPicker.loadContent': loadContent$3,
8963
9010
  'Editor.addCursorAbove': addCursorAbove,
8964
9011
  'Editor.addCursorBelow': addCursorBelow,
9012
+ 'Editor.handleTab': handleTab,
8965
9013
  'Editor.applyEdit': applyEdit,
8966
9014
  'Editor.braceCompletion': braceCompletion,
8967
9015
  'Editor.cancelSelection': cancelSelection,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "3.29.0",
3
+ "version": "3.31.0",
4
4
  "description": "",
5
5
  "main": "dist/editorWorkerMain.js",
6
6
  "type": "module",