@lvce-editor/editor-worker 2.2.0 → 2.3.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.
@@ -246,7 +246,6 @@ const Tab = '\t';
246
246
  const Underline = '_';
247
247
  const T = 't';
248
248
 
249
- // @ts-ignore
250
249
  const getFontString = (fontWeight, fontSize, fontFamily) => {
251
250
  return `${fontWeight} ${fontSize}px ${fontFamily}`;
252
251
  };
@@ -255,14 +254,18 @@ const getLetterSpacingString = letterSpacing => {
255
254
  return `${letterSpacing}px`;
256
255
  };
257
256
 
257
+ const createMeasureContext = () => {
258
+ const canvas = new OffscreenCanvas(0, 0);
259
+ const ctx = /** @type {OffscreenCanvasRenderingContext2D} */canvas.getContext('2d');
260
+ if (!ctx) {
261
+ throw new Error('Failed to get canvas context 2d');
262
+ }
263
+ return ctx;
264
+ };
265
+
258
266
  const state$b = {
259
267
  ctx: undefined
260
268
  };
261
-
262
- /**
263
- * @param {()=>OffscreenCanvasRenderingContext2D} createCtx
264
- * @returns {OffscreenCanvasRenderingContext2D}
265
- */
266
269
  const getOrCreate = createCtx => {
267
270
  if (state$b.ctx) {
268
271
  return state$b.ctx;
@@ -271,16 +274,8 @@ const getOrCreate = createCtx => {
271
274
  return state$b.ctx;
272
275
  };
273
276
 
274
- const createCtx = () => {
275
- const canvas = new OffscreenCanvas(0, 0);
276
- const ctx = /** @type {OffscreenCanvasRenderingContext2D} */canvas.getContext('2d');
277
- if (!ctx) {
278
- throw new Error('Failed to get canvas context 2d');
279
- }
280
- return ctx;
281
- };
282
277
  const getContext = () => {
283
- const ctx = getOrCreate(createCtx);
278
+ const ctx = getOrCreate(createMeasureContext);
284
279
  return ctx;
285
280
  };
286
281
 
@@ -454,7 +449,6 @@ const getAccurateColumnIndex = (line, fontWeight, fontSize, fontFamily, letterSp
454
449
  return getAccurateColumnIndexUnicode(line, normalizedGuess, charWidth, eventX, fontWeight, fontSize, fontFamily, letterSpacing);
455
450
  };
456
451
 
457
- // @ts-ignore
458
452
  const at = (editor, eventX, eventY) => {
459
453
  object(editor);
460
454
  number$1(eventX);
@@ -498,7 +492,6 @@ const at = (editor, eventX, eventY) => {
498
492
  * @param {number} columnIndex
499
493
  * @returns
500
494
  */
501
- // @ts-ignore
502
495
  const x = (editor, rowIndex, columnIndex) => {
503
496
  const {
504
497
  columnWidth,
@@ -507,8 +500,6 @@ const x = (editor, rowIndex, columnIndex) => {
507
500
  const offsetX = columnIndex * columnWidth + x;
508
501
  return offsetX;
509
502
  };
510
-
511
- // @ts-ignore
512
503
  const y = (editor, rowIndex) => {
513
504
  const {
514
505
  rowHeight,
@@ -740,8 +731,8 @@ const SymbolDefault = 'SymbolDefault';
740
731
  const SymbolField = 'SymbolField';
741
732
  const SymbolNone = '';
742
733
 
743
- const getSymbolName = item => {
744
- switch (item.kind) {
734
+ const getSymbolName = kind => {
735
+ switch (kind) {
745
736
  case Property:
746
737
  return SymbolProperty;
747
738
  case Value:
@@ -788,7 +779,7 @@ const getFileIcon = item => {
788
779
  const getVisibleIem = (item, itemHeight, leadingWord, i, focusedIndex) => {
789
780
  return {
790
781
  label: getLabel(item),
791
- symbolName: getSymbolName(item),
782
+ symbolName: getSymbolName(item.kind),
792
783
  top: i * itemHeight,
793
784
  highlights: getHighlights(item),
794
785
  focused: i === focusedIndex,
@@ -1029,8 +1020,6 @@ const traceHighlights = (table, arrows, patternLength, wordLength) => {
1029
1020
  const gridSize = 128;
1030
1021
  const table = createTable(gridSize);
1031
1022
  const arrows = createTable(gridSize);
1032
- // @ts-ignore
1033
- createTable(gridSize);
1034
1023
  const filterCompletionItem = (pattern, word) => {
1035
1024
  const patternLength = Math.min(pattern.length, gridSize - 1);
1036
1025
  const wordLength = Math.min(word.length, gridSize - 1);
@@ -1069,7 +1058,6 @@ const filterCompletionItem = (pattern, word) => {
1069
1058
  if (!strongMatch) {
1070
1059
  return EmptyMatches;
1071
1060
  }
1072
- // printTables(pattern, 0, word, 0)
1073
1061
  const highlights = traceHighlights(table, arrows, patternLength, wordLength);
1074
1062
  return highlights;
1075
1063
  };
@@ -1121,13 +1109,9 @@ const getListHeight = (itemsLength, itemHeight, maxHeight) => {
1121
1109
  return Math.min(totalHeight, maxHeight);
1122
1110
  };
1123
1111
 
1124
- const RE_WORD_START$1 = /^\w+/;
1125
- const RE_WORD_END$1 = /\w+$/;
1126
- const getWordAt = (editor, rowIndex, columnIndex) => {
1127
- const {
1128
- lines
1129
- } = editor;
1130
- const line = lines[rowIndex];
1112
+ const RE_WORD_START$1 = /^[\w\-]+/;
1113
+ const RE_WORD_END$1 = /[\w\-]+$/;
1114
+ const getWordAt$1 = (line, columnIndex) => {
1131
1115
  const before = line.slice(0, columnIndex);
1132
1116
  const matchBefore = before.match(RE_WORD_END$1);
1133
1117
  const after = line.slice(columnIndex);
@@ -1143,11 +1127,7 @@ const getWordAt = (editor, rowIndex, columnIndex) => {
1143
1127
  word
1144
1128
  };
1145
1129
  };
1146
- const getWordBefore = (editor, rowIndex, columnIndex) => {
1147
- const {
1148
- lines
1149
- } = editor;
1150
- const line = lines[rowIndex];
1130
+ const getWordBefore$1 = (line, columnIndex) => {
1151
1131
  const before = line.slice(0, columnIndex);
1152
1132
  const matchBefore = before.match(RE_WORD_END$1);
1153
1133
  if (matchBefore) {
@@ -1156,6 +1136,21 @@ const getWordBefore = (editor, rowIndex, columnIndex) => {
1156
1136
  return EmptyString;
1157
1137
  };
1158
1138
 
1139
+ const getWordAt = (editor, rowIndex, columnIndex) => {
1140
+ const {
1141
+ lines
1142
+ } = editor;
1143
+ const line = lines[rowIndex];
1144
+ return getWordAt$1(line, columnIndex);
1145
+ };
1146
+ const getWordBefore = (editor, rowIndex, columnIndex) => {
1147
+ const {
1148
+ lines
1149
+ } = editor;
1150
+ const line = lines[rowIndex];
1151
+ return getWordBefore$1(line, columnIndex);
1152
+ };
1153
+
1159
1154
  const render$2 = (oldState, newState) => {
1160
1155
  const commands = renderCompletion(oldState, newState);
1161
1156
  const wrappedCommands = [];
@@ -1225,7 +1220,7 @@ const handleEditorDeleteLeft$1 = (editor, state) => {
1225
1220
  const y$1 = y(editor, rowIndex);
1226
1221
  const wordAtOffset = getWordBefore(editor, rowIndex, columnIndex);
1227
1222
  if (!wordAtOffset) {
1228
- return state;
1223
+ return undefined;
1229
1224
  }
1230
1225
  const items = filterCompletionItems(unfilteredItems, wordAtOffset);
1231
1226
  const newMaxLineY = Math.min(items.length, 8);
@@ -1252,13 +1247,16 @@ const EditorCompletionWidget = {
1252
1247
 
1253
1248
  const Completion = 'completion';
1254
1249
 
1250
+ const modules = Object.create(null);
1251
+ const register = (id, value) => {
1252
+ modules[id] = value;
1253
+ };
1254
+ const get$7 = id => {
1255
+ return modules[id];
1256
+ };
1257
+
1255
1258
  const getModule$2 = id => {
1256
- switch (id) {
1257
- case Completion:
1258
- return EditorCompletionWidget;
1259
- default:
1260
- throw new Error('unsupported widget');
1261
- }
1259
+ return get$7(id);
1262
1260
  };
1263
1261
 
1264
1262
  const applyWidgetChange = (editor, widget, changes) => {
@@ -1285,10 +1283,13 @@ const applyWidgetChanges = (editor, changes) => {
1285
1283
  if (widgets.length === 0) {
1286
1284
  return widgets;
1287
1285
  }
1288
- const newWidgets = widgets.map(widget => {
1286
+ const newWidgets = [];
1287
+ for (const widget of widgets) {
1289
1288
  const newWidget = applyWidgetChange(editor, widget, changes);
1290
- return newWidget;
1291
- });
1289
+ if (newWidget.newState) {
1290
+ newWidgets.push(newWidget);
1291
+ }
1292
+ }
1292
1293
  return newWidgets;
1293
1294
  };
1294
1295
 
@@ -1482,8 +1483,7 @@ const positionAt = (textDocument, offset) => {
1482
1483
  };
1483
1484
 
1484
1485
  // TODO this should be in a separate scrolling module
1485
- // @ts-ignore
1486
- const setDeltaY$3 = (state, value) => {
1486
+ const setDeltaY$2 = (state, value) => {
1487
1487
  object(state);
1488
1488
  number$1(value);
1489
1489
  const {
@@ -1521,17 +1521,19 @@ const getSelectionPairs = (selections, i) => {
1521
1521
  return [first, second, third, fourth, 0];
1522
1522
  };
1523
1523
 
1524
- // TODO visible selections could also be uint16array
1525
- // [top1, left1, width1, height1, top2, left2, width2, height2...]
1526
1524
  const getTabCount = string => {
1527
1525
  let count = 0;
1528
1526
  for (const element of string) {
1529
- if (element === '\t') {
1527
+ if (element === Tab) {
1530
1528
  count++;
1531
1529
  }
1532
1530
  }
1533
1531
  return count;
1534
1532
  };
1533
+
1534
+ // TODO visible selections could also be uint16array
1535
+ // [top1, left1, width1, height1, top2, left2, width2, height2...]
1536
+
1535
1537
  const getX = (line, column, fontWeight, fontSize, fontFamily, isMonospaceFont, letterSpacing, tabSize, halfCursorWidth, width, averageCharWidth, difference = 0) => {
1536
1538
  if (!line) {
1537
1539
  return 0;
@@ -1643,6 +1645,9 @@ const push = (selections, startRowIndex, startColumnIndex, endRowIndex, endColum
1643
1645
  newSelections[oldLength + 4] = endColumnIndex;
1644
1646
  return newSelections;
1645
1647
  };
1648
+
1649
+ // TODO maybe only accept sorted selection edits in the first place
1650
+
1646
1651
  const emptyCursors = [];
1647
1652
  const getCursorArray = (visibleCursors, isFocused) => {
1648
1653
  if (!isFocused) {
@@ -1808,9 +1813,9 @@ const applyEdit$1 = (editor, changes) => {
1808
1813
 
1809
1814
  // TODO
1810
1815
  const setDeltaYFixedValue$1 = (editor, value) => {
1811
- return setDeltaY$3(editor, value);
1816
+ return setDeltaY$2(editor, value);
1812
1817
  };
1813
- const setDeltaY$2 = (editor, value) => {
1818
+ const setDeltaY$1 = (editor, value) => {
1814
1819
  return setDeltaYFixedValue$1(editor, editor.deltaY + value);
1815
1820
  };
1816
1821
  const isAutoClosingChange = change => {
@@ -2018,34 +2023,6 @@ const set$6 = (id, oldEditor, newEditor) => {
2018
2023
  };
2019
2024
  };
2020
2025
 
2021
- // TODO this should be in a separate scrolling module
2022
- const setDeltaY$1 = (state, value) => {
2023
- object(state);
2024
- number$1(value);
2025
- const {
2026
- finalDeltaY,
2027
- deltaY,
2028
- numberOfVisibleLines,
2029
- height,
2030
- scrollBarHeight,
2031
- itemHeight
2032
- } = state;
2033
- const newDeltaY = clamp(value, 0, finalDeltaY);
2034
- if (deltaY === newDeltaY) {
2035
- return state;
2036
- }
2037
- const newMinLineY = Math.floor(newDeltaY / itemHeight);
2038
- const newMaxLineY = newMinLineY + numberOfVisibleLines;
2039
- const scrollBarY = getScrollBarY(newDeltaY, finalDeltaY, height, scrollBarHeight);
2040
- return {
2041
- ...state,
2042
- minLineY: newMinLineY,
2043
- maxLineY: newMaxLineY,
2044
- deltaY: newDeltaY,
2045
- scrollBarY
2046
- };
2047
- };
2048
-
2049
2026
  const Two = '2.0';
2050
2027
  class AssertionError extends Error {
2051
2028
  constructor(message) {
@@ -2160,7 +2137,7 @@ class JsonRpcError extends Error {
2160
2137
  this.name = 'JsonRpcError';
2161
2138
  }
2162
2139
  }
2163
- const NewLine$2 = '\n';
2140
+ const NewLine$3 = '\n';
2164
2141
  const DomException = 'DOMException';
2165
2142
  const ReferenceError$1 = 'ReferenceError';
2166
2143
  const SyntaxError$1 = 'SyntaxError';
@@ -2208,20 +2185,20 @@ const constructError = (message, type, name) => {
2208
2185
  return new ErrorConstructor(message);
2209
2186
  };
2210
2187
  const getNewLineIndex$2 = (string, startIndex = undefined) => {
2211
- return string.indexOf(NewLine$2, startIndex);
2188
+ return string.indexOf(NewLine$3, startIndex);
2212
2189
  };
2213
2190
  const joinLines$1 = lines => {
2214
- return lines.join(NewLine$2);
2191
+ return lines.join(NewLine$3);
2215
2192
  };
2216
2193
  const MethodNotFound = -32601;
2217
2194
  const Custom = -32001;
2218
2195
  const splitLines$1 = lines => {
2219
- return lines.split(NewLine$2);
2196
+ return lines.split(NewLine$3);
2220
2197
  };
2221
2198
  const getParentStack = error => {
2222
2199
  let parentStack = error.stack || error.data || error.message || '';
2223
2200
  if (parentStack.startsWith(' at')) {
2224
- parentStack = error.message + NewLine$2 + parentStack;
2201
+ parentStack = error.message + NewLine$3 + parentStack;
2225
2202
  }
2226
2203
  return parentStack;
2227
2204
  };
@@ -2233,14 +2210,14 @@ const restoreJsonRpcError = error => {
2233
2210
  if (error && error.code && error.code === MethodNotFound) {
2234
2211
  const restoredError = new JsonRpcError(error.message);
2235
2212
  const parentStack = getParentStack(error);
2236
- restoredError.stack = parentStack + NewLine$2 + currentStack;
2213
+ restoredError.stack = parentStack + NewLine$3 + currentStack;
2237
2214
  return restoredError;
2238
2215
  }
2239
2216
  if (error && error.message) {
2240
2217
  const restoredError = constructError(error.message, error.type, error.name);
2241
2218
  if (error.data) {
2242
2219
  if (error.data.stack && error.data.type && error.message) {
2243
- restoredError.stack = error.data.type + ': ' + error.message + NewLine$2 + error.data.stack + NewLine$2 + currentStack;
2220
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine$3 + error.data.stack + NewLine$3 + currentStack;
2244
2221
  } else if (error.data.stack) {
2245
2222
  restoredError.stack = error.data.stack;
2246
2223
  }
@@ -2856,7 +2833,7 @@ const createEditor = async ({
2856
2833
  // TODO avoid creating intermediate editors here
2857
2834
  const newEditor1 = setBounds(editor, x, y, width, height, 9);
2858
2835
  const newEditor2 = setText(newEditor1, content);
2859
- const newEditor3 = setDeltaY$1(newEditor2, 0);
2836
+ const newEditor3 = setDeltaY$2(newEditor2, 0);
2860
2837
  const newEditor4 = {
2861
2838
  ...newEditor3,
2862
2839
  focused: true
@@ -3084,7 +3061,7 @@ const cancelSelection = editor => {
3084
3061
  };
3085
3062
 
3086
3063
  const isCompletionWidget = widget => {
3087
- return widget.id === 'completion';
3064
+ return widget.id === Completion;
3088
3065
  };
3089
3066
  const closeCompletion = editor => {
3090
3067
  const {
@@ -3156,17 +3133,6 @@ const compositionEnd = (editor, data) => {
3156
3133
  return scheduleDocumentAndCursorsSelections(editor, changes);
3157
3134
  };
3158
3135
 
3159
- /**
3160
- *
3161
- * @param {string} string
3162
- * @param {number|undefined} startIndex
3163
- * @returns
3164
- */
3165
- // @ts-ignore
3166
- const getNewLineIndex$1 = (string, startIndex = undefined) => {
3167
- return string.indexOf('\n', startIndex);
3168
- };
3169
-
3170
3136
  const normalizeLine$1 = line => {
3171
3137
  if (line.startsWith('Error: ')) {
3172
3138
  return line.slice(`Error: `.length);
@@ -3176,7 +3142,17 @@ const normalizeLine$1 = line => {
3176
3142
  }
3177
3143
  return line;
3178
3144
  };
3179
-
3145
+ const getCombinedMessage$1 = (error, message) => {
3146
+ const stringifiedError = normalizeLine$1(`${error}`);
3147
+ if (message) {
3148
+ return `${message}: ${stringifiedError}`;
3149
+ }
3150
+ return stringifiedError;
3151
+ };
3152
+ const NewLine$2 = '\n';
3153
+ const getNewLineIndex$1 = (string, startIndex = undefined) => {
3154
+ return string.indexOf(NewLine$2, startIndex);
3155
+ };
3180
3156
  const mergeStacks$1 = (parent, child) => {
3181
3157
  if (!child) {
3182
3158
  return parent;
@@ -3194,28 +3170,6 @@ const mergeStacks$1 = (parent, child) => {
3194
3170
  }
3195
3171
  return child;
3196
3172
  };
3197
-
3198
- // @ts-nocheck
3199
- const stringifyError = error => {
3200
- if (error instanceof DOMException && error.message) {
3201
- return `DOMException: ${error.message}`;
3202
- }
3203
- const errorPrefixes = ['Error: ', 'VError: '];
3204
- const stringifiedError = `${error}`;
3205
- for (const errorPrefix of errorPrefixes) {
3206
- if (stringifiedError.startsWith(errorPrefix)) {
3207
- return stringifiedError.slice(errorPrefix.length);
3208
- }
3209
- }
3210
- return stringifiedError;
3211
- };
3212
- const getCombinedMessage$1 = (error, message) => {
3213
- const stringifiedError = stringifyError(error);
3214
- if (message) {
3215
- return `${message}: ${stringifiedError}`;
3216
- }
3217
- return `${stringifiedError}`;
3218
- };
3219
3173
  let VError$1 = class VError extends Error {
3220
3174
  constructor(error, message) {
3221
3175
  const combinedMessage = getCombinedMessage$1(error, message);
@@ -3225,12 +3179,16 @@ let VError$1 = class VError extends Error {
3225
3179
  this.stack = mergeStacks$1(this.stack, error.stack);
3226
3180
  }
3227
3181
  if (error.codeFrame) {
3182
+ // @ts-ignore
3228
3183
  this.codeFrame = error.codeFrame;
3229
3184
  }
3185
+ if (error.code) {
3186
+ // @ts-ignore
3187
+ this.code = error.code;
3188
+ }
3230
3189
  }
3231
3190
  };
3232
3191
 
3233
- // @ts-ignore
3234
3192
  const writeText = async text => {
3235
3193
  try {
3236
3194
  string(text);
@@ -3647,9 +3605,6 @@ const cursorSet = (editor, rowIndex, columnIndex) => {
3647
3605
  return scheduleSelections(editor, selectionEdits);
3648
3606
  };
3649
3607
 
3650
- // @ts-ignore
3651
-
3652
- // @ts-ignore
3653
3608
  const moveSelectionWithoutIntlSegmenter = (selections, i, selectionStartRow, selectionStartColumn, selectionEndRow, selectionEndColumn) => {
3654
3609
  if (selectionStartRow === 0) {
3655
3610
  moveRangeToPosition$1(selections, i, 0, 0);
@@ -3657,13 +3612,9 @@ const moveSelectionWithoutIntlSegmenter = (selections, i, selectionStartRow, sel
3657
3612
  moveRangeToPosition$1(selections, i, selectionStartRow - 1, selectionStartColumn);
3658
3613
  }
3659
3614
  };
3660
-
3661
- // @ts-ignore
3662
3615
  const getNewSelections$8 = selections => {
3663
3616
  return map(selections, moveSelectionWithoutIntlSegmenter);
3664
3617
  };
3665
-
3666
- // @ts-ignore
3667
3618
  const cursorVertical = (editor, getPosition, getEdgePosition, delta) => {
3668
3619
  // if (TextSegmenter.supported()) {
3669
3620
  // return editorCursorsVerticalWithIntlSegmenter(
@@ -3679,7 +3630,6 @@ const cursorVertical = (editor, getPosition, getEdgePosition, delta) => {
3679
3630
  return scheduleSelections(editor, newSelections);
3680
3631
  };
3681
3632
 
3682
- // @ts-ignore
3683
3633
  const cursorUp = editor => {
3684
3634
  return cursorVertical(editor);
3685
3635
  };
@@ -3707,7 +3657,6 @@ const cursorWordRight = editor => {
3707
3657
  return editorCursorHorizontalRight(editor, wordRight);
3708
3658
  };
3709
3659
 
3710
- // @ts-ignore
3711
3660
  const cutLine = async editor => {
3712
3661
  const {
3713
3662
  lines,
@@ -3719,7 +3668,6 @@ const cutLine = async editor => {
3719
3668
  const changes = replaceRange(editor, replaceRange$1, [''], EditorCut);
3720
3669
  const selectionChanges = new Uint32Array([startRowIndex, 0, startRowIndex, 0]);
3721
3670
  await writeText(line);
3722
- // @ts-ignore
3723
3671
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
3724
3672
  };
3725
3673
 
@@ -3739,7 +3687,6 @@ const cutSelectedText = async editor => {
3739
3687
  return scheduleDocumentAndCursorsSelections(editor, changes, selectionChanges);
3740
3688
  };
3741
3689
 
3742
- // @ts-ignore
3743
3690
  const cut = editor => {
3744
3691
  const {
3745
3692
  selections
@@ -4834,7 +4781,7 @@ const handleTouchEnd = (editor, touchEvent) => {
4834
4781
 
4835
4782
  // @ts-ignore
4836
4783
  const setDeltaY = (editor, deltaY) => {
4837
- return setDeltaY$2(editor, deltaY);
4784
+ return setDeltaY$1(editor, deltaY);
4838
4785
  };
4839
4786
 
4840
4787
  // @ts-ignore
@@ -5242,12 +5189,6 @@ const resolveCompletion = async (editor, name, completionItem) => {
5242
5189
 
5243
5190
  const None = 1;
5244
5191
 
5245
- const getFinalDeltaY = (height, itemHeight, itemsLength) => {
5246
- const contentHeight = itemsLength * itemHeight;
5247
- const finalDeltaY = Math.max(contentHeight - height, 0);
5248
- return finalDeltaY;
5249
- };
5250
-
5251
5192
  const getEditor = editorUid => {
5252
5193
  const instance = get$6(editorUid);
5253
5194
  if (!instance) {
@@ -5259,6 +5200,12 @@ const getEditor = editorUid => {
5259
5200
  return newState;
5260
5201
  };
5261
5202
 
5203
+ const getFinalDeltaY = (height, itemHeight, itemsLength) => {
5204
+ const contentHeight = itemsLength * itemHeight;
5205
+ const finalDeltaY = Math.max(contentHeight - height, 0);
5206
+ return finalDeltaY;
5207
+ };
5208
+
5262
5209
  const RE_WORD = /[\w\-]+$/;
5263
5210
  const getWordAtOffset = editor => {
5264
5211
  const {
@@ -5399,14 +5346,26 @@ const advance = (state, word) => {
5399
5346
  };
5400
5347
  };
5401
5348
 
5349
+ const hasWidget = (widgets, id) => {
5350
+ for (const widget of widgets) {
5351
+ if (widget.id === id) {
5352
+ return true;
5353
+ }
5354
+ }
5355
+ return false;
5356
+ };
5357
+
5402
5358
  const openCompletion = async editor => {
5403
5359
  const {
5404
5360
  widgets,
5405
5361
  uid
5406
5362
  } = editor;
5363
+ if (hasWidget(widgets, Completion)) {
5364
+ return editor;
5365
+ }
5407
5366
  const completionUid = Math.random();
5408
5367
  const completionWidget = {
5409
- id: 'completion',
5368
+ id: Completion,
5410
5369
  oldState: {
5411
5370
  items: [],
5412
5371
  itemHeight: 20,
@@ -6377,7 +6336,6 @@ const showSourceActions = async editor => {
6377
6336
  return editor;
6378
6337
  };
6379
6338
 
6380
- // @ts-ignore
6381
6339
  const compareString = (a, b) => {
6382
6340
  return a.localeCompare(b);
6383
6341
  };
@@ -7162,7 +7120,7 @@ const editorUnindent = editor => {
7162
7120
  // editor.lines //?
7163
7121
 
7164
7122
  const isCompletion$2 = widget => {
7165
- return widget.id === 'completion';
7123
+ return widget.id === Completion;
7166
7124
  };
7167
7125
  const getCompletionState = editor => {
7168
7126
  const {
@@ -7173,7 +7131,7 @@ const getCompletionState = editor => {
7173
7131
  };
7174
7132
 
7175
7133
  const isCompletion$1 = widget => {
7176
- return widget.id === 'completion';
7134
+ return widget.id === Completion;
7177
7135
  };
7178
7136
  const focusIndex$1 = (editor, index) => {
7179
7137
  const child = getCompletionState(editor);
@@ -7236,7 +7194,7 @@ const getEdits = async (editor, completionItem) => {
7236
7194
  return changes;
7237
7195
  };
7238
7196
  const isCompletion = widget => {
7239
- return widget.id === 'completion';
7197
+ return widget.id === Completion;
7240
7198
  };
7241
7199
  const select = async (editor, completionItem) => {
7242
7200
  const changes = await getEdits(editor, completionItem);
@@ -9381,6 +9339,7 @@ const listen$1 = async ({
9381
9339
 
9382
9340
  const listen = async () => {
9383
9341
  registerCommands(commandMap);
9342
+ register(Completion, EditorCompletionWidget);
9384
9343
  const ipc = await listen$1({
9385
9344
  method: Auto()
9386
9345
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/editor-worker",
3
- "version": "2.2.0",
3
+ "version": "2.3.0",
4
4
  "description": "",
5
5
  "main": "dist/testWorkerMain.js",
6
6
  "type": "module",