@lvce-editor/editor-worker 1.15.0 → 2.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.
@@ -1816,7 +1816,8 @@ const createEditor = async ({
1816
1816
  letterSpacing,
1817
1817
  charWidth,
1818
1818
  uid: id,
1819
- id
1819
+ id,
1820
+ widgets: []
1820
1821
  };
1821
1822
  // TODO avoid creating intermediate editors here
1822
1823
  const newEditor1 = setBounds(editor, x, y, width, height, 9);
@@ -2240,9 +2241,6 @@ const braceCompletion = async (editor, text) => {
2240
2241
  }
2241
2242
  };
2242
2243
 
2243
- // @ts-ignore
2244
-
2245
- // @ts-ignore
2246
2244
  const cancelSelection = editor => {
2247
2245
  const selections = editor.selections;
2248
2246
  if (selections.length === 4 && selections[0] === selections[2] && selections[1] === selections[3]) {
@@ -2253,12 +2251,22 @@ const cancelSelection = editor => {
2253
2251
  return scheduleSelections(editor, newSelections);
2254
2252
  };
2255
2253
 
2256
- const closeCompletion = async editor => {
2257
- // TODO
2258
- const completionUid = editor.completionUid;
2259
- await invoke$3('Viewlet.dispose', completionUid);
2260
- editor.completionUid = 0;
2261
- return editor;
2254
+ const isCompletionWidget = widget => {
2255
+ return widget.id === 'completion';
2256
+ };
2257
+ const closeCompletion = editor => {
2258
+ const {
2259
+ widgets
2260
+ } = editor;
2261
+ const completionWidgetIndex = widgets.findIndex(isCompletionWidget);
2262
+ if (completionWidgetIndex === -1) {
2263
+ return editor;
2264
+ }
2265
+ const newWidgets = [...widgets.slice(0, completionWidgetIndex), ...widgets.slice(completionWidgetIndex + 1)];
2266
+ return {
2267
+ ...editor,
2268
+ widgets: newWidgets
2269
+ };
2262
2270
  };
2263
2271
 
2264
2272
  // @ts-ignore
@@ -3274,7 +3282,8 @@ const UiStrings = {
3274
3282
  EditorCloseColorPicker: 'Editor: Close Color Picker',
3275
3283
  EditorCopyLineDown: 'Editor: Copy Line Down',
3276
3284
  EditorCopyLineUp: 'Editor: Copy Line Up',
3277
- Replace: 'replace'
3285
+ Replace: 'replace',
3286
+ NoResults: 'No Results'
3278
3287
  };
3279
3288
  const noDefinitionFound = () => {
3280
3289
  return i18nString(UiStrings.NoDefinitionFound);
@@ -3296,6 +3305,9 @@ const noTypeDefinitionFoundFor = word => {
3296
3305
  const noTypeDefinitionFound = () => {
3297
3306
  return i18nString(UiStrings.NoTypeDefinitionFound);
3298
3307
  };
3308
+ const noResults = () => {
3309
+ return i18nString(UiStrings.NoResults);
3310
+ };
3299
3311
 
3300
3312
  // @ts-ignore
3301
3313
  const goTo = async ({
@@ -6264,7 +6276,7 @@ const resolveCompletion = async (editor, name, completionItem) => {
6264
6276
  }
6265
6277
  };
6266
6278
 
6267
- const None = 1;
6279
+ const None$1 = 1;
6268
6280
 
6269
6281
  const EmptyMatches = [];
6270
6282
 
@@ -6535,7 +6547,7 @@ const handleEditorDeleteLeft = (editorUid, state) => {
6535
6547
  const y$1 = y(editor, rowIndex);
6536
6548
  const wordAtOffset = getWordAtOffset(editor);
6537
6549
  if (!wordAtOffset) {
6538
- editor.completionState = None;
6550
+ editor.completionState = None$1;
6539
6551
  return {
6540
6552
  ...state,
6541
6553
  disposed: true
@@ -6561,7 +6573,7 @@ const dispose = state => {
6561
6573
  };
6562
6574
  };
6563
6575
  const disposeWithEditor = (state, editor) => {
6564
- editor.completionState = None;
6576
+ editor.completionState = None$1;
6565
6577
  editor.completionUid = 0;
6566
6578
  // Focus.removeAdditionalFocus(FocusKey.EditorCompletion)
6567
6579
  return dispose(state);
@@ -6603,7 +6615,8 @@ const loadContent$2 = async (editorUid, state) => {
6603
6615
  height,
6604
6616
  rowIndex,
6605
6617
  columnIndex,
6606
- editorUid
6618
+ editorUid,
6619
+ width: 200
6607
6620
  };
6608
6621
  };
6609
6622
  const advance = (state, word) => {
@@ -6614,12 +6627,24 @@ const advance = (state, word) => {
6614
6627
  };
6615
6628
  };
6616
6629
 
6617
- const getEdits = async (state, editor, completionItem) => {
6630
+ const isCompletion$1 = widget => {
6631
+ return widget.id === 'completion';
6632
+ };
6633
+ const getCompletionState = editor => {
6634
+ const {
6635
+ widgets
6636
+ } = editor;
6637
+ const child = widgets.find(isCompletion$1);
6638
+ return child.newState;
6639
+ };
6640
+
6641
+ const getEdits = async (editor, completionItem) => {
6642
+ const child = getCompletionState(editor);
6618
6643
  // @ts-ignore
6619
6644
  const {
6620
6645
  leadingWord,
6621
6646
  uid
6622
- } = state;
6647
+ } = child;
6623
6648
  const word = completionItem.label;
6624
6649
  const resolvedItem = await resolveCompletion(editor, word, completionItem);
6625
6650
  const inserted = resolvedItem ? resolvedItem.snippet : word;
@@ -6633,41 +6658,55 @@ const getEdits = async (state, editor, completionItem) => {
6633
6658
  const changes = replaceRange(editor, replaceRange$1, [inserted], '');
6634
6659
  return changes;
6635
6660
  };
6636
- const select = async (state, editor, completionItem) => {
6637
- const changes = await getEdits(state, editor, completionItem);
6661
+ const isCompletion = widget => {
6662
+ return widget.id === 'completion';
6663
+ };
6664
+ const select = async (editor, completionItem) => {
6665
+ const changes = await getEdits(editor, completionItem);
6638
6666
  const index = editor.widgets.indexOf
6639
6667
  // ViewletModuleId.EditorCompletion
6640
6668
  ();
6641
6669
  if (index !== -1) {
6642
6670
  editor.widgets.splice(index, 1);
6643
- editor.completionState = None;
6671
+ editor.completionState = None$1;
6644
6672
  editor.completionUid = 0;
6645
6673
  }
6646
- await invoke$3('Editor.applyEdit', changes);
6647
- await invoke$3('Viewlet.dispose', state.uid);
6648
- return state;
6674
+ // TODO dispose completion widget
6675
+ // TODO apply edit in editor worker instead of asking renderer worker
6676
+ // await RendererWorker.invoke('Viewlet.dispose', state.uid)
6677
+ const {
6678
+ widgets
6679
+ } = editor;
6680
+ const completionWidgetIndex = editor.widgets.findIndex(isCompletion);
6681
+ const newWidgets = [...widgets.slice(0, completionWidgetIndex), ...widgets.slice(completionWidgetIndex + 1)];
6682
+ const intermediateEditor = await applyEdit(editor, changes);
6683
+ return {
6684
+ ...intermediateEditor,
6685
+ widgets: newWidgets
6686
+ };
6649
6687
  };
6650
- const selectIndex = (editorUid, state, index) => {
6651
- const editor = getEditor(editorUid);
6688
+ const selectIndex = (editor, index) => {
6689
+ const child = getCompletionState(editor);
6652
6690
  const {
6653
6691
  items
6654
- } = state;
6692
+ } = child;
6655
6693
  if (index === -1) {
6656
- return state;
6694
+ return editor;
6657
6695
  }
6658
6696
  if (index > items.length) {
6659
6697
  throw new Error('index too large');
6660
6698
  }
6661
6699
  const actualIndex = index;
6662
6700
  const completionItem = items[actualIndex];
6663
- return select(state, editor, completionItem);
6701
+ return select(editor, completionItem);
6664
6702
  };
6665
6703
 
6666
- const selectCurrent = (editorUid, state) => {
6704
+ const selectCurrent = editor => {
6705
+ const child = getCompletionState(editor);
6667
6706
  const {
6668
6707
  focusedIndex
6669
- } = state;
6670
- return selectIndex(editorUid, state, focusedIndex);
6708
+ } = child;
6709
+ return selectIndex(editor, focusedIndex);
6671
6710
  };
6672
6711
 
6673
6712
  // copied from https://github.com/microsoft/vscode/tree/main/src/vs/base/common/strings.ts by Microsoft (License MIT)
@@ -7170,7 +7209,7 @@ const moveLineUp = editor => {
7170
7209
  };
7171
7210
 
7172
7211
  const Link$1 = 'Link';
7173
- const Function = 'Function';
7212
+ const Function$1 = 'Function';
7174
7213
  const Parameter = 'Parameter';
7175
7214
  const Type = 'Type';
7176
7215
  const VariableName = 'VariableName';
@@ -7229,7 +7268,7 @@ const getDecorationClassName = type => {
7229
7268
  case Ts3073:
7230
7269
  case Ts3077:
7231
7270
  case Ts3088:
7232
- return Function;
7271
+ return Function$1;
7233
7272
  case Ts1792:
7234
7273
  case Ts1793:
7235
7274
  return Parameter;
@@ -7658,7 +7697,9 @@ const getVisible = async (editor, syncIncremental) => {
7658
7697
  const Div = 4;
7659
7698
  const Span = 8;
7660
7699
  const Text = 12;
7700
+ const Img = 17;
7661
7701
 
7702
+ const ColoredMaskIcon = 'ColoredMaskIcon';
7662
7703
  const ColorPicker = 'ColorPicker';
7663
7704
  const ColorPickerBackgroundColor = 'ColorPickerBackgroundColor';
7664
7705
  const ColorPickerDark = 'ColorPickerDark';
@@ -7667,15 +7708,21 @@ const ColorPickerRectangle = 'ColorPickerRectangle';
7667
7708
  const ColorPickerSlider = 'ColorPickerSlider';
7668
7709
  const ColorPickerSliderThumb = 'ColorPickerSliderThumb';
7669
7710
  const Diagnostic = 'Diagnostic';
7711
+ const EditorCompletionItem = 'EditorCompletionItem';
7712
+ const EditorCompletionItemDeprecated = 'EditorCompletionItemDeprecated';
7713
+ const EditorCompletionItemFocused = 'EditorCompletionItemFocused';
7714
+ const EditorCompletionItemHighlight = 'EditorCompletionItemHighlight';
7670
7715
  const EditorCursor = 'EditorCursor';
7671
7716
  const EditorRow = 'EditorRow';
7672
7717
  const EditorSelection = 'EditorSelection';
7718
+ const FileIcon = 'FileIcon';
7673
7719
  const HoverDisplayString = 'HoverDisplayString';
7674
7720
  const HoverDocumentation = 'HoverDocumentation';
7675
7721
  const HoverEditorRow = 'HoverEditorRow';
7676
7722
  const HoverProblem = 'HoverProblem';
7677
7723
  const HoverProblemDetail = 'HoverProblemDetail';
7678
7724
  const HoverProblemMessage = 'HoverProblemMessage';
7725
+ const Label = 'Label';
7679
7726
  const Viewlet = 'Viewlet';
7680
7727
 
7681
7728
  const getCursorsVirtualDom = cursors => {
@@ -7813,6 +7860,315 @@ const getSelectionsVirtualDom = selections => {
7813
7860
  return dom;
7814
7861
  };
7815
7862
 
7863
+ const None = 'none';
7864
+ const Option = 'option';
7865
+
7866
+ const getFileIconVirtualDom = icon => {
7867
+ return {
7868
+ type: Img,
7869
+ className: FileIcon,
7870
+ src: icon,
7871
+ role: None,
7872
+ childCount: 0
7873
+ };
7874
+ };
7875
+
7876
+ const getIconDom = (fileIcon, symbolName) => {
7877
+ if (fileIcon) {
7878
+ return getFileIconVirtualDom(fileIcon);
7879
+ }
7880
+ return {
7881
+ type: Div,
7882
+ className: `${ColoredMaskIcon} ${symbolName}`,
7883
+ childCount: 0
7884
+ };
7885
+ };
7886
+
7887
+ const label1 = {
7888
+ type: Div,
7889
+ className: Label,
7890
+ childCount: 1
7891
+ };
7892
+ const completionHighlight = {
7893
+ type: Span,
7894
+ className: EditorCompletionItemHighlight,
7895
+ childCount: 1
7896
+ };
7897
+ const getHighlightedLabelDom = (label, highlights) => {
7898
+ if (highlights.length === 0) {
7899
+ return [label1, text(label)];
7900
+ }
7901
+ const dom = [];
7902
+ const labelDom = {
7903
+ type: Div,
7904
+ className: Label,
7905
+ childCount: 0
7906
+ };
7907
+ dom.push(labelDom);
7908
+ let position = 0;
7909
+ for (let i = 0; i < highlights.length; i += 2) {
7910
+ const highlightStart = highlights[i];
7911
+ const highlightEnd = highlights[i + 1];
7912
+ if (position < highlightStart) {
7913
+ const beforeText = label.slice(position, highlightStart);
7914
+ labelDom.childCount++;
7915
+ dom.push(text(beforeText));
7916
+ }
7917
+ const highlightText = label.slice(highlightStart, highlightEnd);
7918
+ labelDom.childCount++;
7919
+ dom.push(completionHighlight, text(highlightText));
7920
+ position = highlightEnd;
7921
+ }
7922
+ if (position < label.length) {
7923
+ const afterText = label.slice(position);
7924
+ labelDom.childCount++;
7925
+ dom.push(text(afterText));
7926
+ }
7927
+ return dom;
7928
+ };
7929
+
7930
+ const getCompletionItemVirtualDom = visibleItem => {
7931
+ const {
7932
+ top,
7933
+ label,
7934
+ symbolName,
7935
+ highlights,
7936
+ focused,
7937
+ deprecated,
7938
+ fileIcon
7939
+ } = visibleItem;
7940
+ let className = EditorCompletionItem;
7941
+ if (focused) {
7942
+ className += ' ' + EditorCompletionItemFocused;
7943
+ }
7944
+ if (deprecated) {
7945
+ className += ' ' + EditorCompletionItemDeprecated;
7946
+ }
7947
+ return [{
7948
+ type: Div,
7949
+ role: Option,
7950
+ className,
7951
+ top,
7952
+ childCount: 2
7953
+ }, getIconDom(fileIcon, symbolName), ...getHighlightedLabelDom(label, highlights)];
7954
+ };
7955
+
7956
+ const getCompletionItemsVirtualDom = visibleItems => {
7957
+ if (visibleItems.length === 0) {
7958
+ return [{
7959
+ type: Div,
7960
+ childCount: 1
7961
+ }, text(noResults())];
7962
+ }
7963
+ const root = {
7964
+ type: Div,
7965
+ childCount: visibleItems.length
7966
+ };
7967
+ const dom = [root, ...visibleItems.flatMap(getCompletionItemVirtualDom)];
7968
+ return dom;
7969
+ };
7970
+
7971
+ const Property = 1;
7972
+ const Value = 2;
7973
+ const Function = 3;
7974
+ const Variable = 4;
7975
+ const Keyword = 5;
7976
+ const Folder = 6;
7977
+ const File = 7;
7978
+ const Field = 8;
7979
+
7980
+ const SymbolProperty = 'SymbolProperty';
7981
+ const SymbolValue = 'SymbolValue';
7982
+ const SymbolFunction = 'SymbolFunction';
7983
+ const SymbolVariable = 'SymbolVariable';
7984
+ const SymbolKeyword = 'SymbolKeyword';
7985
+ const SymbolDefault = 'SymbolDefault';
7986
+ const SymbolField = 'SymbolField';
7987
+ const SymbolNone = '';
7988
+
7989
+ const getSymbolName = item => {
7990
+ switch (item.kind) {
7991
+ case Property:
7992
+ return SymbolProperty;
7993
+ case Value:
7994
+ return SymbolValue;
7995
+ case Function:
7996
+ return SymbolFunction;
7997
+ case Variable:
7998
+ return SymbolVariable;
7999
+ case Keyword:
8000
+ return SymbolKeyword;
8001
+ case Field:
8002
+ return SymbolField;
8003
+ case File:
8004
+ return SymbolNone;
8005
+ default:
8006
+ return SymbolDefault;
8007
+ }
8008
+ };
8009
+
8010
+ const getHighlights = (item, leadingWord) => {
8011
+ const {
8012
+ matches
8013
+ } = item;
8014
+ return matches.slice(1);
8015
+ };
8016
+
8017
+ // import * as IconTheme from '../IconTheme/IconTheme.ts'
8018
+
8019
+ const getLabel = item => {
8020
+ return item.label;
8021
+ };
8022
+ const getFileIcon = item => {
8023
+ switch (item.kind) {
8024
+ case File:
8025
+ // TODO IconTheme.getFileNameIcon(item.label)
8026
+ return '';
8027
+ case Folder:
8028
+ // TODO IconTheme.getFolderNameIcon(item.label)
8029
+ return '';
8030
+ default:
8031
+ return '';
8032
+ }
8033
+ };
8034
+ const getVisibleIem = (item, itemHeight, leadingWord, i, focusedIndex) => {
8035
+ return {
8036
+ label: getLabel(item),
8037
+ symbolName: getSymbolName(item),
8038
+ top: i * itemHeight,
8039
+ highlights: getHighlights(item),
8040
+ focused: i === focusedIndex,
8041
+ deprecated: item.flags & Deprecated,
8042
+ fileIcon: getFileIcon(item)
8043
+ };
8044
+ };
8045
+
8046
+ const getVisibleItems = (filteredItems, itemHeight, leadingWord, minLineY, maxLineY, focusedIndex) => {
8047
+ const visibleItems = [];
8048
+ for (let i = minLineY; i < maxLineY; i++) {
8049
+ const filteredItem = filteredItems[i];
8050
+ visibleItems.push(getVisibleIem(filteredItem, itemHeight, leadingWord, i, focusedIndex));
8051
+ }
8052
+ return visibleItems;
8053
+ };
8054
+
8055
+ const SetBounds = 'setBounds';
8056
+ const SetColor = 'setColor';
8057
+ const SetContentHeight = 'setContentHeight';
8058
+ const SetNegativeMargin = 'setNegativeMargin';
8059
+ const SetOffsetX = 'setOffsetX';
8060
+ const SetScrollBar = 'setScrollBar';
8061
+
8062
+ const renderItems = {
8063
+ isEqual(oldState, newState) {
8064
+ return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.focusedIndex === newState.focusedIndex;
8065
+ },
8066
+ apply(oldState, newState) {
8067
+ const visibleItems = getVisibleItems(newState.items, newState.itemHeight, newState.leadingWord, newState.minLineY, newState.maxLineY, newState.focusedIndex);
8068
+ const dom = getCompletionItemsVirtualDom(visibleItems);
8069
+ return ['setDom', dom];
8070
+ }
8071
+ };
8072
+ const renderBounds$1 = {
8073
+ isEqual(oldState, newState) {
8074
+ return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.x === newState.x && oldState.y === newState.y;
8075
+ },
8076
+ apply(oldState, newState) {
8077
+ const {
8078
+ x,
8079
+ y,
8080
+ width,
8081
+ height
8082
+ } = newState;
8083
+ return [/* method */SetBounds, /* x */x, /* y */y, /* width */width, /* height */height];
8084
+ }
8085
+ };
8086
+ const renderHeight = {
8087
+ isEqual(oldState, newState) {
8088
+ return oldState.items.length === newState.items.length;
8089
+ },
8090
+ apply(oldState, newState) {
8091
+ const {
8092
+ itemHeight
8093
+ } = newState;
8094
+ const contentHeight = newState.items.length * itemHeight;
8095
+ return [/* method */SetContentHeight, /* contentHeight */contentHeight];
8096
+ }
8097
+ };
8098
+ const renderNegativeMargin = {
8099
+ isEqual(oldState, newState) {
8100
+ return oldState.deltaY === newState.deltaY;
8101
+ },
8102
+ apply(oldState, newState) {
8103
+ return [/* method */SetNegativeMargin, /* negativeMargin */-newState.deltaY];
8104
+ }
8105
+ };
8106
+ const renderScrollBar = {
8107
+ isEqual(oldState, newState) {
8108
+ return oldState.negativeMargin === newState.negativeMargin && oldState.deltaY === newState.deltaY && oldState.height === newState.height && oldState.finalDeltaY === newState.finalDeltaY && oldState.items.length === newState.items.length;
8109
+ },
8110
+ apply(oldState, newState) {
8111
+ const total = newState.items.length;
8112
+ const contentHeight = total * newState.itemHeight;
8113
+ const scrollBarHeight = getScrollBarSize(newState.height, contentHeight, newState.minimumSliderSize);
8114
+ const scrollBarY = getScrollBarY(newState.deltaY, newState.finalDeltaY, newState.height - newState.headerHeight, scrollBarHeight);
8115
+ return [/* method */SetScrollBar, /* scrollBarY */scrollBarY, /* scrollBarHeight */scrollBarHeight];
8116
+ }
8117
+ };
8118
+ const render$3 = [renderItems, renderBounds$1, renderHeight, renderNegativeMargin, renderScrollBar];
8119
+ const renderCompletion$1 = (oldState, newState) => {
8120
+ const commands = [];
8121
+ for (const item of render$3) {
8122
+ if (!item.isEqual(oldState, newState)) {
8123
+ commands.push(item.apply(oldState, newState));
8124
+ }
8125
+ }
8126
+ return commands;
8127
+ };
8128
+
8129
+ const renderCompletion = (oldState, newState) => {
8130
+ const commands = renderCompletion$1(oldState, newState);
8131
+ return commands;
8132
+ };
8133
+ const addWidgetCompletion = widget => {
8134
+ const commands = renderCompletion(widget.oldState, widget.newState);
8135
+ const id = 'EditorCompletion';
8136
+ // TODO how to generate a unique integer id
8137
+ // that doesn't collide with ids created in renderer worker?
8138
+ const uid = widget.newState.uid;
8139
+ const allCommands = [];
8140
+ allCommands.push(['Viewlet.create', id, uid]);
8141
+ for (const command of commands) {
8142
+ allCommands.push(['Viewlet.send', uid, ...command]);
8143
+ }
8144
+ return allCommands;
8145
+ };
8146
+ const addWidget = widget => {
8147
+ const {
8148
+ id
8149
+ } = widget;
8150
+ switch (id) {
8151
+ case 'completion':
8152
+ return addWidgetCompletion(widget);
8153
+ default:
8154
+ throw new Error('unsupported widget');
8155
+ }
8156
+ };
8157
+ const removeCompletion = widget => {
8158
+ return [['Viewlet.send', widget.newState.uid, 'dispose']];
8159
+ };
8160
+ const removeWidget = widget => {
8161
+ const {
8162
+ id
8163
+ } = widget;
8164
+ switch (id) {
8165
+ case 'completion':
8166
+ return removeCompletion(widget);
8167
+ default:
8168
+ throw new Error('unsupported widget');
8169
+ }
8170
+ };
8171
+
7816
8172
  const renderLines = {
7817
8173
  isEqual(oldState, newState) {
7818
8174
  return oldState.lines === newState.lines && oldState.tokenizerId === newState.tokenizerId && oldState.minLineY === newState.minLineY && oldState.decorations === newState.decorations && oldState.embeds === newState.embeds && oldState.deltaX === newState.deltaX && oldState.width === newState.width;
@@ -7909,7 +8265,53 @@ const renderGutterInfo = {
7909
8265
  return ['renderGutter', dom];
7910
8266
  }
7911
8267
  };
7912
- const render$2 = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus, renderDecorations, renderGutterInfo];
8268
+ const renderWidgets = {
8269
+ isEqual(oldState, newState) {
8270
+ return oldState.widgets === newState.widgets;
8271
+ },
8272
+ apply(oldState, newState) {
8273
+ const addedWidgets = [];
8274
+ const removedWidgets = [];
8275
+ const oldWidgets = oldState.widgets || [];
8276
+ const newWidgets = newState.widgets || [];
8277
+ const oldWidgetMap = Object.create(null);
8278
+ const newWidgetMap = Object.create(null);
8279
+ for (const oldWidget of oldWidgets) {
8280
+ oldWidgetMap[oldWidget.id] = oldWidget;
8281
+ }
8282
+ for (const newWidget of newWidgets) {
8283
+ newWidgetMap[newWidget.id] = newWidget;
8284
+ }
8285
+ for (const oldWidget of oldWidgets) {
8286
+ if (oldWidget.id in newWidgetMap) ; else {
8287
+ removedWidgets.push(oldWidget);
8288
+ }
8289
+ }
8290
+ for (const newWidget of newWidgets) {
8291
+ if (newWidget.id in oldWidgetMap) ; else {
8292
+ addedWidgets.push(newWidget);
8293
+ }
8294
+ }
8295
+ const addCommands = [];
8296
+ for (const addedWidget of addedWidgets) {
8297
+ const childCommands = addWidget(addedWidget);
8298
+ if (childCommands.length > 0) {
8299
+ addCommands.push(...childCommands);
8300
+ }
8301
+ }
8302
+ const removeCommands = [];
8303
+ for (const removedWidget of removedWidgets) {
8304
+ const childCommands = removeWidget(removedWidget);
8305
+ if (childCommands.length > 0) {
8306
+ removeCommands.push(...childCommands);
8307
+ }
8308
+ }
8309
+ const allCommands = [...addCommands, ...removeCommands];
8310
+ return allCommands;
8311
+ },
8312
+ multiple: true
8313
+ };
8314
+ const render$2 = [renderLines, renderSelections, renderScrollBarX, renderScrollBarY, renderFocus, renderDecorations, renderGutterInfo, renderWidgets];
7913
8315
  const renderEditor = async id => {
7914
8316
  const instance = get$6(id);
7915
8317
  if (!instance) {
@@ -7923,13 +8325,77 @@ const renderEditor = async id => {
7923
8325
  set$6(id, newState, newState);
7924
8326
  for (const item of render$2) {
7925
8327
  if (!item.isEqual(oldState, newState)) {
7926
- commands.push(await item.apply(oldState, newState));
8328
+ const result = await item.apply(oldState, newState);
8329
+ // @ts-ignore
8330
+ if (item.multiple) {
8331
+ commands.push(...result);
8332
+ } else if (result.length > 0) {
8333
+ commands.push(result);
8334
+ }
7927
8335
  }
7928
8336
  }
7929
8337
  return commands;
7930
8338
  };
7931
8339
 
7932
- const keep = ['ColorPicker.handleSliderPointerDown', 'ColorPicker.handleSliderPointerMove', 'ColorPicker.loadContent', 'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render', 'ColorPicker.render', 'Editor.getText', 'Editor.getSelections', 'EditorCompletion.advance', 'EditorCompletion.handleEditorBlur', 'EditorCompletion.handleEditorClick', 'EditorCompletion.handleEditorDeleteLeft', 'EditorCompletion.handleEditorType', 'EditorCompletion.loadContent', 'EditorCompletion.selectCurrent', 'EditorCompletion.selectIndex', 'FindWidget.focusFirst', 'FindWidget.focusIndex', 'FindWidget.focusLast', 'FindWidget.focusNext', 'FindWidget.focusPrevious', 'FindWidget.handleInput', 'FindWidget.loadContent', 'Font.ensure', 'Hover.getHoverInfo', 'Hover.handleSashPointerDown', 'Hover.handleSashPointerMove', 'Hover.handleSashPointerUp', 'Hover.loadContent', 'Hover.render', 'Initialize.initialize'];
8340
+ const openCompletion = async editor => {
8341
+ const {
8342
+ widgets,
8343
+ uid
8344
+ } = editor;
8345
+ const completionUid = Math.random();
8346
+ const completionWidget = {
8347
+ id: 'completion',
8348
+ oldState: {
8349
+ items: [],
8350
+ itemHeight: 20,
8351
+ maxHeight: 150,
8352
+ minLineY: 0,
8353
+ maxLineY: 0,
8354
+ uid: completionUid
8355
+ },
8356
+ newState: {
8357
+ items: [],
8358
+ itemHeight: 20,
8359
+ maxHeight: 150,
8360
+ minLineY: 0,
8361
+ maxLineY: 10,
8362
+ uid: completionUid
8363
+ }
8364
+ };
8365
+ const newWidgets = [...widgets, completionWidget];
8366
+ const newEditor = {
8367
+ ...editor,
8368
+ widgets: newWidgets
8369
+ };
8370
+ set$6(uid, editor, newEditor);
8371
+ const newCompletionWidget = await loadContent$2(uid, completionWidget.newState);
8372
+ const FocusEditorCompletions = 9;
8373
+ await invoke$3('Focus.setAdditionalFocus', FocusEditorCompletions);
8374
+ const latestEditor = getEditor(uid);
8375
+ if (!latestEditor.widgets.includes(completionWidget)) {
8376
+ return editor;
8377
+ }
8378
+ const index = latestEditor.widgets.indexOf(completionWidget);
8379
+ const latestWidgets = [...latestEditor.widgets.slice(0, index), {
8380
+ ...completionWidget,
8381
+ newState: newCompletionWidget
8382
+ }, ...latestEditor.widgets.slice(index + 1)];
8383
+ return {
8384
+ ...latestEditor,
8385
+ widgets: latestWidgets
8386
+ };
8387
+ };
8388
+
8389
+ const keep = ['ColorPicker.handleSliderPointerDown', 'ColorPicker.handleSliderPointerMove', 'ColorPicker.loadContent', 'Editor.create', 'Editor.getWordAt', 'Editor.getWordBefore', 'Editor.offsetAt', 'Editor.render', 'ColorPicker.render', 'Editor.getText', 'Editor.getSelections',
8390
+ // 'EditorCompletion.advance',
8391
+ // 'EditorCompletion.handleEditorBlur',
8392
+ // 'EditorCompletion.handleEditorClick',
8393
+ // 'EditorCompletion.handleEditorDeleteLeft',
8394
+ // 'EditorCompletion.handleEditorType',
8395
+ // 'EditorCompletion.loadContent',
8396
+ // 'EditorCompletion.selectCurrent',
8397
+ // 'EditorCompletion.selectIndex',
8398
+ 'FindWidget.focusFirst', 'FindWidget.focusIndex', 'FindWidget.focusLast', 'FindWidget.focusNext', 'FindWidget.focusPrevious', 'FindWidget.handleInput', 'FindWidget.loadContent', 'Font.ensure', 'Hover.getHoverInfo', 'Hover.handleSashPointerDown', 'Hover.handleSashPointerMove', 'Hover.handleSashPointerUp', 'Hover.loadContent', 'Hover.render', 'Initialize.initialize'];
7933
8399
 
7934
8400
  // TODO wrap commands globally, not per editor
7935
8401
  // TODO only store editor state in editor worker, not in renderer worker also
@@ -7991,10 +8457,6 @@ const getColorPickerVirtualDom = () => {
7991
8457
  }];
7992
8458
  };
7993
8459
 
7994
- const SetBounds = 'setBounds';
7995
- const SetColor = 'setColor';
7996
- const SetOffsetX = 'setOffsetX';
7997
-
7998
8460
  const renderColor = {
7999
8461
  isEqual(oldState, newState) {
8000
8462
  return oldState.color === newState.color;
@@ -8234,8 +8696,8 @@ const commandMap = {
8234
8696
  'Editor.deleteWordRight': deleteWordRight,
8235
8697
  'Editor.findAllReferences': findAllReferences,
8236
8698
  'Editor.format': format,
8237
- 'Editor.getWordAt': getWordAt,
8238
8699
  'Editor.getText': getText,
8700
+ 'Editor.getWordAt': getWordAt,
8239
8701
  'Editor.getWordBefore': getWordBefore,
8240
8702
  'Editor.goToDefinition': goToDefinition,
8241
8703
  'Editor.goToTypeDefinition': goToTypeDefinition,
@@ -8273,6 +8735,7 @@ const commandMap = {
8273
8735
  'Editor.moveSelection': editorMoveSelection,
8274
8736
  'Editor.moveSelectionPx': moveSelectionPx,
8275
8737
  'Editor.offsetAt': offsetAt,
8738
+ 'Editor.openCompletion': openCompletion,
8276
8739
  'Editor.openFind': openFind,
8277
8740
  'Editor.organizeImports': organizeImports,
8278
8741
  'Editor.paste': paste,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "1.15.0",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",