@lvce-editor/text-search-worker 6.8.0 → 7.0.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.
@@ -1795,7 +1795,6 @@ const diffChildren = (oldChildren, newChildren, patches) => {
1795
1795
  patches.push({
1796
1796
  type: NavigateParent
1797
1797
  });
1798
- currentChildIndex = -1;
1799
1798
  }
1800
1799
  // Add remove patches in reverse order (highest index first)
1801
1800
  // This ensures indices remain valid as we remove
@@ -2038,6 +2037,76 @@ const collapseAll$1 = async state => {
2038
2037
  };
2039
2038
  };
2040
2039
 
2040
+ const getFilteredResults = (results, collapsedPaths) => {
2041
+ if (collapsedPaths.length === 0) {
2042
+ return results;
2043
+ }
2044
+ const filteredResults = [];
2045
+ let isExcluded = false;
2046
+ for (const result of results) {
2047
+ if (result.type === File) {
2048
+ filteredResults.push(result);
2049
+ isExcluded = collapsedPaths.includes(result.text) ? true : false;
2050
+ }
2051
+ if (result.type === Match && !isExcluded) {
2052
+ filteredResults.push(result);
2053
+ }
2054
+ }
2055
+ return filteredResults;
2056
+ };
2057
+
2058
+ const applyCollapsedPaths = async (state, collapsedPaths, listFocusedIndex) => {
2059
+ const {
2060
+ fileIconCache,
2061
+ headerHeight,
2062
+ height,
2063
+ itemHeight,
2064
+ items
2065
+ } = state;
2066
+ const filteredResults = getFilteredResults(items, collapsedPaths);
2067
+ const {
2068
+ icons,
2069
+ newFileIconCache
2070
+ } = await getFileIcons(filteredResults, fileIconCache);
2071
+ const total = filteredResults.length;
2072
+ const listHeight = height - headerHeight;
2073
+ const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
2074
+ const maxLineY = Math.min(numberOfVisible, total);
2075
+ return {
2076
+ ...state,
2077
+ collapsedPaths,
2078
+ fileIconCache: newFileIconCache,
2079
+ focus: FocusSearchResults,
2080
+ focusSource: Script,
2081
+ icons,
2082
+ listFocused: true,
2083
+ listFocusedIndex,
2084
+ listItems: filteredResults,
2085
+ maxLineY
2086
+ };
2087
+ };
2088
+
2089
+ const collapseCurrent = async state => {
2090
+ const {
2091
+ collapsedPaths,
2092
+ focusedIndex,
2093
+ listFocusedIndex,
2094
+ listItems
2095
+ } = state;
2096
+ const actualIndex = focusedIndex === -1 ? listFocusedIndex : focusedIndex;
2097
+ if (actualIndex === -1) {
2098
+ return state;
2099
+ }
2100
+ const item = listItems[actualIndex];
2101
+ if (!item || item.type !== File) {
2102
+ return state;
2103
+ }
2104
+ if (collapsedPaths.includes(item.text)) {
2105
+ return state;
2106
+ }
2107
+ return applyCollapsedPaths(state, [...collapsedPaths, item.text], actualIndex);
2108
+ };
2109
+
2041
2110
  const PreserveCase$2 = 1 << 0; // 1
2042
2111
  const UseRegularExpression$2 = 1 << 1; // 2
2043
2112
  const ReplaceExpanded = 1 << 2; // 4
@@ -2104,6 +2173,65 @@ const copy$1 = async state => {
2104
2173
  return state;
2105
2174
  };
2106
2175
 
2176
+ const writeText = async text => {
2177
+ await writeClipBoardText(text);
2178
+ };
2179
+ const readText = async () => {
2180
+ return await invoke$1('ClipBoard.readText');
2181
+ };
2182
+
2183
+ const getActualIndex$1 = state => {
2184
+ const {
2185
+ focusedIndex,
2186
+ listFocusedIndex
2187
+ } = state;
2188
+ return focusedIndex === -1 ? listFocusedIndex : focusedIndex;
2189
+ };
2190
+ const getFileIndex$2 = (items, actualIndex) => {
2191
+ if (actualIndex < 0 || actualIndex >= items.length) {
2192
+ return -1;
2193
+ }
2194
+ if (items[actualIndex].type === File) {
2195
+ return actualIndex;
2196
+ }
2197
+ for (let i = actualIndex; i >= 0; i--) {
2198
+ if (items[i].type === File) {
2199
+ return i;
2200
+ }
2201
+ }
2202
+ return -1;
2203
+ };
2204
+ const getMatchTexts = (items, fileIndex) => {
2205
+ const matchTexts = [];
2206
+ for (let i = fileIndex + 1; i < items.length; i++) {
2207
+ const item = items[i];
2208
+ if (item.type === File) {
2209
+ break;
2210
+ }
2211
+ matchTexts.push(item.text);
2212
+ }
2213
+ return matchTexts;
2214
+ };
2215
+ const copyAll$1 = async state => {
2216
+ const {
2217
+ items
2218
+ } = state;
2219
+ const actualIndex = getActualIndex$1(state);
2220
+ if (actualIndex === -1) {
2221
+ return state;
2222
+ }
2223
+ const fileIndex = getFileIndex$2(items, actualIndex);
2224
+ if (fileIndex === -1) {
2225
+ return state;
2226
+ }
2227
+ const matchTexts = getMatchTexts(items, fileIndex);
2228
+ if (matchTexts.length === 0) {
2229
+ return state;
2230
+ }
2231
+ await writeText(matchTexts.join('\n'));
2232
+ return state;
2233
+ };
2234
+
2107
2235
  const copyPath$1 = async state => {
2108
2236
  const {
2109
2237
  focusedIndex,
@@ -2724,6 +2852,28 @@ const enableRenderFolderPaths = state => {
2724
2852
  };
2725
2853
  };
2726
2854
 
2855
+ const expandCurrent = async state => {
2856
+ const {
2857
+ collapsedPaths,
2858
+ focusedIndex,
2859
+ listFocusedIndex,
2860
+ listItems
2861
+ } = state;
2862
+ const actualIndex = focusedIndex === -1 ? listFocusedIndex : focusedIndex;
2863
+ if (actualIndex === -1) {
2864
+ return state;
2865
+ }
2866
+ const item = listItems[actualIndex];
2867
+ if (!item || item.type !== File) {
2868
+ return state;
2869
+ }
2870
+ const collapsedIndex = collapsedPaths.indexOf(item.text);
2871
+ if (collapsedIndex === -1) {
2872
+ return state;
2873
+ }
2874
+ return applyCollapsedPaths(state, collapsedPaths.toSpliced(collapsedIndex, 1), actualIndex);
2875
+ };
2876
+
2727
2877
  const expandDetails = state => {
2728
2878
  const {
2729
2879
  flags,
@@ -2876,7 +3026,9 @@ const Enter = 3;
2876
3026
  const End = 255;
2877
3027
  const Home = 12;
2878
3028
  const UpArrow = 14;
3029
+ const LeftArrow = 15;
2879
3030
  const DownArrow = 16;
3031
+ const RightArrow = 17;
2880
3032
  const Delete = 18;
2881
3033
  const KeyC = 31;
2882
3034
 
@@ -2925,6 +3077,14 @@ const getSearchResultKeyBindings = () => {
2925
3077
  command: 'Search.focusPrevious',
2926
3078
  key: UpArrow,
2927
3079
  when: FocusSearchResults
3080
+ }, {
3081
+ command: 'Search.collapseCurrent',
3082
+ key: LeftArrow,
3083
+ when: FocusSearchResults
3084
+ }, {
3085
+ command: 'Search.expandCurrent',
3086
+ key: RightArrow,
3087
+ when: FocusSearchResults
2928
3088
  }, {
2929
3089
  command: 'Search.dismissItem',
2930
3090
  key: Delete,
@@ -3112,16 +3272,27 @@ const handleUpdateEmpty = (state, update) => {
3112
3272
  ...state,
3113
3273
  ...update
3114
3274
  };
3275
+ const headerHeight = getTopHeight(partialNewState.flags);
3115
3276
  return {
3116
3277
  ...partialNewState,
3278
+ collapsedPaths: [],
3117
3279
  deltaY: 0,
3280
+ fileCount: 0,
3281
+ finalDeltaY: 0,
3282
+ headerHeight,
3283
+ icons: [],
3118
3284
  items: [],
3285
+ limitHit: false,
3286
+ limitHitWarning: '',
3119
3287
  listItems: [],
3120
3288
  loaded: true,
3121
3289
  matchCount: 0,
3122
3290
  maxLineY: 0,
3123
3291
  message: '',
3124
3292
  minLineY: 0,
3293
+ scrollBarHeight: 0,
3294
+ scrollBarY: 0,
3295
+ searchId: '',
3125
3296
  searchInputErrorMessage: ''
3126
3297
  };
3127
3298
  };
@@ -3664,7 +3835,106 @@ const getReplaceElements = (items, workspacePath, replacement) => {
3664
3835
  return bulkChanges;
3665
3836
  };
3666
3837
 
3838
+ const getActualIndex = state => {
3839
+ const {
3840
+ focusedIndex,
3841
+ listFocusedIndex
3842
+ } = state;
3843
+ return focusedIndex === -1 ? listFocusedIndex : focusedIndex;
3844
+ };
3845
+ const getFileIndex$1 = (state, actualIndex) => {
3846
+ const {
3847
+ items
3848
+ } = state;
3849
+ if (actualIndex < 0 || actualIndex >= items.length) {
3850
+ return -1;
3851
+ }
3852
+ if (items[actualIndex].type === File) {
3853
+ return actualIndex;
3854
+ }
3855
+ return -1;
3856
+ };
3857
+ const getFileItems = (state, fileIndex) => {
3858
+ const {
3859
+ items
3860
+ } = state;
3861
+ const fileItems = [items[fileIndex]];
3862
+ for (let i = fileIndex + 1; i < items.length; i++) {
3863
+ const item = items[i];
3864
+ if (item.type === File) {
3865
+ break;
3866
+ }
3867
+ fileItems.push(item);
3868
+ }
3869
+ return fileItems;
3870
+ };
3871
+ const replaceAllInFocusedFile = async (state, fileIndex) => {
3872
+ const {
3873
+ deltaY,
3874
+ fileCount,
3875
+ fileIconCache,
3876
+ headerHeight,
3877
+ height,
3878
+ itemHeight,
3879
+ items,
3880
+ maxLineY,
3881
+ minimumSliderSize,
3882
+ minLineY,
3883
+ replacement,
3884
+ workspacePath
3885
+ } = state;
3886
+ const fileItems = getFileItems(state, fileIndex);
3887
+ const matchCount = Math.max(fileItems.length - 1, 0);
3888
+ if (matchCount === 0) {
3889
+ return state;
3890
+ }
3891
+ const bulkEdits = getReplaceElements(fileItems, workspacePath, replacement);
3892
+ await applyBulkReplacement(bulkEdits);
3893
+ await handleWorkspaceRefresh();
3894
+ const {
3895
+ newFileCount,
3896
+ newFocusedIndex,
3897
+ newItems,
3898
+ newMatchCount
3899
+ } = removeItemFromItems(items, fileIndex, state.matchCount, fileCount);
3900
+ const {
3901
+ newDeltaY,
3902
+ newMaxLineY,
3903
+ newMinLineY
3904
+ } = getNewMinMax(newItems.length, minLineY, maxLineY, deltaY, itemHeight);
3905
+ const total = newItems.length;
3906
+ const contentHeight = total * itemHeight;
3907
+ const listHeight = height - headerHeight;
3908
+ const scrollBarHeight = getScrollBarSize$1(height, contentHeight, minimumSliderSize);
3909
+ const finalDeltaY = Math.max(contentHeight - listHeight, 0);
3910
+ const visible = newItems.slice(0, newMaxLineY);
3911
+ const {
3912
+ icons,
3913
+ newFileIconCache
3914
+ } = await getFileIcons(visible, fileIconCache);
3915
+ return {
3916
+ ...state,
3917
+ deltaY: newDeltaY,
3918
+ fileCount: newFileCount,
3919
+ fileIconCache: newFileIconCache,
3920
+ finalDeltaY,
3921
+ icons,
3922
+ items: newItems,
3923
+ listFocusedIndex: newFocusedIndex,
3924
+ listItems: newItems,
3925
+ matchCount: newMatchCount,
3926
+ maxLineY: newMaxLineY,
3927
+ message: getReplacedMessage(1, matchCount, replacement),
3928
+ minLineY: newMinLineY,
3929
+ scrollBarHeight
3930
+ };
3931
+ };
3667
3932
  const replaceAll = async state => {
3933
+ const actualIndex = getActualIndex(state);
3934
+ const fileIndex = getFileIndex$1(state, actualIndex);
3935
+ if (fileIndex !== -1) {
3936
+ return replaceAllInFocusedFile(state, fileIndex);
3937
+ }
3668
3938
  const {
3669
3939
  items,
3670
3940
  matchCount,
@@ -3889,13 +4159,6 @@ const handleInputContextMenu = async (state, name, button, x, y) => {
3889
4159
  return state;
3890
4160
  };
3891
4161
 
3892
- const writeText = async text => {
3893
- await writeClipBoardText(text);
3894
- };
3895
- const readText = async () => {
3896
- return await invoke$1('ClipBoard.readText');
3897
- };
3898
-
3899
4162
  const getCurrentValue = (state, name) => {
3900
4163
  switch (name) {
3901
4164
  case FilesToExclude:
@@ -4622,24 +4885,6 @@ const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight, topHeight, itemC
4622
4885
  return index;
4623
4886
  };
4624
4887
 
4625
- const getFilteredResults = (results, collapsedPaths) => {
4626
- if (collapsedPaths.length === 0) {
4627
- return results;
4628
- }
4629
- const filteredResults = [];
4630
- let isExcluded = false;
4631
- for (const result of results) {
4632
- if (result.type === File) {
4633
- filteredResults.push(result);
4634
- isExcluded = collapsedPaths.includes(result.text) ? true : false;
4635
- }
4636
- if (result.type === Match && !isExcluded) {
4637
- filteredResults.push(result);
4638
- }
4639
- }
4640
- return filteredResults;
4641
- };
4642
-
4643
4888
  const toggleCollapsedPath = (collapsedPaths, path) => {
4644
4889
  if (collapsedPaths.includes(path)) {
4645
4890
  const index = collapsedPaths.indexOf(path);
@@ -4650,36 +4895,11 @@ const toggleCollapsedPath = (collapsedPaths, path) => {
4650
4895
 
4651
4896
  const selectIndexFile = async (state, searchResult, index) => {
4652
4897
  const {
4653
- collapsedPaths,
4654
- fileIconCache,
4655
- headerHeight,
4656
- height,
4657
- itemHeight,
4658
- items
4898
+ collapsedPaths
4659
4899
  } = state;
4660
4900
  const path = searchResult.text;
4661
4901
  const newCollapsedPaths = toggleCollapsedPath(collapsedPaths, path);
4662
- const filteredResults = getFilteredResults(items, newCollapsedPaths);
4663
- const {
4664
- icons,
4665
- newFileIconCache
4666
- } = await getFileIcons(filteredResults, fileIconCache);
4667
- const total = filteredResults.length;
4668
- const listHeight = height - headerHeight;
4669
- const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
4670
- const maxLineY = Math.min(numberOfVisible, total);
4671
- return {
4672
- ...state,
4673
- collapsedPaths: newCollapsedPaths,
4674
- fileIconCache: newFileIconCache,
4675
- focus: FocusSearchResults,
4676
- focusSource: Script,
4677
- icons,
4678
- listFocused: true,
4679
- listFocusedIndex: index,
4680
- listItems: filteredResults,
4681
- maxLineY
4682
- };
4902
+ return applyCollapsedPaths(state, newCollapsedPaths, index);
4683
4903
  };
4684
4904
 
4685
4905
  const getFileIndex = (items, index) => {
@@ -5119,8 +5339,8 @@ const createViewModel = state => {
5119
5339
  } = state;
5120
5340
  const displayResults = getDisplayResults(listItems, itemHeight, fileCount, value, minLineY, maxLineY, replacement, icons, listFocusedIndex, collapsedPaths, renderFolderPaths || false, items);
5121
5341
  const focusOutline = listFocused && listFocusedIndex === -1;
5122
- const scrollBarValue = deltaY / finalDeltaY * 100;
5123
- const scrollBarY = getScrollBarY$1(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
5342
+ const scrollBarValue = finalDeltaY === 0 ? 0 : deltaY / finalDeltaY * 100;
5343
+ const scrollBarY = finalDeltaY === 0 ? 0 : getScrollBarY$1(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
5124
5344
  return {
5125
5345
  deltaY,
5126
5346
  displayResults,
@@ -6357,14 +6577,17 @@ const handleContextMenu = async (state, button, x, y) => {
6357
6577
  const commandMap = {
6358
6578
  'TextSearch.clearSearchResults': wrapCommand(clearSearchResults$1),
6359
6579
  'TextSearch.collapseAll': wrapCommand(collapseAll$1),
6580
+ 'TextSearch.collapseCurrent': wrapCommand(collapseCurrent),
6360
6581
  'TextSearch.collapseDetails': wrapCommand(collapseDetails),
6361
6582
  'TextSearch.copy': wrapCommand(copy$1),
6583
+ 'TextSearch.copyAll': wrapCommand(copyAll$1),
6362
6584
  'TextSearch.copyPath': wrapCommand(copyPath$1),
6363
6585
  'TextSearch.create': create,
6364
6586
  'TextSearch.diff2': diff2,
6365
6587
  'TextSearch.disableRenderFolderPaths': wrapCommand(disableRenderFolderPaths),
6366
6588
  'TextSearch.dismissItem': wrapCommand(dismissItem),
6367
6589
  'TextSearch.enableRenderFolderPaths': wrapCommand(enableRenderFolderPaths),
6590
+ 'TextSearch.expandCurrent': wrapCommand(expandCurrent),
6368
6591
  'TextSearch.expandDetails': wrapCommand(expandDetails),
6369
6592
  'TextSearch.focusFirst': wrapCommand(focusFirst),
6370
6593
  'TextSearch.focusIndex': wrapCommand(focusIndex),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "6.8.0",
3
+ "version": "7.0.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"