@lvce-editor/text-search-worker 6.9.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.
- package/dist/textSearchWorkerMain.js +265 -52
- package/package.json +1 -1
|
@@ -2037,6 +2037,76 @@ const collapseAll$1 = async state => {
|
|
|
2037
2037
|
};
|
|
2038
2038
|
};
|
|
2039
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
|
+
|
|
2040
2110
|
const PreserveCase$2 = 1 << 0; // 1
|
|
2041
2111
|
const UseRegularExpression$2 = 1 << 1; // 2
|
|
2042
2112
|
const ReplaceExpanded = 1 << 2; // 4
|
|
@@ -2103,6 +2173,65 @@ const copy$1 = async state => {
|
|
|
2103
2173
|
return state;
|
|
2104
2174
|
};
|
|
2105
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
|
+
|
|
2106
2235
|
const copyPath$1 = async state => {
|
|
2107
2236
|
const {
|
|
2108
2237
|
focusedIndex,
|
|
@@ -2723,6 +2852,28 @@ const enableRenderFolderPaths = state => {
|
|
|
2723
2852
|
};
|
|
2724
2853
|
};
|
|
2725
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
|
+
|
|
2726
2877
|
const expandDetails = state => {
|
|
2727
2878
|
const {
|
|
2728
2879
|
flags,
|
|
@@ -2875,7 +3026,9 @@ const Enter = 3;
|
|
|
2875
3026
|
const End = 255;
|
|
2876
3027
|
const Home = 12;
|
|
2877
3028
|
const UpArrow = 14;
|
|
3029
|
+
const LeftArrow = 15;
|
|
2878
3030
|
const DownArrow = 16;
|
|
3031
|
+
const RightArrow = 17;
|
|
2879
3032
|
const Delete = 18;
|
|
2880
3033
|
const KeyC = 31;
|
|
2881
3034
|
|
|
@@ -2924,6 +3077,14 @@ const getSearchResultKeyBindings = () => {
|
|
|
2924
3077
|
command: 'Search.focusPrevious',
|
|
2925
3078
|
key: UpArrow,
|
|
2926
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
|
|
2927
3088
|
}, {
|
|
2928
3089
|
command: 'Search.dismissItem',
|
|
2929
3090
|
key: Delete,
|
|
@@ -3674,7 +3835,106 @@ const getReplaceElements = (items, workspacePath, replacement) => {
|
|
|
3674
3835
|
return bulkChanges;
|
|
3675
3836
|
};
|
|
3676
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
|
+
};
|
|
3677
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
|
+
}
|
|
3678
3938
|
const {
|
|
3679
3939
|
items,
|
|
3680
3940
|
matchCount,
|
|
@@ -3899,13 +4159,6 @@ const handleInputContextMenu = async (state, name, button, x, y) => {
|
|
|
3899
4159
|
return state;
|
|
3900
4160
|
};
|
|
3901
4161
|
|
|
3902
|
-
const writeText = async text => {
|
|
3903
|
-
await writeClipBoardText(text);
|
|
3904
|
-
};
|
|
3905
|
-
const readText = async () => {
|
|
3906
|
-
return await invoke$1('ClipBoard.readText');
|
|
3907
|
-
};
|
|
3908
|
-
|
|
3909
4162
|
const getCurrentValue = (state, name) => {
|
|
3910
4163
|
switch (name) {
|
|
3911
4164
|
case FilesToExclude:
|
|
@@ -4632,24 +4885,6 @@ const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight, topHeight, itemC
|
|
|
4632
4885
|
return index;
|
|
4633
4886
|
};
|
|
4634
4887
|
|
|
4635
|
-
const getFilteredResults = (results, collapsedPaths) => {
|
|
4636
|
-
if (collapsedPaths.length === 0) {
|
|
4637
|
-
return results;
|
|
4638
|
-
}
|
|
4639
|
-
const filteredResults = [];
|
|
4640
|
-
let isExcluded = false;
|
|
4641
|
-
for (const result of results) {
|
|
4642
|
-
if (result.type === File) {
|
|
4643
|
-
filteredResults.push(result);
|
|
4644
|
-
isExcluded = collapsedPaths.includes(result.text) ? true : false;
|
|
4645
|
-
}
|
|
4646
|
-
if (result.type === Match && !isExcluded) {
|
|
4647
|
-
filteredResults.push(result);
|
|
4648
|
-
}
|
|
4649
|
-
}
|
|
4650
|
-
return filteredResults;
|
|
4651
|
-
};
|
|
4652
|
-
|
|
4653
4888
|
const toggleCollapsedPath = (collapsedPaths, path) => {
|
|
4654
4889
|
if (collapsedPaths.includes(path)) {
|
|
4655
4890
|
const index = collapsedPaths.indexOf(path);
|
|
@@ -4660,36 +4895,11 @@ const toggleCollapsedPath = (collapsedPaths, path) => {
|
|
|
4660
4895
|
|
|
4661
4896
|
const selectIndexFile = async (state, searchResult, index) => {
|
|
4662
4897
|
const {
|
|
4663
|
-
collapsedPaths
|
|
4664
|
-
fileIconCache,
|
|
4665
|
-
headerHeight,
|
|
4666
|
-
height,
|
|
4667
|
-
itemHeight,
|
|
4668
|
-
items
|
|
4898
|
+
collapsedPaths
|
|
4669
4899
|
} = state;
|
|
4670
4900
|
const path = searchResult.text;
|
|
4671
4901
|
const newCollapsedPaths = toggleCollapsedPath(collapsedPaths, path);
|
|
4672
|
-
|
|
4673
|
-
const {
|
|
4674
|
-
icons,
|
|
4675
|
-
newFileIconCache
|
|
4676
|
-
} = await getFileIcons(filteredResults, fileIconCache);
|
|
4677
|
-
const total = filteredResults.length;
|
|
4678
|
-
const listHeight = height - headerHeight;
|
|
4679
|
-
const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
|
|
4680
|
-
const maxLineY = Math.min(numberOfVisible, total);
|
|
4681
|
-
return {
|
|
4682
|
-
...state,
|
|
4683
|
-
collapsedPaths: newCollapsedPaths,
|
|
4684
|
-
fileIconCache: newFileIconCache,
|
|
4685
|
-
focus: FocusSearchResults,
|
|
4686
|
-
focusSource: Script,
|
|
4687
|
-
icons,
|
|
4688
|
-
listFocused: true,
|
|
4689
|
-
listFocusedIndex: index,
|
|
4690
|
-
listItems: filteredResults,
|
|
4691
|
-
maxLineY
|
|
4692
|
-
};
|
|
4902
|
+
return applyCollapsedPaths(state, newCollapsedPaths, index);
|
|
4693
4903
|
};
|
|
4694
4904
|
|
|
4695
4905
|
const getFileIndex = (items, index) => {
|
|
@@ -6367,14 +6577,17 @@ const handleContextMenu = async (state, button, x, y) => {
|
|
|
6367
6577
|
const commandMap = {
|
|
6368
6578
|
'TextSearch.clearSearchResults': wrapCommand(clearSearchResults$1),
|
|
6369
6579
|
'TextSearch.collapseAll': wrapCommand(collapseAll$1),
|
|
6580
|
+
'TextSearch.collapseCurrent': wrapCommand(collapseCurrent),
|
|
6370
6581
|
'TextSearch.collapseDetails': wrapCommand(collapseDetails),
|
|
6371
6582
|
'TextSearch.copy': wrapCommand(copy$1),
|
|
6583
|
+
'TextSearch.copyAll': wrapCommand(copyAll$1),
|
|
6372
6584
|
'TextSearch.copyPath': wrapCommand(copyPath$1),
|
|
6373
6585
|
'TextSearch.create': create,
|
|
6374
6586
|
'TextSearch.diff2': diff2,
|
|
6375
6587
|
'TextSearch.disableRenderFolderPaths': wrapCommand(disableRenderFolderPaths),
|
|
6376
6588
|
'TextSearch.dismissItem': wrapCommand(dismissItem),
|
|
6377
6589
|
'TextSearch.enableRenderFolderPaths': wrapCommand(enableRenderFolderPaths),
|
|
6590
|
+
'TextSearch.expandCurrent': wrapCommand(expandCurrent),
|
|
6378
6591
|
'TextSearch.expandDetails': wrapCommand(expandDetails),
|
|
6379
6592
|
'TextSearch.focusFirst': wrapCommand(focusFirst),
|
|
6380
6593
|
'TextSearch.focusIndex': wrapCommand(focusIndex),
|