@lvce-editor/text-search-worker 5.18.0 → 5.19.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.
@@ -596,7 +596,7 @@ const create$4$1 = (method, params) => {
596
596
  };
597
597
  };
598
598
  const callbacks = Object.create(null);
599
- const set$4 = (id, fn) => {
599
+ const set$5 = (id, fn) => {
600
600
  callbacks[id] = fn;
601
601
  };
602
602
  const get$3 = id => {
@@ -615,7 +615,7 @@ const registerPromise = () => {
615
615
  resolve,
616
616
  promise
617
617
  } = Promise.withResolvers();
618
- set$4(id, resolve);
618
+ set$5(id, resolve);
619
619
  return {
620
620
  id,
621
621
  promise
@@ -956,11 +956,11 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
956
956
  const responseMessage = await promise;
957
957
  return unwrapJsonRpcResult(responseMessage);
958
958
  };
959
- const send = (transport, method, ...params) => {
959
+ const send$1 = (transport, method, ...params) => {
960
960
  const message = create$4$1(method, params);
961
961
  transport.send(message);
962
962
  };
963
- const invoke$3 = (ipc, method, ...params) => {
963
+ const invoke$4 = (ipc, method, ...params) => {
964
964
  return invokeHelper(ipc, method, params, false);
965
965
  };
966
966
  const invokeAndTransfer$1 = (ipc, method, ...params) => {
@@ -996,10 +996,10 @@ const createRpc = ipc => {
996
996
  * @deprecated
997
997
  */
998
998
  send(method, ...params) {
999
- send(ipc, method, ...params);
999
+ send$1(ipc, method, ...params);
1000
1000
  },
1001
1001
  invoke(method, ...params) {
1002
- return invoke$3(ipc, method, ...params);
1002
+ return invoke$4(ipc, method, ...params);
1003
1003
  },
1004
1004
  invokeAndTransfer(method, ...params) {
1005
1005
  return invokeAndTransfer$1(ipc, method, ...params);
@@ -1340,6 +1340,7 @@ const Remote = 3;
1340
1340
  const DebugWorker = 55;
1341
1341
  const RendererWorker$1 = 1;
1342
1342
  const SearchProcess = 77;
1343
+ const IconThemeWorker = 7009;
1343
1344
 
1344
1345
  const FocusElementByName = 'Viewlet.focusElementByName';
1345
1346
  const SetDom2 = 'Viewlet.setDom2';
@@ -1661,7 +1662,7 @@ const collapseDetails = state => {
1661
1662
  };
1662
1663
 
1663
1664
  const rpcs = Object.create(null);
1664
- const set$3 = (id, rpc) => {
1665
+ const set$4 = (id, rpc) => {
1665
1666
  rpcs[id] = rpc;
1666
1667
  };
1667
1668
  const get$2 = id => {
@@ -1683,7 +1684,7 @@ const create$2 = rpcId => {
1683
1684
  return rpc.invokeAndTransfer(method, ...params);
1684
1685
  },
1685
1686
  set(rpc) {
1686
- set$3(rpcId, rpc);
1687
+ set$4(rpcId, rpc);
1687
1688
  },
1688
1689
  async dispose() {
1689
1690
  const rpc = get$2(rpcId);
@@ -1692,6 +1693,14 @@ const create$2 = rpcId => {
1692
1693
  };
1693
1694
  };
1694
1695
 
1696
+ const {
1697
+ invoke: invoke$3,
1698
+ set: set$3} = create$2(IconThemeWorker);
1699
+ const getIcons$1 = async iconRequests => {
1700
+ // @ts-ignore
1701
+ return invoke$3('IconTheme.getIcons', iconRequests);
1702
+ };
1703
+
1695
1704
  const {
1696
1705
  invoke: invoke$2,
1697
1706
  invokeAndTransfer,
@@ -1842,7 +1851,7 @@ const handleDebugResumed = async params => {
1842
1851
  const openWidget = async name => {
1843
1852
  await invoke$2('Viewlet.openWidget', name);
1844
1853
  };
1845
- const getIcons$1 = async requests => {
1854
+ const getIcons = async requests => {
1846
1855
  const icons = await invoke$2('IconTheme.getIcons', requests);
1847
1856
  return icons;
1848
1857
  };
@@ -1989,7 +1998,7 @@ const RendererWorker = {
1989
1998
  getFilePathElectron,
1990
1999
  getFolderIcon,
1991
2000
  getFolderSize,
1992
- getIcons: getIcons$1,
2001
+ getIcons,
1993
2002
  getKeyBindings: getKeyBindings$1,
1994
2003
  getLogsDir,
1995
2004
  getMarkdownDom,
@@ -2052,7 +2061,7 @@ const createLazyRpc = rpcId => {
2052
2061
  let factory;
2053
2062
  const createRpc = async () => {
2054
2063
  const rpc = await factory();
2055
- set$3(rpcId, rpc);
2064
+ set$4(rpcId, rpc);
2056
2065
  };
2057
2066
  const ensureRpc = async () => {
2058
2067
  if (!rpcPromise) {
@@ -2078,9 +2087,7 @@ const {
2078
2087
  sendMessagePortToSearchProcess,
2079
2088
  set: set$1,
2080
2089
  showContextMenu,
2081
- writeClipBoardText,
2082
- getIcons
2083
- } = RendererWorker;
2090
+ writeClipBoardText} = RendererWorker;
2084
2091
 
2085
2092
  const copy = async state => {
2086
2093
  const {
@@ -2195,7 +2202,8 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
2195
2202
  useFileIcons: true,
2196
2203
  limitHit: false,
2197
2204
  limitHitWarning: '',
2198
- limit: 20_000
2205
+ limit: 20_000,
2206
+ fileIconCache: {}
2199
2207
  };
2200
2208
  set(uid, state, state);
2201
2209
  return state;
@@ -2883,29 +2891,100 @@ const handleUpdateError = async (state, update, error) => {
2883
2891
  };
2884
2892
  };
2885
2893
 
2894
+ const getIconsCached = (dirents, fileIconCache) => {
2895
+ return dirents.map(dirent => fileIconCache[dirent]);
2896
+ };
2897
+
2886
2898
  const getFileName$1 = text => {
2899
+ // TODO make api stricter so that results always have the same shape
2887
2900
  if (text.startsWith('./')) {
2888
2901
  return text.slice(2);
2889
2902
  }
2890
2903
  return text;
2891
2904
  };
2892
- const getFileIcons = async matches => {
2893
- const requests = [];
2894
- for (const item of matches) {
2895
- if (item.type === File) {
2896
- const fileName = getFileName$1(item.text);
2897
- requests.push({
2898
- type: File$1,
2899
- name: fileName,
2900
- path: `/${fileName}`
2901
- });
2905
+
2906
+ const getFileName = text => {
2907
+ if (text.startsWith('./')) {
2908
+ return text.slice(2);
2909
+ }
2910
+ return text;
2911
+ };
2912
+ const getMissingDirents = (items, fileIconCache) => {
2913
+ const missingDirents = [];
2914
+ for (const item of items) {
2915
+ const uri = getFileName(item.text);
2916
+ if (!(uri in fileIconCache)) {
2917
+ missingDirents.push(item);
2902
2918
  }
2903
2919
  }
2904
- const icons = await getIcons(requests);
2905
- // TODO cache file icons
2920
+ return missingDirents;
2921
+ };
2922
+ const toIconRequest = item => {
2923
+ return {
2924
+ type: File$1,
2925
+ name: getFileName(item.text),
2926
+ path: getFileName(item.text)
2927
+ };
2928
+ };
2929
+ const getMissingIconRequests = (dirents, fileIconCache) => {
2930
+ const missingRequests = getMissingDirents(dirents, fileIconCache);
2931
+ const iconRequests = missingRequests.map(toIconRequest);
2932
+ return iconRequests;
2933
+ };
2934
+
2935
+ const Directory = 3;
2936
+ const DirectoryExpanded = 4;
2937
+
2938
+ const getSimpleIconRequestType = direntType => {
2939
+ if (direntType === Directory || direntType === DirectoryExpanded) {
2940
+ return 2;
2941
+ }
2942
+ return 1;
2943
+ };
2944
+
2945
+ const toSimpleIconRequest = request => {
2946
+ return {
2947
+ name: request.name,
2948
+ type: getSimpleIconRequestType(request.type)
2949
+ };
2950
+ };
2951
+
2952
+ const requestFileIcons = async requests => {
2953
+ if (requests.length === 0) {
2954
+ return [];
2955
+ }
2956
+ const simpleRequests = requests.map(toSimpleIconRequest);
2957
+ const icons = await getIcons$1(simpleRequests);
2906
2958
  return icons;
2907
2959
  };
2908
2960
 
2961
+ const updateIconCache = (iconCache, missingRequests, newIcons) => {
2962
+ if (missingRequests.length === 0) {
2963
+ return iconCache;
2964
+ }
2965
+ const newFileIconCache = {
2966
+ ...iconCache
2967
+ };
2968
+ for (let i = 0; i < missingRequests.length; i++) {
2969
+ const request = missingRequests[i];
2970
+ const icon = newIcons[i];
2971
+ newFileIconCache[request.path] = icon;
2972
+ }
2973
+ return newFileIconCache;
2974
+ };
2975
+
2976
+ const getFileIcons = async (items, fileIconCache) => {
2977
+ const missingRequests = getMissingIconRequests(items, fileIconCache);
2978
+ const newIcons = await requestFileIcons(missingRequests);
2979
+ const newFileIconCache = updateIconCache(fileIconCache, missingRequests, newIcons);
2980
+ const paths = items.map(item => getFileName$1(item.text));
2981
+ const icons = getIconsCached(paths, newFileIconCache);
2982
+ return {
2983
+ icons,
2984
+ newFileIconCache
2985
+ };
2986
+ };
2987
+
2909
2988
  // TODO optimize this function to return the minimum number
2910
2989
  // of visible items needed, e.g. when not scrolled 5 items with
2911
2990
  // 20px fill 100px but when scrolled 6 items are needed
@@ -2991,7 +3070,8 @@ const handleUpdateFull = async (state, update) => {
2991
3070
  excludeValue,
2992
3071
  assetDir,
2993
3072
  platform,
2994
- limit
3073
+ limit,
3074
+ fileIconCache
2995
3075
  } = partialNewState;
2996
3076
  const root = state.workspacePath;
2997
3077
  const scheme = getProtocol(root);
@@ -3028,7 +3108,10 @@ const handleUpdateFull = async (state, update) => {
3028
3108
  const maxLineY = Math.min(numberOfVisible, total);
3029
3109
  const finalDeltaY = Math.max(contentHeight - listHeight, 0);
3030
3110
  const visible = results.slice(0, maxLineY);
3031
- const icons = await getFileIcons(visible);
3111
+ const {
3112
+ icons,
3113
+ newFileIconCache
3114
+ } = await getFileIcons(visible, fileIconCache);
3032
3115
 
3033
3116
  // TODO add info message if limit was hit
3034
3117
 
@@ -3037,6 +3120,7 @@ const handleUpdateFull = async (state, update) => {
3037
3120
  ...partialNewState,
3038
3121
  deltaY: 0,
3039
3122
  fileCount,
3123
+ fileIconCache: newFileIconCache,
3040
3124
  finalDeltaY,
3041
3125
  icons,
3042
3126
  items: results,
@@ -3289,14 +3373,6 @@ const getReplacedMessage = (fileCount, replaceCount, replacement) => {
3289
3373
  return replacedManyOccurrencesInManyFiles(replaceCount, fileCount, replacement);
3290
3374
  };
3291
3375
 
3292
- const getFileName = text => {
3293
- // TODO make api stricter so that results always have the same shape
3294
- if (text.startsWith('./')) {
3295
- return text.slice(2);
3296
- }
3297
- return text;
3298
- };
3299
-
3300
3376
  const getReplaceElements = (items, workspacePath, replacement) => {
3301
3377
  let element = {
3302
3378
  uri: '',
@@ -3315,7 +3391,7 @@ const getReplaceElements = (items, workspacePath, replacement) => {
3315
3391
  } = match;
3316
3392
  if (type === File) {
3317
3393
  changes = [];
3318
- const fileName = getFileName(text);
3394
+ const fileName = getFileName$1(text);
3319
3395
  const absolutePath = `${workspacePath}/${fileName}`;
3320
3396
  element = {
3321
3397
  uri: absolutePath,
@@ -3481,10 +3557,14 @@ const handleIconThemeChange = async state => {
3481
3557
  maxLineY
3482
3558
  } = state;
3483
3559
  const visibleItems = items.slice(minLineY, maxLineY);
3484
- const icons = await getFileIcons(visibleItems);
3560
+ const {
3561
+ icons,
3562
+ newFileIconCache
3563
+ } = await getFileIcons(visibleItems, {});
3485
3564
  return {
3486
3565
  ...state,
3487
- icons
3566
+ icons,
3567
+ fileIconCache: newFileIconCache
3488
3568
  };
3489
3569
  };
3490
3570
 
@@ -3601,6 +3681,23 @@ const handleSharedInput = (state, name, value, inputSource = Script) => {
3601
3681
  return fn(state, value, inputSource);
3602
3682
  };
3603
3683
 
3684
+ const send = async port => {
3685
+ await sendMessagePortToIconThemeWorker(port, 0);
3686
+ };
3687
+ const launchIconThemeWorker = async () => {
3688
+ // TODO connect to icon theme worker
3689
+ const rpc = await TransferMessagePortRpcParent.create({
3690
+ commandMap: {},
3691
+ send
3692
+ });
3693
+ return rpc;
3694
+ };
3695
+
3696
+ const initializeIconThemeWorker = async () => {
3697
+ const rpc = await launchIconThemeWorker();
3698
+ set$3(rpc);
3699
+ };
3700
+
3604
3701
  const launchSearchProcessElectron = async () => {
3605
3702
  const rpc = await TransferMessagePortRpcParent.create({
3606
3703
  commandMap: {},
@@ -3627,8 +3724,7 @@ const setSearchProcessFactory = platform => {
3627
3724
  };
3628
3725
  const initialize = async platform => {
3629
3726
  setSearchProcessFactory(platform);
3630
-
3631
- // TODO connect to icon theme worker
3727
+ await initializeIconThemeWorker();
3632
3728
  };
3633
3729
 
3634
3730
  // TODO optimize this function to return the minimum number
@@ -3981,12 +4077,16 @@ const selectIndexFile = async (state, searchResult, index) => {
3981
4077
  items,
3982
4078
  itemHeight,
3983
4079
  headerHeight,
3984
- height
4080
+ height,
4081
+ fileIconCache
3985
4082
  } = state;
3986
4083
  const path = searchResult.text;
3987
4084
  const newCollapsedPaths = toggleCollapsedPath(collapsedPaths, path);
3988
4085
  const filteredResults = getFilteredResults(items, newCollapsedPaths);
3989
- const icons = await getFileIcons(filteredResults);
4086
+ const {
4087
+ icons,
4088
+ newFileIconCache
4089
+ } = await getFileIcons(filteredResults, fileIconCache);
3990
4090
  const total = filteredResults.length;
3991
4091
  const listHeight = height - headerHeight;
3992
4092
  const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
@@ -3994,13 +4094,14 @@ const selectIndexFile = async (state, searchResult, index) => {
3994
4094
  return {
3995
4095
  ...state,
3996
4096
  collapsedPaths: newCollapsedPaths,
3997
- listFocusedIndex: index,
4097
+ fileIconCache: newFileIconCache,
4098
+ focus: FocusSearchResults,
4099
+ focusSource: Script,
4100
+ icons,
3998
4101
  listFocused: true,
4102
+ listFocusedIndex: index,
3999
4103
  listItems: filteredResults,
4000
- maxLineY,
4001
- icons,
4002
- focus: FocusSearchResults,
4003
- focusSource: Script
4104
+ maxLineY
4004
4105
  };
4005
4106
  };
4006
4107
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "5.18.0",
3
+ "version": "5.19.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"