@lvce-editor/completion-worker 1.8.0 → 1.10.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.
@@ -1126,7 +1126,8 @@ const create = (uid, x, y, width, height, editorUid, editorLanguageId) => {
1126
1126
  unfilteredItems: [],
1127
1127
  version: 0,
1128
1128
  editorUid,
1129
- editorLanguageId
1129
+ editorLanguageId,
1130
+ maxItems: 8
1130
1131
  };
1131
1132
  set$1(uid, state, state);
1132
1133
  };
@@ -1298,6 +1299,16 @@ const resolveCompletion = async (editorUid, name, completionItem) => {
1298
1299
  }
1299
1300
  };
1300
1301
 
1302
+ const getLines = async editorUid => {
1303
+ const lines = await invoke$1('Editor.getLines2', editorUid);
1304
+ return lines;
1305
+ };
1306
+
1307
+ const getSelections = async editorUid => {
1308
+ const selections = await invoke$1('Editor.getSelections2', editorUid);
1309
+ return selections;
1310
+ };
1311
+
1301
1312
  const getSelectionPairs = (selections, i) => {
1302
1313
  const first = selections[i];
1303
1314
  const second = selections[i + 1];
@@ -1354,8 +1365,8 @@ const getEdits = async (editorUid, leadingWord, completionItem) => {
1354
1365
  const word = completionItem.label;
1355
1366
  const resolvedItem = await resolveCompletion(editorUid, word, completionItem);
1356
1367
  const inserted = resolvedItem ? resolvedItem.snippet : word;
1357
- const lines = await invoke$1('Editor.getLines2', editorUid);
1358
- const selections = await invoke$1('Editor.getSelections2', editorUid);
1368
+ const lines = await getLines(editorUid);
1369
+ const selections = await getSelections(editorUid);
1359
1370
  const [startRowIndex, startColumnIndex] = selections;
1360
1371
  const leadingWordLength = leadingWord.length;
1361
1372
  const replaceRange$1 = new Uint32Array([startRowIndex, startColumnIndex - leadingWordLength, startRowIndex, startColumnIndex]);
@@ -1630,10 +1641,12 @@ const filterCompletionItems = (completionItems, word) => {
1630
1641
  if (result.length > 0) {
1631
1642
  if (flags & Deprecated) {
1632
1643
  // TODO avoid mutation
1644
+ // @ts-ignore
1633
1645
  completionItem.matches = EmptyMatches;
1634
1646
  deprecated.push(completionItem);
1635
1647
  } else {
1636
1648
  // TODO avoid mutation
1649
+ // @ts-ignore
1637
1650
  completionItem.matches = result;
1638
1651
  filteredCompletions.push(completionItem);
1639
1652
  }
@@ -1656,6 +1669,11 @@ const getListHeight = (itemsLength, itemHeight, maxHeight) => {
1656
1669
  return Math.min(totalHeight, maxHeight);
1657
1670
  };
1658
1671
 
1672
+ const getPositionAtCursor = async parentUid => {
1673
+ const position = await invoke$1('Editor.getPositionAtCursor', parentUid);
1674
+ return position;
1675
+ };
1676
+
1659
1677
  const getWordAtOffset = async editorUid => {
1660
1678
  return invoke$1('Editor.getWordAtOffset2', editorUid);
1661
1679
  };
@@ -1665,11 +1683,13 @@ const handleEditorDeleteLeft = async state => {
1665
1683
  unfilteredItems,
1666
1684
  itemHeight,
1667
1685
  maxHeight,
1668
- editorUid
1686
+ editorUid,
1687
+ maxItems
1669
1688
  } = state;
1670
- const x = 0; // TODO
1671
- // @ts-ignore
1672
- const y = 0; // TODP
1689
+ const {
1690
+ x,
1691
+ y
1692
+ } = await getPositionAtCursor(editorUid);
1673
1693
  const wordAtOffset = await getWordAtOffset(editorUid);
1674
1694
  if (!wordAtOffset) {
1675
1695
  return {
@@ -1678,7 +1698,7 @@ const handleEditorDeleteLeft = async state => {
1678
1698
  };
1679
1699
  }
1680
1700
  const items = filterCompletionItems(unfilteredItems, wordAtOffset);
1681
- const newMaxLineY = Math.min(items.length, 8);
1701
+ const newMaxLineY = Math.min(items.length, maxItems);
1682
1702
  const height = getListHeight(items.length, itemHeight, maxHeight);
1683
1703
  return {
1684
1704
  ...state,
@@ -1691,11 +1711,6 @@ const handleEditorDeleteLeft = async state => {
1691
1711
  };
1692
1712
  };
1693
1713
 
1694
- const getPositionAtCursor = async parentUid => {
1695
- const position = await invoke$1('Editor.getPositionAtCursor', parentUid);
1696
- return position;
1697
- };
1698
-
1699
1714
  const getWordBefore = async (editorUid, rowIndex, columnIndex) => {
1700
1715
  return invoke$1('Editor.getWordBefore2', editorUid, rowIndex, columnIndex);
1701
1716
  };
@@ -2038,17 +2053,18 @@ const i18nString = (key, placeholders = emptyObject) => {
2038
2053
  return key.replaceAll(RE_PLACEHOLDER, replacer);
2039
2054
  };
2040
2055
 
2041
- const NoResults = 'No Results';
2056
+ const NoSuggestions = 'No Suggestions';
2042
2057
 
2043
- const noResults = () => {
2044
- return i18nString(NoResults);
2058
+ const noSuggestions = () => {
2059
+ return i18nString(NoSuggestions);
2045
2060
  };
2046
2061
 
2062
+ const parentNode = {
2063
+ type: Div,
2064
+ childCount: 1
2065
+ };
2047
2066
  const getNoResultsVirtualDom = () => {
2048
- return [{
2049
- type: Div,
2050
- childCount: 1
2051
- }, text(noResults())];
2067
+ return [parentNode, text(noSuggestions())];
2052
2068
  };
2053
2069
 
2054
2070
  const getCompletionItemsVirtualDom = visibleItems => {
@@ -2234,7 +2250,7 @@ const commandMap = {
2234
2250
  'Completions.getCommandIds': getCommandIds,
2235
2251
  'Completions.getKeyBindings': getKeyBindings,
2236
2252
  'Completions.handleEditorDeleteLeft': wrapCommand(handleEditorDeleteLeft),
2237
- 'Completions.handleEditorType': handleEditorType,
2253
+ 'Completions.handleEditorType': wrapCommand(handleEditorType),
2238
2254
  'Completions.handleWheel': wrapCommand(handleWheel),
2239
2255
  'Completions.initialize': initialize,
2240
2256
  'Completions.loadContent': wrapCommand(loadContent),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/completion-worker",
3
- "version": "1.8.0",
3
+ "version": "1.10.0",
4
4
  "description": "Web Worker for the find widget in Lvce Editor",
5
5
  "repository": {
6
6
  "type": "git",