@lvce-editor/file-search-worker 3.6.0 → 3.8.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.
@@ -100,6 +100,12 @@ const array = value => {
100
100
  throw new AssertionError('expected value to be of type array');
101
101
  }
102
102
  };
103
+ const string = value => {
104
+ const type = getType(value);
105
+ if (type !== 'string') {
106
+ throw new AssertionError('expected value to be of type string');
107
+ }
108
+ };
103
109
 
104
110
  const isMessagePort = value => {
105
111
  return value && value instanceof MessagePort;
@@ -995,7 +1001,7 @@ const prefixIdWithExt = item => {
995
1001
  const getExtensionPicks = async () => {
996
1002
  try {
997
1003
  // TODO don't call this every time
998
- const extensionPicks = await invoke$1('ExtensionHostCommands.getCommands');
1004
+ const extensionPicks = await invoke$1('ExtensionHost.getCommands');
999
1005
  if (!extensionPicks) {
1000
1006
  return [];
1001
1007
  }
@@ -1084,6 +1090,9 @@ const execute = async (method, ...params) => {
1084
1090
  // TODO
1085
1091
  };
1086
1092
 
1093
+ const Directory$1 = 3;
1094
+ const File$2 = 7;
1095
+
1087
1096
  const RE_PROTOCOL = /^([a-z-]+):\/\//;
1088
1097
  const getProtocol = uri => {
1089
1098
  const protocolMatch = uri.match(RE_PROTOCOL);
@@ -1097,9 +1106,6 @@ const Memfs = 'memfs';
1097
1106
  const Html = 'html';
1098
1107
  const Fetch = 'fetch';
1099
1108
 
1100
- const Directory$1 = 3;
1101
- const File$2 = 7;
1102
-
1103
1109
  class FileNotFoundError extends Error {
1104
1110
  constructor(uri) {
1105
1111
  super(`File not found: ${uri}`);
@@ -1288,7 +1294,7 @@ const getFiles = () => {
1288
1294
  return state$3.files;
1289
1295
  };
1290
1296
 
1291
- const searchFile$4 = async () => {
1297
+ const searchFile$5 = async () => {
1292
1298
  const files = await getFiles();
1293
1299
  const keys = Object.keys(files);
1294
1300
  return keys;
@@ -1296,7 +1302,7 @@ const searchFile$4 = async () => {
1296
1302
 
1297
1303
  const SearchFileMemfs = {
1298
1304
  __proto__: null,
1299
- searchFile: searchFile$4
1305
+ searchFile: searchFile$5
1300
1306
  };
1301
1307
 
1302
1308
  const assetDir = '';
@@ -1326,7 +1332,7 @@ const removeLeadingSlash = path => {
1326
1332
  // TODO simplify code
1327
1333
  // 1. don't have playground prefix in fileMap json
1328
1334
  // 2. remove code here that removes the prefix
1329
- const searchFile$3 = async path => {
1335
+ const searchFile$4 = async path => {
1330
1336
  const fileList = await getJson(fileMapUrl);
1331
1337
  const result = fileList.map(removeLeadingSlash);
1332
1338
  const prefixLength = path.length - 'file:///'.length;
@@ -1339,7 +1345,7 @@ const searchFile$3 = async path => {
1339
1345
 
1340
1346
  const SearchFileFetch = {
1341
1347
  __proto__: null,
1342
- searchFile: searchFile$3
1348
+ searchFile: searchFile$4
1343
1349
  };
1344
1350
 
1345
1351
  const Directory = 'directory';
@@ -1686,7 +1692,7 @@ const searchFilesRecursively = async (all, parent, handle) => {
1686
1692
  }
1687
1693
  await Promise.all(promises);
1688
1694
  };
1689
- const searchFile$2 = async uri => {
1695
+ const searchFile$3 = async uri => {
1690
1696
  const path = uri.slice('html://'.length);
1691
1697
  const handle = await getDirectoryHandle(path);
1692
1698
  if (!handle) {
@@ -1700,7 +1706,7 @@ const searchFile$2 = async uri => {
1700
1706
 
1701
1707
  const SearchFileHtml = {
1702
1708
  __proto__: null,
1703
- searchFile: searchFile$2
1709
+ searchFile: searchFile$3
1704
1710
  };
1705
1711
 
1706
1712
  const emptyMatches = [];
@@ -1871,18 +1877,34 @@ const filterQuickPickItem = (pattern, word) => {
1871
1877
  return matches;
1872
1878
  };
1873
1879
 
1874
- const getBaseName = path => {
1880
+ // TODO this should be in FileSystem module
1881
+ const pathBaseName = path => {
1875
1882
  return path.slice(path.lastIndexOf('/') + 1);
1876
1883
  };
1877
1884
 
1878
- const filterQuickPickItems = (items, value) => {
1885
+ // TODO this should be in FileSystem module
1886
+ const pathDirName = path => {
1887
+ const pathSeparator = '/';
1888
+ const index = path.lastIndexOf(pathSeparator);
1889
+ if (index === -1) {
1890
+ return '';
1891
+ }
1892
+ return path.slice(0, index);
1893
+ };
1894
+
1895
+ const filterQuickPickItems = (items, value, provider) => {
1879
1896
  if (!value) {
1880
1897
  return items.map(convertToPick);
1881
1898
  }
1882
1899
  const results = [];
1883
1900
  for (const item of items) {
1884
- const baseName = getBaseName(item);
1885
- const matches = filterQuickPickItem(value, baseName);
1901
+ let filterValue = '';
1902
+ if (provider) {
1903
+ filterValue = provider.getPickLabel(item);
1904
+ } else {
1905
+ filterValue = pathBaseName(item);
1906
+ }
1907
+ const matches = filterQuickPickItem(value, filterValue);
1886
1908
  if (matches.length > 0) {
1887
1909
  results.push({
1888
1910
  pick: item,
@@ -1911,7 +1933,7 @@ const splitLines = lines => {
1911
1933
 
1912
1934
  // TODO create direct connection from electron to file search worker using message ports
1913
1935
 
1914
- const searchFile$1 = async (path, value, prepare) => {
1936
+ const searchFile$2 = async (path, value, prepare) => {
1915
1937
  const ripGrepArgs = getFileSearchRipGrepArgs();
1916
1938
  const options = {
1917
1939
  ripGrepArgs,
@@ -1929,7 +1951,7 @@ const searchFile$1 = async (path, value, prepare) => {
1929
1951
 
1930
1952
  const SearchFileRipGrep = {
1931
1953
  __proto__: null,
1932
- searchFile: searchFile$1
1954
+ searchFile: searchFile$2
1933
1955
  };
1934
1956
 
1935
1957
  const getModule = protocol => {
@@ -1944,7 +1966,8 @@ const getModule = protocol => {
1944
1966
  return SearchFileRipGrep;
1945
1967
  }
1946
1968
  };
1947
- const searchFile = async (path, value, prepare, assetDir) => {
1969
+
1970
+ const searchFile$1 = async (path, value, prepare, assetDir) => {
1948
1971
  const protocol = getProtocol(path);
1949
1972
  // TODO call different providers depending on protocol
1950
1973
  const module = await getModule(protocol);
@@ -1952,21 +1975,12 @@ const searchFile = async (path, value, prepare, assetDir) => {
1952
1975
  return result;
1953
1976
  };
1954
1977
 
1955
- // TODO this should be in FileSystem module
1956
- const pathBaseName = path => {
1957
- return path.slice(path.lastIndexOf('/') + 1);
1958
- };
1959
-
1960
- // TODO this should be in FileSystem module
1961
- const pathDirName = path => {
1962
- const pathSeparator = '/';
1963
- const index = path.lastIndexOf(pathSeparator);
1964
- if (index === -1) {
1965
- return '';
1966
- }
1967
- return path.slice(0, index);
1978
+ const searchFile = async (path, value) => {
1979
+ const prepare = true;
1980
+ // @ts-ignore
1981
+ const files = await searchFile$1(/* path */path, /* searchTerm */value, prepare);
1982
+ return files;
1968
1983
  };
1969
-
1970
1984
  const name$7 = 'file';
1971
1985
  const getPlaceholder$a = () => {
1972
1986
  return '';
@@ -1988,9 +2002,14 @@ const getNoResults$9 = () => {
1988
2002
  };
1989
2003
  };
1990
2004
  const getPicks$a = async searchValue => {
1991
- {
2005
+ // TODO cache workspace path
2006
+ const workspace = await invoke$1('Workspace.getPath');
2007
+ if (!workspace) {
1992
2008
  return [];
1993
2009
  }
2010
+ const files = await searchFile(workspace, searchValue);
2011
+ // const picks = files.map(toPick)
2012
+ return files;
1994
2013
  };
1995
2014
  const selectPick$a = async pick => {
1996
2015
  if (typeof pick === 'object') {
@@ -2030,7 +2049,17 @@ const getPickIcon$4 = () => {
2030
2049
  return '';
2031
2050
  };
2032
2051
  const getPickFileIcon$2 = pick => {
2033
- return '';
2052
+ if (typeof pick === 'object') {
2053
+ pick = pick.pick;
2054
+ }
2055
+ if (typeof pick === 'object') {
2056
+ pick = pick.pick;
2057
+ }
2058
+ const baseName = pathBaseName(pick);
2059
+ return {
2060
+ type: File$2,
2061
+ name: baseName
2062
+ };
2034
2063
  };
2035
2064
  const isPrepared$1 = () => {
2036
2065
  const workspace = '';
@@ -2697,9 +2726,29 @@ const focusIndex = async (state, index) => {
2697
2726
  };
2698
2727
  };
2699
2728
 
2729
+ const first = () => {
2730
+ return 0;
2731
+ };
2732
+ const last = items => {
2733
+ return items.length - 1;
2734
+ };
2700
2735
  const next = (items, index) => {
2701
2736
  return (index + 1) % items.length;
2702
2737
  };
2738
+ const previous = (items, index) => {
2739
+ return index === 0 ? items.length - 1 : index - 1;
2740
+ };
2741
+
2742
+ const focusFirst = state => {
2743
+ return focusIndex(state, first());
2744
+ };
2745
+
2746
+ const focusLast = state => {
2747
+ const {
2748
+ items
2749
+ } = state;
2750
+ return focusIndex(state, last(items));
2751
+ };
2703
2752
 
2704
2753
  const focusNext = state => {
2705
2754
  const {
@@ -2710,6 +2759,20 @@ const focusNext = state => {
2710
2759
  return focusIndex(state, nextIndex);
2711
2760
  };
2712
2761
 
2762
+ const focusPrevious = state => {
2763
+ const {
2764
+ items,
2765
+ focusedIndex
2766
+ } = state;
2767
+ const previousIndex = previous(items, focusedIndex);
2768
+ return focusIndex(state, previousIndex);
2769
+ };
2770
+
2771
+ const commandIds = ['handleBlur', 'handleClickAt', 'handleWheel', 'selectCurrentIndex', 'selectIndex', 'selectItem', 'focusFirst', 'focusIndex', 'focusLast', 'focusNext', 'focusPrevious', 'handleInput', 'handleBeforeInput'];
2772
+ const getCommandIds = () => {
2773
+ return commandIds;
2774
+ };
2775
+
2713
2776
  const Enter = 3;
2714
2777
  const Escape = 8;
2715
2778
  const PageUp = 10;
@@ -2748,6 +2811,182 @@ const getKeyBindings = () => {
2748
2811
  }];
2749
2812
  };
2750
2813
 
2814
+ const InsertText = 'insertText';
2815
+ const DeleteContentBackward = 'deleteContentBackward';
2816
+ const DeleteContentForward = 'deleteContentForward';
2817
+ const DeleteWordForward = 'deleteWordForward';
2818
+ const DeleteWordBackward = 'deleteWordBackward';
2819
+ const InsertLineBreak = 'insertLineBreak';
2820
+ const InsertCompositionText = 'insertCompositionText';
2821
+ const InsertFromPaste = 'insertFromPaste';
2822
+
2823
+ const getNewValueInsertText = (value, selectionStart, selectionEnd, data) => {
2824
+ if (selectionStart === value.length) {
2825
+ const newValue = value + data;
2826
+ return {
2827
+ newValue,
2828
+ cursorOffset: newValue.length
2829
+ };
2830
+ }
2831
+ const before = value.slice(0, selectionStart);
2832
+ const after = value.slice(selectionEnd);
2833
+ const newValue = before + data + after;
2834
+ return {
2835
+ newValue,
2836
+ cursorOffset: selectionStart + data.length
2837
+ };
2838
+ };
2839
+ const getNewValueDeleteContentBackward = (value, selectionStart, selectionEnd, data) => {
2840
+ const after = value.slice(selectionEnd);
2841
+ if (selectionStart === selectionEnd) {
2842
+ const before = value.slice(0, selectionStart - 1);
2843
+ const newValue = before + after;
2844
+ return {
2845
+ newValue,
2846
+ cursorOffset: before.length
2847
+ };
2848
+ }
2849
+ const before = value.slice(0, selectionStart);
2850
+ const newValue = before + after;
2851
+ return {
2852
+ newValue,
2853
+ cursorOffset: selectionStart
2854
+ };
2855
+ };
2856
+ const RE_ALPHA_NUMERIC = /[a-z\d]/i;
2857
+ const isAlphaNumeric = character => {
2858
+ return RE_ALPHA_NUMERIC.test(character);
2859
+ };
2860
+ const getNewValueDeleteWordBackward = (value, selectionStart, selectionEnd, data) => {
2861
+ const after = value.slice(selectionEnd);
2862
+ if (selectionStart === selectionEnd) {
2863
+ let startIndex = Math.max(selectionStart - 1, 0);
2864
+ while (startIndex > 0 && isAlphaNumeric(value[startIndex])) {
2865
+ startIndex--;
2866
+ }
2867
+ const before = value.slice(0, startIndex);
2868
+ const newValue = before + after;
2869
+ return {
2870
+ newValue,
2871
+ cursorOffset: before.length
2872
+ };
2873
+ }
2874
+ const before = value.slice(0, selectionStart);
2875
+ const newValue = before + after;
2876
+ return {
2877
+ newValue,
2878
+ cursorOffset: selectionStart
2879
+ };
2880
+ };
2881
+ const getNewValueDeleteContentForward = (value, selectionStart, selectionEnd, data) => {
2882
+ const before = value.slice(0, selectionStart);
2883
+ if (selectionStart === selectionEnd) {
2884
+ const after = value.slice(selectionEnd + 1);
2885
+ const newValue = before + after;
2886
+ return {
2887
+ newValue,
2888
+ cursorOffset: selectionStart
2889
+ };
2890
+ }
2891
+ const after = value.slice(selectionEnd);
2892
+ const newValue = before + after;
2893
+ return {
2894
+ newValue,
2895
+ cursorOffset: selectionStart
2896
+ };
2897
+ };
2898
+ const getNewValueDeleteWordForward = (value, selectionStart, selectionEnd, data) => {
2899
+ const before = value.slice(0, selectionStart);
2900
+ if (selectionStart === selectionEnd) {
2901
+ let startIndex = Math.min(selectionStart + 1, value.length - 1);
2902
+ while (startIndex < value.length && isAlphaNumeric(value[startIndex])) {
2903
+ startIndex++;
2904
+ }
2905
+ const after = value.slice(startIndex);
2906
+ const newValue = before + after;
2907
+ return {
2908
+ newValue,
2909
+ cursorOffset: before.length
2910
+ };
2911
+ }
2912
+ const after = value.slice(selectionEnd);
2913
+ const newValue = before + after;
2914
+ return {
2915
+ newValue,
2916
+ cursorOffset: selectionStart
2917
+ };
2918
+ };
2919
+ const getNewValueInsertCompositionText = (value, selectionStart, selectionEnd, data) => {
2920
+ return getNewValueInsertText(value, selectionStart, selectionEnd, data);
2921
+ };
2922
+ const getNewValueInsertLineBreak = (value, selectionStart, selectionEnd, data) => {
2923
+ return {
2924
+ newValue: value,
2925
+ cursorOffset: selectionEnd
2926
+ };
2927
+ };
2928
+ const getFn = inputType => {
2929
+ switch (inputType) {
2930
+ case InsertFromPaste:
2931
+ case InsertText:
2932
+ return getNewValueInsertText;
2933
+ case DeleteContentBackward:
2934
+ return getNewValueDeleteContentBackward;
2935
+ case DeleteContentForward:
2936
+ return getNewValueDeleteContentForward;
2937
+ case DeleteWordForward:
2938
+ return getNewValueDeleteWordForward;
2939
+ case DeleteWordBackward:
2940
+ return getNewValueDeleteWordBackward;
2941
+ case InsertLineBreak:
2942
+ return getNewValueInsertLineBreak;
2943
+ case InsertCompositionText:
2944
+ return getNewValueInsertCompositionText;
2945
+ default:
2946
+ throw new Error(`unsupported input type ${inputType}`);
2947
+ }
2948
+ };
2949
+ const getNewValue = (value, inputType, data, selectionStart, selectionEnd) => {
2950
+ const fn = getFn(inputType);
2951
+ return fn(value, selectionStart, selectionEnd, data);
2952
+ };
2953
+
2954
+ // TODO when user types letters -> no need to query provider again -> just filter existing results
2955
+ const handleInput = async (state, newValue, cursorOffset, inputSource = Script) => {
2956
+ if (state.value === newValue) {
2957
+ return state;
2958
+ }
2959
+ // @ts-ignore
2960
+ state.value = newValue;
2961
+ // @ts-ignore
2962
+ state.inputSource = inputSource;
2963
+ const newPicks = await state.provider.getPicks(newValue);
2964
+ const filterValue = state.provider.getFilterValue(newValue);
2965
+ const items = filterQuickPickItems(newPicks, filterValue, state.provider);
2966
+ const focusedIndex = items.length === 0 ? -1 : 0;
2967
+ return {
2968
+ ...state,
2969
+ picks: newPicks,
2970
+ items,
2971
+ focusedIndex,
2972
+ cursorOffset
2973
+ };
2974
+ };
2975
+
2976
+ const handleBeforeInput = (state, inputType, data, selectionStart, selectionEnd) => {
2977
+ string(inputType);
2978
+ number(selectionStart);
2979
+ number(selectionEnd);
2980
+ const {
2981
+ value
2982
+ } = state;
2983
+ const {
2984
+ newValue,
2985
+ cursorOffset
2986
+ } = getNewValue(value, inputType, data, selectionStart, selectionEnd);
2987
+ return handleInput(state, newValue, cursorOffset, User);
2988
+ };
2989
+
2751
2990
  const closeWidget = async id => {
2752
2991
  await invoke$1('Viewlet.closeWidget', id);
2753
2992
  };
@@ -2969,11 +3208,6 @@ const QuickPickEntriesNumber = {
2969
3208
  selectPick: selectPick$1
2970
3209
  };
2971
3210
 
2972
- // TODO support file icons
2973
- const getFolderIcon = () => {
2974
- return '';
2975
- };
2976
-
2977
3211
  const getRecentlyOpened = () => {
2978
3212
  return invoke$1(/* RecentlyOpened.getRecentlyOpened */'RecentlyOpened.getRecentlyOpened');
2979
3213
  };
@@ -3028,8 +3262,17 @@ const getPickDescription$1 = pick => {
3028
3262
  const getPickIcon = () => {
3029
3263
  return '';
3030
3264
  };
3031
- const getPickFileIcon = () => {
3032
- return getFolderIcon();
3265
+ const getPickFileIcon = pick => {
3266
+ if (typeof pick === 'object') {
3267
+ pick = pick.pick;
3268
+ }
3269
+ if (typeof pick === 'object') {
3270
+ pick = pick.pick;
3271
+ }
3272
+ return {
3273
+ type: Directory$1,
3274
+ name: pick
3275
+ };
3033
3276
  };
3034
3277
 
3035
3278
  const QuickPickEntriesOpenRecent = {
@@ -3099,7 +3342,7 @@ const loadContent = async state => {
3099
3342
  array(newPicks);
3100
3343
  // @ts-ignore
3101
3344
  const filterValue = provider.getFilterValue(value);
3102
- const items = filterQuickPickItems(state.items, filterValue);
3345
+ const items = filterQuickPickItems(newPicks, filterValue, provider);
3103
3346
  // @ts-ignore
3104
3347
  provider.getLabel();
3105
3348
  const minLineY = 0;
@@ -3129,6 +3372,87 @@ const loadQuickPickEntries = moduleId => {
3129
3372
  }
3130
3373
  };
3131
3374
 
3375
+ const getIconRequests = (items, provider) => {
3376
+ const iconRequests = [];
3377
+ for (let i = 0; i < items.length; i++) {
3378
+ const pick = items[i];
3379
+ const iconObject = provider.getPickFileIcon(pick);
3380
+ iconRequests.push({
3381
+ name: iconObject?.name,
3382
+ path: '',
3383
+ type: iconObject?.type
3384
+ });
3385
+ }
3386
+ return iconRequests;
3387
+ };
3388
+
3389
+ const requestFileIcons = async requests => {
3390
+ const promises = requests.map(request => {
3391
+ if (!request.name) {
3392
+ return '';
3393
+ }
3394
+ return request.type === File$2 ? invoke$1('IconTheme.getFileIcon', {
3395
+ name: request.name
3396
+ }) : invoke$1('IconTheme.getFolderIcon', {
3397
+ name: request.name
3398
+ });
3399
+ });
3400
+ return Promise.all(promises);
3401
+ };
3402
+
3403
+ const getPickDescription = (provider, pick) => {
3404
+ if (provider.getPickDescription) {
3405
+ return provider.getPickDescription(pick);
3406
+ }
3407
+ return '';
3408
+ };
3409
+ const getVisible = async (provider, items, minLineY, maxLineY, focusedIndex) => {
3410
+ const visibleItems = [];
3411
+ const setSize = items.length;
3412
+ const max = Math.min(setSize, maxLineY);
3413
+ const iconsRequests = getIconRequests(items.slice(minLineY, maxLineY), provider);
3414
+ const icons = await requestFileIcons(iconsRequests);
3415
+ let iconIndex = 0;
3416
+ for (let i = minLineY; i < max; i++) {
3417
+ const item = items[i];
3418
+ const pick = item.pick;
3419
+ const label = provider.getPickLabel(pick);
3420
+ const description = getPickDescription(provider, pick);
3421
+ const icon = provider.getPickIcon(pick);
3422
+ const fileIcon = icons[iconIndex++];
3423
+ visibleItems.push({
3424
+ label,
3425
+ description,
3426
+ icon,
3427
+ fileIcon,
3428
+ posInSet: i + 1,
3429
+ setSize,
3430
+ isActive: i === focusedIndex,
3431
+ matches: item.matches
3432
+ });
3433
+ }
3434
+ return visibleItems;
3435
+ };
3436
+
3437
+ const createQuickPickViewModel = async (oldState, newState) => {
3438
+ const visibleItems = await getVisible(newState.provider, newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex);
3439
+ const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
3440
+ const newFocusedIndex = newState.focusedIndex - newState.minLineY;
3441
+ const maxLineY = Math.min(newState.maxLineY, newState.items.length);
3442
+ const itemCount = maxLineY - newState.minLineY;
3443
+ const height = itemCount * newState.itemHeight;
3444
+ return {
3445
+ visibleItems,
3446
+ value: newState.value,
3447
+ cursorOffset: newState.cursorOffset,
3448
+ focused: newState.focused,
3449
+ height,
3450
+ oldFocusedIndex,
3451
+ newFocusedIndex,
3452
+ uid: newState.uid
3453
+ };
3454
+ };
3455
+
3132
3456
  const RenderItems = 1;
3133
3457
  const RenderFocus = 2;
3134
3458
  const RenderValue = 3;
@@ -3268,74 +3592,31 @@ const getQuickPickItemsVirtualDom = visibleItems => {
3268
3592
  return dom;
3269
3593
  };
3270
3594
 
3271
- const getPickDescription = (provider, pick) => {
3272
- if (provider.getPickDescription) {
3273
- return provider.getPickDescription(pick);
3274
- }
3275
- return '';
3276
- };
3277
- const getFileIcon = (provider, pick) => {
3278
- if (provider.getPickFileIcon) {
3279
- return provider.getPickFileIcon(pick);
3280
- }
3281
- return '';
3282
- };
3283
- const getVisible = (provider, items, minLineY, maxLineY, focusedIndex) => {
3284
- const visibleItems = [];
3285
- const setSize = items.length;
3286
- const max = Math.min(setSize, maxLineY);
3287
- for (let i = minLineY; i < max; i++) {
3288
- const item = items[i];
3289
- const pick = item.pick;
3290
- const label = provider.getPickLabel(pick);
3291
- const description = getPickDescription(provider, pick);
3292
- const icon = provider.getPickIcon(pick);
3293
- const fileIcon = getFileIcon(provider, pick);
3294
- visibleItems.push({
3295
- label,
3296
- description,
3297
- icon,
3298
- fileIcon,
3299
- posInSet: i + 1,
3300
- setSize,
3301
- isActive: i === focusedIndex,
3302
- matches: item.matches
3303
- });
3304
- }
3305
- return visibleItems;
3306
- };
3307
-
3308
3595
  const SetCursorOffset = 'setCursorOffset';
3309
3596
  const SetFocusedIndex = 'setFocusedIndex';
3310
3597
  const SetItemsHeight = 'setItemsHeight';
3311
3598
  const SetValue = 'setValue';
3312
3599
 
3313
- const renderValue = (oldState, newState) => {
3314
- return [/* method */SetValue, /* value */newState.value];
3600
+ const renderValue = newState => {
3601
+ return ['Viewlet.send', newState.uid, /* method */SetValue, /* value */newState.value];
3315
3602
  };
3316
- const renderCursorOffset = (oldState, newState) => {
3317
- return [/* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
3603
+ const renderCursorOffset = newState => {
3604
+ return ['Viewlet.send', newState.uid, /* method */SetCursorOffset, /* cursorOffset */newState.cursorOffset];
3318
3605
  };
3319
- const renderItems = (oldState, newState) => {
3320
- const visibleItems = getVisible(newState.provider, newState.items, newState.minLineY, newState.maxLineY, newState.focusedIndex);
3321
- const dom = getQuickPickItemsVirtualDom(visibleItems);
3322
- return [/* method */'setItemsDom', dom];
3606
+ const renderItems = newState => {
3607
+ const dom = getQuickPickItemsVirtualDom(newState.visibleItems);
3608
+ return ['Viewlet.send', newState.uid, /* method */'setItemsDom', dom];
3323
3609
  };
3324
- const renderFocusedIndex = (oldState, newState) => {
3325
- const oldFocusedIndex = oldState.focusedIndex - oldState.minLineY;
3326
- const newFocusedIndex = newState.focusedIndex - newState.minLineY;
3327
- return [/* method */SetFocusedIndex, /* oldFocusedIndex */oldFocusedIndex, /* newFocusedIndex */newFocusedIndex];
3610
+ const renderFocusedIndex = newState => {
3611
+ return ['Viewlet.send', newState.uid, /* method */SetFocusedIndex, /* oldFocusedIndex */newState.oldFocusedIndex, /* newFocusedIndex */newState.newFocusedIndex];
3328
3612
  };
3329
- const renderHeight = (oldState, newState) => {
3330
- if (newState.items.length === 0) {
3331
- return [/* method */SetItemsHeight, /* height */newState.itemHeight];
3613
+ const renderHeight = newState => {
3614
+ if (newState.height === 0) {
3615
+ return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */20];
3332
3616
  }
3333
- const maxLineY = Math.min(newState.maxLineY, newState.items.length);
3334
- const itemCount = maxLineY - newState.minLineY;
3335
- const height = itemCount * newState.itemHeight;
3336
- return [/* method */SetItemsHeight, /* height */height];
3617
+ return ['Viewlet.send', newState.uid, /* method */SetItemsHeight, /* height */newState.height];
3337
3618
  };
3338
- const renderFocus = (oldState, newState) => {
3619
+ const renderFocus = newState => {
3339
3620
  const selector = newState.focused ? '.InputBox' : '';
3340
3621
  return ['Viewlet.focusSelector', selector];
3341
3622
  };
@@ -3358,11 +3639,12 @@ const getRenderer = diffType => {
3358
3639
  }
3359
3640
  };
3360
3641
 
3361
- const applyRender = (oldState, newState, diffResult) => {
3642
+ const applyRender = async (oldState, newState, diffResult) => {
3362
3643
  const commands = [];
3644
+ const viewModel = await createQuickPickViewModel(oldState, newState);
3363
3645
  for (const item of diffResult) {
3364
3646
  const fn = getRenderer(item);
3365
- commands.push(fn(oldState, newState));
3647
+ commands.push(fn(viewModel));
3366
3648
  }
3367
3649
  return commands;
3368
3650
  };
@@ -3434,7 +3716,7 @@ const diff = (oldState, newState) => {
3434
3716
  return diffResult;
3435
3717
  };
3436
3718
 
3437
- const doRender = uid => {
3719
+ const doRender = async uid => {
3438
3720
  const {
3439
3721
  oldState,
3440
3722
  newState
@@ -3443,6 +3725,74 @@ const doRender = uid => {
3443
3725
  return applyRender(oldState, newState, diffResult);
3444
3726
  };
3445
3727
 
3728
+ const getPick = (items, index) => {
3729
+ array(items);
3730
+ number(index);
3731
+ // if (index < state.recentPicks.length) {
3732
+ // return state.recentPicks[index]
3733
+ // }
3734
+ // index -= state.recentPicks.length
3735
+ if (index < items.length) {
3736
+ return items[index].pick;
3737
+ }
3738
+ console.warn('no pick matching index', index);
3739
+ };
3740
+
3741
+ const selectIndex = async (state, index, button = /* left */0) => {
3742
+ const {
3743
+ minLineY,
3744
+ provider,
3745
+ items
3746
+ } = state;
3747
+ const actualIndex = index + minLineY;
3748
+ const pick = getPick(items, actualIndex);
3749
+ const selectPickResult = await provider.selectPick(pick, actualIndex, button);
3750
+ object(selectPickResult);
3751
+ string(selectPickResult.command);
3752
+ const {
3753
+ command
3754
+ } = selectPickResult;
3755
+ switch (command) {
3756
+ case Hide:
3757
+ await closeWidget(state.uid);
3758
+ return state;
3759
+ default:
3760
+ return state;
3761
+ }
3762
+
3763
+ // TODO recent picks should be per provider
3764
+ // if (!state.recentPickIds.has(pick.id)) {
3765
+ // state.recentPicks.unshift(pick)
3766
+ // state.recentPickIds.add(pick.id)
3767
+ // }
3768
+ // if (state.recentPicks.length > RECENT_PICKS_MAX_SIZE) {
3769
+ // const last = state.recentPicks.pop()
3770
+ // state.recentPickIds.delete(last.id)
3771
+ // }
3772
+ };
3773
+
3774
+ const selectCurrentIndex = state => {
3775
+ return selectIndex(state, state.focusedIndex);
3776
+ };
3777
+
3778
+ const findLabelIndex = (items, label) => {
3779
+ for (let i = 0; i < items.length; i++) {
3780
+ if (items[i].pick.label === label) {
3781
+ return i;
3782
+ }
3783
+ }
3784
+ return -1;
3785
+ };
3786
+
3787
+ const selectItem = async (state, label) => {
3788
+ string(label);
3789
+ const index = findLabelIndex(state.items, label);
3790
+ if (index === -1) {
3791
+ return state;
3792
+ }
3793
+ return selectIndex(state, index);
3794
+ };
3795
+
3446
3796
  const wrapCommand = fn => {
3447
3797
  const wrapped = async (uid, ...args) => {
3448
3798
  const {
@@ -3455,23 +3805,31 @@ const wrapCommand = fn => {
3455
3805
  };
3456
3806
 
3457
3807
  const commandMap = {
3458
- 'QuickPick.create': create,
3459
3808
  'QuickPick.create2': create$1,
3809
+ 'QuickPick.focusFirst': wrapCommand(focusFirst),
3460
3810
  'QuickPick.focusIndex': wrapCommand(focusIndex),
3811
+ 'QuickPick.focusLast': wrapCommand(focusLast),
3461
3812
  'QuickPick.focusNext': wrapCommand(focusNext),
3813
+ 'QuickPick.focusPrevious': wrapCommand(focusPrevious),
3814
+ 'QuickPick.getCommandIds': getCommandIds,
3462
3815
  'QuickPick.getKeyBindings': getKeyBindings,
3816
+ 'QuickPick.handleBeforeInput': wrapCommand(handleBeforeInput),
3463
3817
  'QuickPick.handleBlur': wrapCommand(handleBlur),
3464
3818
  'QuickPick.handleWheel': wrapCommand(handleWheel),
3465
- 'QuickPick.setDeltaY': wrapCommand(setDeltaY),
3466
3819
  'QuickPick.loadContent': wrapCommand(loadContent),
3467
3820
  'QuickPick.loadEntries2': load,
3468
3821
  'QuickPick.render': doRender,
3822
+ 'QuickPick.selectCurrentIndex': wrapCommand(selectCurrentIndex),
3823
+ 'QuickPick.selectIndex': wrapCommand(selectIndex),
3824
+ 'QuickPick.selectItem': wrapCommand(selectItem),
3825
+ 'QuickPick.setDeltaY': wrapCommand(setDeltaY),
3469
3826
  'SearchFile.filter': filterQuickPickItems,
3470
- 'SearchFile.searchFile': searchFile,
3471
- 'SearchFile.searchFileWithFetch': searchFile$3,
3472
- 'SearchFile.searchFileWithHtml': searchFile$2,
3473
- 'SearchFile.searchFileWithRipGrep': searchFile$1,
3827
+ 'SearchFile.searchFile': searchFile$1,
3828
+ 'SearchFile.searchFileWithFetch': searchFile$4,
3829
+ 'SearchFile.searchFileWithHtml': searchFile$3,
3830
+ 'SearchFile.searchFileWithRipGrep': searchFile$2,
3474
3831
  // deprecated
3832
+ 'QuickPick.create': create,
3475
3833
  'QuickPick.loadEntries': loadQuickPickEntries,
3476
3834
  'FileSystemFetch.chmod': chmod,
3477
3835
  'FileSystemFetch.getBlob': getBlob,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/file-search-worker",
3
- "version": "3.6.0",
3
+ "version": "3.8.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "text-search"