@lvce-editor/text-search-worker 5.23.0 → 5.24.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.
package/README.md CHANGED
@@ -10,7 +10,3 @@ cd text-search-worker &&
10
10
  npm ci &&
11
11
  npm test
12
12
  ```
13
-
14
- ## Gitpod
15
-
16
- [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/lvce-editor/text-search-worker)
@@ -1918,6 +1918,132 @@ const diff2 = uid => {
1918
1918
  return diffResult;
1919
1919
  };
1920
1920
 
1921
+ const getFilePath = text => {
1922
+ // TODO make api stricter so that results always have the same shape
1923
+ if (text.startsWith('./')) {
1924
+ return text.slice(2);
1925
+ }
1926
+ return text;
1927
+ };
1928
+
1929
+ const getIconsCached = (dirents, fileIconCache) => {
1930
+ return dirents.map(dirent => {
1931
+ if (dirent.type === Match$1) {
1932
+ return '';
1933
+ }
1934
+ const path = getFilePath(dirent.text);
1935
+ return fileIconCache[path];
1936
+ });
1937
+ };
1938
+
1939
+ const getFileName = path => {
1940
+ const slashIndex = path.lastIndexOf('/');
1941
+ if (slashIndex === -1) {
1942
+ return path;
1943
+ }
1944
+ return path.slice(slashIndex + 1);
1945
+ };
1946
+
1947
+ const isFile = match => {
1948
+ return match.type === File;
1949
+ };
1950
+
1951
+ const getMissingDirents = (searchResults, fileIconCache) => {
1952
+ const missingDirents = [];
1953
+ const files = searchResults.filter(isFile);
1954
+ for (const file of files) {
1955
+ const uri = getFilePath(file.text);
1956
+ if (!(uri in fileIconCache)) {
1957
+ missingDirents.push(file);
1958
+ }
1959
+ }
1960
+ return missingDirents;
1961
+ };
1962
+ const toIconRequest = item => {
1963
+ const filePath = getFilePath(item.text);
1964
+ const fileName = getFileName(filePath);
1965
+ return {
1966
+ type: File$1,
1967
+ name: fileName,
1968
+ path: filePath
1969
+ };
1970
+ };
1971
+ const getMissingIconRequests = (dirents, fileIconCache) => {
1972
+ const missingRequests = getMissingDirents(dirents, fileIconCache);
1973
+ const iconRequests = missingRequests.map(toIconRequest);
1974
+ return iconRequests;
1975
+ };
1976
+
1977
+ const Directory = 3;
1978
+ const DirectoryExpanded = 4;
1979
+
1980
+ const getSimpleIconRequestType = direntType => {
1981
+ if (direntType === Directory || direntType === DirectoryExpanded) {
1982
+ return 2;
1983
+ }
1984
+ return 1;
1985
+ };
1986
+
1987
+ const toSimpleIconRequest = request => {
1988
+ return {
1989
+ name: request.name,
1990
+ type: getSimpleIconRequestType(request.type)
1991
+ };
1992
+ };
1993
+
1994
+ const requestFileIcons = async requests => {
1995
+ if (requests.length === 0) {
1996
+ return [];
1997
+ }
1998
+ const simpleRequests = requests.map(toSimpleIconRequest);
1999
+ const icons = await getIcons(simpleRequests);
2000
+ return icons;
2001
+ };
2002
+
2003
+ const updateIconCache = (iconCache, missingRequests, newIcons) => {
2004
+ if (missingRequests.length === 0) {
2005
+ return iconCache;
2006
+ }
2007
+ const newFileIconCache = {
2008
+ ...iconCache
2009
+ };
2010
+ for (let i = 0; i < missingRequests.length; i++) {
2011
+ const request = missingRequests[i];
2012
+ const icon = newIcons[i];
2013
+ newFileIconCache[request.path] = icon;
2014
+ }
2015
+ return newFileIconCache;
2016
+ };
2017
+
2018
+ const getFileIcons = async (items, fileIconCache) => {
2019
+ const missingRequests = getMissingIconRequests(items, fileIconCache);
2020
+ const newIcons = await requestFileIcons(missingRequests);
2021
+ const newFileIconCache = updateIconCache(fileIconCache, missingRequests, newIcons);
2022
+ const icons = getIconsCached(items, newFileIconCache);
2023
+ return {
2024
+ icons,
2025
+ newFileIconCache
2026
+ };
2027
+ };
2028
+
2029
+ const getNewMinMax = (newItemsLength, minLineY, maxLineY, deltaY, itemHeight) => {
2030
+ if (maxLineY > newItemsLength) {
2031
+ const diff = maxLineY - minLineY;
2032
+ const newMinLineY = Math.max(newItemsLength - diff, 0);
2033
+ const newDeltaY = newMinLineY * itemHeight;
2034
+ return {
2035
+ newDeltaY,
2036
+ newMinLineY,
2037
+ newMaxLineY: newItemsLength
2038
+ };
2039
+ }
2040
+ return {
2041
+ newDeltaY: deltaY,
2042
+ newMinLineY: minLineY,
2043
+ newMaxLineY: maxLineY
2044
+ };
2045
+ };
2046
+
1921
2047
  // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1922
2048
 
1923
2049
  const remove$1 = (array, index, deleteCount) => {
@@ -1996,6 +2122,18 @@ const removeItemFromItems = (items, index, matchCount, fileCount) => {
1996
2122
  };
1997
2123
  };
1998
2124
 
2125
+ const getScrollBarSize$1 = (size, contentSize, minimumSliderSize) => {
2126
+ if (size >= contentSize) {
2127
+ return 0;
2128
+ }
2129
+ return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
2130
+ };
2131
+ const getScrollBarOffset$1 = (delta, finalDelta, size, scrollBarSize) => {
2132
+ const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
2133
+ return scrollBarOffset;
2134
+ };
2135
+ const getScrollBarY$1 = getScrollBarOffset$1;
2136
+
1999
2137
  const emptyObject = {};
2000
2138
  const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
2001
2139
  const i18nString = (key, placeholders = emptyObject) => {
@@ -2206,27 +2344,13 @@ const getStatusMessage = (resultCount, fileResultCount) => {
2206
2344
  return manyResultsInManyFiles(resultCount, fileResultCount);
2207
2345
  };
2208
2346
 
2209
- const getNewMinMax = (newItemsLength, minLineY, maxLineY, deltaY, itemHeight) => {
2210
- if (maxLineY > newItemsLength) {
2211
- const diff = maxLineY - minLineY;
2212
- const newMinLineY = Math.max(newItemsLength - diff, 0);
2213
- const newDeltaY = newMinLineY * itemHeight;
2214
- return {
2215
- newDeltaY,
2216
- newMinLineY,
2217
- newMaxLineY: newItemsLength
2218
- };
2219
- }
2220
- return {
2221
- newDeltaY: deltaY,
2222
- newMinLineY: minLineY,
2223
- newMaxLineY: maxLineY
2224
- };
2225
- };
2226
- const dismissItem = state => {
2347
+ const removeIndex = async (state, index) => {
2227
2348
  const {
2349
+ fileIconCache,
2350
+ minimumSliderSize,
2351
+ height,
2352
+ headerHeight,
2228
2353
  items,
2229
- listFocusedIndex,
2230
2354
  fileCount,
2231
2355
  matchCount,
2232
2356
  minLineY,
@@ -2234,7 +2358,7 @@ const dismissItem = state => {
2234
2358
  deltaY,
2235
2359
  itemHeight
2236
2360
  } = state;
2237
- if (listFocusedIndex === -1) {
2361
+ if (index === -1) {
2238
2362
  return state;
2239
2363
  }
2240
2364
  const {
@@ -2242,26 +2366,50 @@ const dismissItem = state => {
2242
2366
  newFocusedIndex,
2243
2367
  newMatchCount,
2244
2368
  newFileCount
2245
- } = removeItemFromItems(items, listFocusedIndex, matchCount, fileCount);
2369
+ } = removeItemFromItems(items, index, matchCount, fileCount);
2246
2370
  const message = getStatusMessage(newMatchCount, newFileCount);
2247
2371
  const {
2248
2372
  newMinLineY,
2249
2373
  newMaxLineY,
2250
2374
  newDeltaY
2251
2375
  } = getNewMinMax(newItems.length, minLineY, maxLineY, deltaY, itemHeight);
2376
+ const total = newItems.length;
2377
+ const contentHeight = total * itemHeight;
2378
+ const listHeight = height - headerHeight;
2379
+ const scrollBarHeight = getScrollBarSize$1(height, contentHeight, minimumSliderSize);
2380
+ const finalDeltaY = Math.max(contentHeight - listHeight, 0);
2381
+ const visible = newItems.slice(0, maxLineY);
2382
+ const {
2383
+ icons,
2384
+ newFileIconCache
2385
+ } = await getFileIcons(visible, fileIconCache);
2252
2386
  return {
2253
2387
  ...state,
2388
+ deltaY: newDeltaY,
2389
+ fileCount: newFileCount,
2254
2390
  items: newItems,
2391
+ listItems: newItems,
2255
2392
  listFocusedIndex: newFocusedIndex,
2256
- message,
2257
2393
  matchCount: newMatchCount,
2258
- fileCount: newFileCount,
2259
- minLineY: newMinLineY,
2260
2394
  maxLineY: newMaxLineY,
2261
- deltaY: newDeltaY
2395
+ message,
2396
+ minLineY: newMinLineY,
2397
+ icons,
2398
+ fileIconCache: newFileIconCache,
2399
+ finalDeltaY,
2400
+ scrollBarHeight
2262
2401
  };
2263
2402
  };
2264
2403
 
2404
+ const dismissItem = state => {
2405
+ const {
2406
+ listFocusedIndex,
2407
+ focusedIndex
2408
+ } = state;
2409
+ const actualIndex = listFocusedIndex === -1 ? focusedIndex : listFocusedIndex;
2410
+ return removeIndex(state, actualIndex);
2411
+ };
2412
+
2265
2413
  const expandDetails = state => {
2266
2414
  const {
2267
2415
  flags
@@ -2545,114 +2693,6 @@ const handleUpdateError = async (state, update, error) => {
2545
2693
  };
2546
2694
  };
2547
2695
 
2548
- const getFilePath = text => {
2549
- // TODO make api stricter so that results always have the same shape
2550
- if (text.startsWith('./')) {
2551
- return text.slice(2);
2552
- }
2553
- return text;
2554
- };
2555
-
2556
- const getIconsCached = (dirents, fileIconCache) => {
2557
- return dirents.map(dirent => {
2558
- if (dirent.type === Match$1) {
2559
- return '';
2560
- }
2561
- const path = getFilePath(dirent.text);
2562
- return fileIconCache[path];
2563
- });
2564
- };
2565
-
2566
- const getFileName = path => {
2567
- const slashIndex = path.lastIndexOf('/');
2568
- if (slashIndex === -1) {
2569
- return path;
2570
- }
2571
- return path.slice(slashIndex + 1);
2572
- };
2573
-
2574
- const isFile = match => {
2575
- return match.type === File;
2576
- };
2577
-
2578
- const getMissingDirents = (searchResults, fileIconCache) => {
2579
- const missingDirents = [];
2580
- const files = searchResults.filter(isFile);
2581
- for (const file of files) {
2582
- const uri = getFilePath(file.text);
2583
- if (!(uri in fileIconCache)) {
2584
- missingDirents.push(file);
2585
- }
2586
- }
2587
- return missingDirents;
2588
- };
2589
- const toIconRequest = item => {
2590
- const filePath = getFilePath(item.text);
2591
- const fileName = getFileName(filePath);
2592
- return {
2593
- type: File$1,
2594
- name: fileName,
2595
- path: filePath
2596
- };
2597
- };
2598
- const getMissingIconRequests = (dirents, fileIconCache) => {
2599
- const missingRequests = getMissingDirents(dirents, fileIconCache);
2600
- const iconRequests = missingRequests.map(toIconRequest);
2601
- return iconRequests;
2602
- };
2603
-
2604
- const Directory = 3;
2605
- const DirectoryExpanded = 4;
2606
-
2607
- const getSimpleIconRequestType = direntType => {
2608
- if (direntType === Directory || direntType === DirectoryExpanded) {
2609
- return 2;
2610
- }
2611
- return 1;
2612
- };
2613
-
2614
- const toSimpleIconRequest = request => {
2615
- return {
2616
- name: request.name,
2617
- type: getSimpleIconRequestType(request.type)
2618
- };
2619
- };
2620
-
2621
- const requestFileIcons = async requests => {
2622
- if (requests.length === 0) {
2623
- return [];
2624
- }
2625
- const simpleRequests = requests.map(toSimpleIconRequest);
2626
- const icons = await getIcons(simpleRequests);
2627
- return icons;
2628
- };
2629
-
2630
- const updateIconCache = (iconCache, missingRequests, newIcons) => {
2631
- if (missingRequests.length === 0) {
2632
- return iconCache;
2633
- }
2634
- const newFileIconCache = {
2635
- ...iconCache
2636
- };
2637
- for (let i = 0; i < missingRequests.length; i++) {
2638
- const request = missingRequests[i];
2639
- const icon = newIcons[i];
2640
- newFileIconCache[request.path] = icon;
2641
- }
2642
- return newFileIconCache;
2643
- };
2644
-
2645
- const getFileIcons = async (items, fileIconCache) => {
2646
- const missingRequests = getMissingIconRequests(items, fileIconCache);
2647
- const newIcons = await requestFileIcons(missingRequests);
2648
- const newFileIconCache = updateIconCache(fileIconCache, missingRequests, newIcons);
2649
- const icons = getIconsCached(items, newFileIconCache);
2650
- return {
2651
- icons,
2652
- newFileIconCache
2653
- };
2654
- };
2655
-
2656
2696
  // TODO optimize this function to return the minimum number
2657
2697
  // of visible items needed, e.g. when not scrolled 5 items with
2658
2698
  // 20px fill 100px but when scrolled 6 items are needed
@@ -2688,18 +2728,6 @@ const getTextSearchResultCounts = results => {
2688
2728
  };
2689
2729
  };
2690
2730
 
2691
- const getScrollBarSize$1 = (size, contentSize, minimumSliderSize) => {
2692
- if (size >= contentSize) {
2693
- return 0;
2694
- }
2695
- return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
2696
- };
2697
- const getScrollBarOffset$1 = (delta, finalDelta, size, scrollBarSize) => {
2698
- const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
2699
- return scrollBarOffset;
2700
- };
2701
- const getScrollBarY$1 = getScrollBarOffset$1;
2702
-
2703
2731
  const providers = Object.create(null);
2704
2732
  const add = providerMap => {
2705
2733
  Object.assign(providers, providerMap);
@@ -2752,7 +2780,7 @@ const handleUpdateFull = async (state, update) => {
2752
2780
  useRegularExpression: Boolean(flags & UseRegularExpression$2),
2753
2781
  exclude: excludeValue,
2754
2782
  include: includeValue,
2755
- assetDir: assetDir,
2783
+ assetDir,
2756
2784
  root,
2757
2785
  query: value,
2758
2786
  scheme,
@@ -2780,9 +2808,6 @@ const handleUpdateFull = async (state, update) => {
2780
2808
  icons,
2781
2809
  newFileIconCache
2782
2810
  } = await getFileIcons(visible, fileIconCache);
2783
-
2784
- // TODO add info message if limit was hit
2785
-
2786
2811
  const limitHitWarning = limitHit ? theResultSetOnlyContainsASubSetOfMatches() : '';
2787
2812
  return {
2788
2813
  ...partialNewState,
@@ -3740,7 +3765,7 @@ const toggleCollapsedPath = (collapsedPaths, path) => {
3740
3765
  return [...collapsedPaths, path];
3741
3766
  };
3742
3767
 
3743
- const selectIndexFile = async (state, searchResult, index, isRemove) => {
3768
+ const selectIndexFile = async (state, searchResult, index) => {
3744
3769
  const {
3745
3770
  collapsedPaths,
3746
3771
  items,
@@ -3799,7 +3824,7 @@ const getRelativePath = relativePath => {
3799
3824
  return `/${relativePath}`; // TODO support windows paths
3800
3825
  };
3801
3826
 
3802
- const selectIndexPreview = async (state, searchResult, index, isRemove) => {
3827
+ const selectIndexPreview = async (state, searchResult, index) => {
3803
3828
  const {
3804
3829
  items,
3805
3830
  workspacePath
@@ -3837,7 +3862,7 @@ const getSelectHandler = type => {
3837
3862
  }
3838
3863
  };
3839
3864
 
3840
- const selectIndex = async (state, index, isRemoveButton = false) => {
3865
+ const selectIndex = async (state, index) => {
3841
3866
  if (index === -1) {
3842
3867
  return {
3843
3868
  ...state,
@@ -3850,7 +3875,7 @@ const selectIndex = async (state, index, isRemoveButton = false) => {
3850
3875
  } = state;
3851
3876
  const searchResult = listItems[index];
3852
3877
  const fn = getSelectHandler(searchResult.type);
3853
- return fn(state, searchResult, index, isRemoveButton);
3878
+ return fn(state, searchResult, index);
3854
3879
  };
3855
3880
 
3856
3881
  const handleClickAt = async (state, eventX, eventY, name) => {
@@ -3865,7 +3890,10 @@ const handleClickAt = async (state, eventX, eventY, name) => {
3865
3890
  const topHeight = getTopHeight(flags);
3866
3891
  const index = getListIndex(eventX, eventY, x, y, deltaY, itemHeight, topHeight, listItems.length);
3867
3892
  const isRemoveButton = name === Remove;
3868
- return selectIndex(state, index, isRemoveButton);
3893
+ if (isRemoveButton) {
3894
+ return removeIndex(state, index);
3895
+ }
3896
+ return selectIndex(state, index);
3869
3897
  };
3870
3898
 
3871
3899
  const handleListPointerDown = async (state, button) => {
@@ -4045,13 +4073,6 @@ const removeCurrent = async state => {
4045
4073
  };
4046
4074
  };
4047
4075
 
4048
- const removeIndex = async (state, searchResult, index) => {
4049
- // TODO
4050
- return {
4051
- ...state
4052
- };
4053
- };
4054
-
4055
4076
  const getFocusSelector = focusKey => {
4056
4077
  switch (focusKey) {
4057
4078
  case FocusSearchInput:
@@ -5293,7 +5314,6 @@ const commandMap = {
5293
5314
  'TextSearch.clearSearchResults': wrapCommand(clearSearchResults$1),
5294
5315
  'TextSearch.collapseAll': wrapCommand(collapseAll$1),
5295
5316
  'TextSearch.collapseDetails': wrapCommand(collapseDetails),
5296
- 'TextSearch.removeCurrent': wrapCommand(removeCurrent),
5297
5317
  'TextSearch.copy': wrapCommand(copy),
5298
5318
  'TextSearch.copyPath': wrapCommand(copyPath$1),
5299
5319
  'TextSearch.diff2': diff2,
@@ -5348,6 +5368,7 @@ const commandMap = {
5348
5368
  'TextSearch.nextHistoryResult': wrapCommand(nextHistoryResult),
5349
5369
  'TextSearch.previousHistoryResult': wrapCommand(previousHistoryResult),
5350
5370
  'TextSearch.refresh': wrapCommand(refresh),
5371
+ 'TextSearch.removeCurrent': wrapCommand(removeCurrent),
5351
5372
  'TextSearch.removeIndex': wrapCommand(removeIndex),
5352
5373
  'TextSearch.replaceAll': wrapCommand(replaceAll),
5353
5374
  'TextSearch.rerender': rerender,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "5.23.0",
3
+ "version": "5.24.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"