@lvce-editor/text-search-worker 5.17.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';
@@ -1641,6 +1642,9 @@ const MatchCase$2 = 1 << 4; // 16
1641
1642
  const DetailsExpanded = 1 << 5; // 32
1642
1643
  const OpenEditors = 1 << 6; // 64
1643
1644
  const UseIgnoreFiles = 1 << 7; // 128
1645
+ const hasReplaceExpanded = flags => {
1646
+ return (flags & ReplaceExpanded) === ReplaceExpanded;
1647
+ };
1644
1648
  const hasDetailsExpanded = flags => {
1645
1649
  return (flags & DetailsExpanded) === DetailsExpanded;
1646
1650
  };
@@ -1658,7 +1662,7 @@ const collapseDetails = state => {
1658
1662
  };
1659
1663
 
1660
1664
  const rpcs = Object.create(null);
1661
- const set$3 = (id, rpc) => {
1665
+ const set$4 = (id, rpc) => {
1662
1666
  rpcs[id] = rpc;
1663
1667
  };
1664
1668
  const get$2 = id => {
@@ -1680,7 +1684,7 @@ const create$2 = rpcId => {
1680
1684
  return rpc.invokeAndTransfer(method, ...params);
1681
1685
  },
1682
1686
  set(rpc) {
1683
- set$3(rpcId, rpc);
1687
+ set$4(rpcId, rpc);
1684
1688
  },
1685
1689
  async dispose() {
1686
1690
  const rpc = get$2(rpcId);
@@ -1689,6 +1693,14 @@ const create$2 = rpcId => {
1689
1693
  };
1690
1694
  };
1691
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
+
1692
1704
  const {
1693
1705
  invoke: invoke$2,
1694
1706
  invokeAndTransfer,
@@ -1839,7 +1851,7 @@ const handleDebugResumed = async params => {
1839
1851
  const openWidget = async name => {
1840
1852
  await invoke$2('Viewlet.openWidget', name);
1841
1853
  };
1842
- const getIcons$1 = async requests => {
1854
+ const getIcons = async requests => {
1843
1855
  const icons = await invoke$2('IconTheme.getIcons', requests);
1844
1856
  return icons;
1845
1857
  };
@@ -1986,7 +1998,7 @@ const RendererWorker = {
1986
1998
  getFilePathElectron,
1987
1999
  getFolderIcon,
1988
2000
  getFolderSize,
1989
- getIcons: getIcons$1,
2001
+ getIcons,
1990
2002
  getKeyBindings: getKeyBindings$1,
1991
2003
  getLogsDir,
1992
2004
  getMarkdownDom,
@@ -2049,7 +2061,7 @@ const createLazyRpc = rpcId => {
2049
2061
  let factory;
2050
2062
  const createRpc = async () => {
2051
2063
  const rpc = await factory();
2052
- set$3(rpcId, rpc);
2064
+ set$4(rpcId, rpc);
2053
2065
  };
2054
2066
  const ensureRpc = async () => {
2055
2067
  if (!rpcPromise) {
@@ -2075,9 +2087,7 @@ const {
2075
2087
  sendMessagePortToSearchProcess,
2076
2088
  set: set$1,
2077
2089
  showContextMenu,
2078
- writeClipBoardText,
2079
- getIcons
2080
- } = RendererWorker;
2090
+ writeClipBoardText} = RendererWorker;
2081
2091
 
2082
2092
  const copy = async state => {
2083
2093
  const {
@@ -2192,7 +2202,8 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
2192
2202
  useFileIcons: true,
2193
2203
  limitHit: false,
2194
2204
  limitHitWarning: '',
2195
- limit: 20_000
2205
+ limit: 20_000,
2206
+ fileIconCache: {}
2196
2207
  };
2197
2208
  set(uid, state, state);
2198
2209
  return state;
@@ -2880,29 +2891,100 @@ const handleUpdateError = async (state, update, error) => {
2880
2891
  };
2881
2892
  };
2882
2893
 
2894
+ const getIconsCached = (dirents, fileIconCache) => {
2895
+ return dirents.map(dirent => fileIconCache[dirent]);
2896
+ };
2897
+
2883
2898
  const getFileName$1 = text => {
2899
+ // TODO make api stricter so that results always have the same shape
2884
2900
  if (text.startsWith('./')) {
2885
2901
  return text.slice(2);
2886
2902
  }
2887
2903
  return text;
2888
2904
  };
2889
- const getFileIcons = async matches => {
2890
- const requests = [];
2891
- for (const item of matches) {
2892
- if (item.type === File) {
2893
- const fileName = getFileName$1(item.text);
2894
- requests.push({
2895
- type: File$1,
2896
- name: fileName,
2897
- path: `/${fileName}`
2898
- });
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);
2899
2918
  }
2900
2919
  }
2901
- const icons = await getIcons(requests);
2902
- // 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);
2903
2958
  return icons;
2904
2959
  };
2905
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
+
2906
2988
  // TODO optimize this function to return the minimum number
2907
2989
  // of visible items needed, e.g. when not scrolled 5 items with
2908
2990
  // 20px fill 100px but when scrolled 6 items are needed
@@ -2988,7 +3070,8 @@ const handleUpdateFull = async (state, update) => {
2988
3070
  excludeValue,
2989
3071
  assetDir,
2990
3072
  platform,
2991
- limit
3073
+ limit,
3074
+ fileIconCache
2992
3075
  } = partialNewState;
2993
3076
  const root = state.workspacePath;
2994
3077
  const scheme = getProtocol(root);
@@ -3025,7 +3108,10 @@ const handleUpdateFull = async (state, update) => {
3025
3108
  const maxLineY = Math.min(numberOfVisible, total);
3026
3109
  const finalDeltaY = Math.max(contentHeight - listHeight, 0);
3027
3110
  const visible = results.slice(0, maxLineY);
3028
- const icons = await getFileIcons(visible);
3111
+ const {
3112
+ icons,
3113
+ newFileIconCache
3114
+ } = await getFileIcons(visible, fileIconCache);
3029
3115
 
3030
3116
  // TODO add info message if limit was hit
3031
3117
 
@@ -3034,6 +3120,7 @@ const handleUpdateFull = async (state, update) => {
3034
3120
  ...partialNewState,
3035
3121
  deltaY: 0,
3036
3122
  fileCount,
3123
+ fileIconCache: newFileIconCache,
3037
3124
  finalDeltaY,
3038
3125
  icons,
3039
3126
  items: results,
@@ -3286,14 +3373,6 @@ const getReplacedMessage = (fileCount, replaceCount, replacement) => {
3286
3373
  return replacedManyOccurrencesInManyFiles(replaceCount, fileCount, replacement);
3287
3374
  };
3288
3375
 
3289
- const getFileName = text => {
3290
- // TODO make api stricter so that results always have the same shape
3291
- if (text.startsWith('./')) {
3292
- return text.slice(2);
3293
- }
3294
- return text;
3295
- };
3296
-
3297
3376
  const getReplaceElements = (items, workspacePath, replacement) => {
3298
3377
  let element = {
3299
3378
  uri: '',
@@ -3312,7 +3391,7 @@ const getReplaceElements = (items, workspacePath, replacement) => {
3312
3391
  } = match;
3313
3392
  if (type === File) {
3314
3393
  changes = [];
3315
- const fileName = getFileName(text);
3394
+ const fileName = getFileName$1(text);
3316
3395
  const absolutePath = `${workspacePath}/${fileName}`;
3317
3396
  element = {
3318
3397
  uri: absolutePath,
@@ -3383,8 +3462,31 @@ const togglePreserveCase = state => {
3383
3462
  return toggleSearchFlag(state, PreserveCase$2);
3384
3463
  };
3385
3464
 
3386
- const toggleReplace = state => {
3387
- return toggleSearchFlag(state, ReplaceExpanded);
3465
+ const collapseReplace = state => {
3466
+ const {
3467
+ flags
3468
+ } = state;
3469
+ return {
3470
+ ...state,
3471
+ flags: flags & -5
3472
+ };
3473
+ };
3474
+
3475
+ const expandReplace = state => {
3476
+ const {
3477
+ flags
3478
+ } = state;
3479
+ return {
3480
+ ...state,
3481
+ flags: flags | ReplaceExpanded
3482
+ };
3483
+ };
3484
+
3485
+ const toggleReplace = async state => {
3486
+ if (hasReplaceExpanded(state.flags)) {
3487
+ return collapseReplace(state);
3488
+ }
3489
+ return expandReplace(state);
3388
3490
  };
3389
3491
 
3390
3492
  const toggleUseIgnoreFiles = state => {
@@ -3455,10 +3557,14 @@ const handleIconThemeChange = async state => {
3455
3557
  maxLineY
3456
3558
  } = state;
3457
3559
  const visibleItems = items.slice(minLineY, maxLineY);
3458
- const icons = await getFileIcons(visibleItems);
3560
+ const {
3561
+ icons,
3562
+ newFileIconCache
3563
+ } = await getFileIcons(visibleItems, {});
3459
3564
  return {
3460
3565
  ...state,
3461
- icons
3566
+ icons,
3567
+ fileIconCache: newFileIconCache
3462
3568
  };
3463
3569
  };
3464
3570
 
@@ -3575,6 +3681,23 @@ const handleSharedInput = (state, name, value, inputSource = Script) => {
3575
3681
  return fn(state, value, inputSource);
3576
3682
  };
3577
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
+
3578
3701
  const launchSearchProcessElectron = async () => {
3579
3702
  const rpc = await TransferMessagePortRpcParent.create({
3580
3703
  commandMap: {},
@@ -3601,8 +3724,7 @@ const setSearchProcessFactory = platform => {
3601
3724
  };
3602
3725
  const initialize = async platform => {
3603
3726
  setSearchProcessFactory(platform);
3604
-
3605
- // TODO connect to icon theme worker
3727
+ await initializeIconThemeWorker();
3606
3728
  };
3607
3729
 
3608
3730
  // TODO optimize this function to return the minimum number
@@ -3955,12 +4077,16 @@ const selectIndexFile = async (state, searchResult, index) => {
3955
4077
  items,
3956
4078
  itemHeight,
3957
4079
  headerHeight,
3958
- height
4080
+ height,
4081
+ fileIconCache
3959
4082
  } = state;
3960
4083
  const path = searchResult.text;
3961
4084
  const newCollapsedPaths = toggleCollapsedPath(collapsedPaths, path);
3962
4085
  const filteredResults = getFilteredResults(items, newCollapsedPaths);
3963
- const icons = await getFileIcons(filteredResults);
4086
+ const {
4087
+ icons,
4088
+ newFileIconCache
4089
+ } = await getFileIcons(filteredResults, fileIconCache);
3964
4090
  const total = filteredResults.length;
3965
4091
  const listHeight = height - headerHeight;
3966
4092
  const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
@@ -3968,13 +4094,14 @@ const selectIndexFile = async (state, searchResult, index) => {
3968
4094
  return {
3969
4095
  ...state,
3970
4096
  collapsedPaths: newCollapsedPaths,
3971
- listFocusedIndex: index,
4097
+ fileIconCache: newFileIconCache,
4098
+ focus: FocusSearchResults,
4099
+ focusSource: Script,
4100
+ icons,
3972
4101
  listFocused: true,
4102
+ listFocusedIndex: index,
3973
4103
  listItems: filteredResults,
3974
- maxLineY,
3975
- icons,
3976
- focus: FocusSearchResults,
3977
- focusSource: Script
4104
+ maxLineY
3978
4105
  };
3979
4106
  };
3980
4107
 
@@ -4417,7 +4544,7 @@ const createViewModel = state => {
4417
4544
  };
4418
4545
 
4419
4546
  const HandleClick = 1;
4420
- const HandleContextMenu = 2;
4547
+ const HandleListContextMenu = 2;
4421
4548
  const HandleHeaderContextMenu = 3;
4422
4549
  const HandleExcludeInput = 4;
4423
4550
  const HandleButtonClick = 5;
@@ -4613,7 +4740,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
4613
4740
  onInput,
4614
4741
  onFocus: HandleInputFocus,
4615
4742
  onBlur: HandleInputBlur,
4616
- onContextMenu: HandleContextMenu,
4743
+ onContextMenu: HandleListContextMenu,
4617
4744
  childCount: 0
4618
4745
  }, {
4619
4746
  type: Div,
@@ -5010,7 +5137,7 @@ const getTreeItemsVirtualDom = (visibleItems, deltaY, itemHeight) => {
5010
5137
  onClick: HandleClick,
5011
5138
  onBlur: HandleListBlur,
5012
5139
  onWheel: HandleWheel,
5013
- onContextMenu: HandleContextMenu,
5140
+ onContextMenu: HandleListContextMenu,
5014
5141
  id: TreeItems,
5015
5142
  top: `${-pixelOffset}px` // TODO use dynamic css instead
5016
5143
  }, ...visibleItems.flatMap(getSearchResultVirtualDom)];
@@ -5024,9 +5151,10 @@ const getSearchResultsVirtualDom = (visibleItems, focusOutline, scrollbarHeight,
5024
5151
  role: Tree$1,
5025
5152
  tabIndex: 0,
5026
5153
  childCount,
5027
- onBlur: HandleListBlur,
5028
- onPointerDown: HandleListPointerDown,
5029
- onFocus: HandleListFocus
5154
+ onBlur: HandleListBlur
5155
+ // TODO renable this when dom diffing is supported
5156
+ // onPointerDown: HandleListPointerDown,
5157
+ // onFocus: HandleListFocus,
5030
5158
  }, ...getTreeItemsVirtualDom(visibleItems, deltaY, itemHeight), ...getScrollBarVirtualDom(scrollbarHeight, scrollBarY, scrollBarValue)];
5031
5159
  };
5032
5160
 
@@ -5214,7 +5342,7 @@ const renderEventListeners = () => {
5214
5342
  name: HandleListBlur,
5215
5343
  params: ['handleListBlur']
5216
5344
  }, {
5217
- name: HandleContextMenu,
5345
+ name: HandleListContextMenu,
5218
5346
  params: ['handleContextMenu', Button$1, ClientX, ClientY],
5219
5347
  preventDefault: true
5220
5348
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "5.17.0",
3
+ "version": "5.19.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"