@lvce-editor/text-search-worker 7.5.1 → 7.5.3

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.
@@ -2592,6 +2592,7 @@ const {
2592
2592
  getCommandIds,
2593
2593
  registerCommands,
2594
2594
  set,
2595
+ wrapAsyncCommand,
2595
2596
  wrapCommand,
2596
2597
  wrapGetter
2597
2598
  } = create$2();
@@ -2927,6 +2928,9 @@ const PreserveCase$1 = 'Preserve Case';
2927
2928
  const Refresh$2 = 'Refresh';
2928
2929
  const Replace = 'Replace';
2929
2930
  const ReplaceAll$1 = 'Replace All';
2931
+ const ReplacingManyOccurrencesInManyFiles = 'Replacing {PH1} occurrences across {PH2} files…';
2932
+ const ReplacingManyOccurrencesInOneFile = 'Replacing {PH1} occurrences across 1 file…';
2933
+ const ReplacingOneOccurrenceInOneFile = 'Replacing 1 occurrence across 1 file…';
2930
2934
  const ReplacedManyOccurrencesInManyFiles = "Replaced {PH1} occurrences across {PH2} files with '{PH3}'";
2931
2935
  const ReplacedOneOccurrenceInOneFile = "Replaced 1 occurrence across 1 file with '{PH1}'";
2932
2936
  const ReplaceForHistory = 'Replace (⇅ for history)';
@@ -3028,6 +3032,20 @@ const replacedManyOccurrencesInManyFiles = (matchCount, fileCount, replacement)
3028
3032
  PH3: replacement
3029
3033
  });
3030
3034
  };
3035
+ const replacingOneOccurrenceInOneFile = () => {
3036
+ return i18nString(ReplacingOneOccurrenceInOneFile);
3037
+ };
3038
+ const replacingManyOccurrencesInOneFile = matchCount => {
3039
+ return i18nString(ReplacingManyOccurrencesInOneFile, {
3040
+ PH1: matchCount
3041
+ });
3042
+ };
3043
+ const replacingManyOccurrencesInManyFiles = (matchCount, fileCount) => {
3044
+ return i18nString(ReplacingManyOccurrencesInManyFiles, {
3045
+ PH1: matchCount,
3046
+ PH2: fileCount
3047
+ });
3048
+ };
3031
3049
  const replaceAll$1 = () => {
3032
3050
  return i18nString(ReplaceAll$1);
3033
3051
  };
@@ -3611,6 +3629,24 @@ const openSearchEditor = async state => {
3611
3629
  return state;
3612
3630
  };
3613
3631
 
3632
+ const getSearchExcludes = async (fallback = []) => {
3633
+ try {
3634
+ const value = await invoke$1('Preferences.get', 'search.exclude');
3635
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
3636
+ return [];
3637
+ }
3638
+ const excludes = [];
3639
+ for (const [pattern, enabled] of Object.entries(value)) {
3640
+ if (enabled === true) {
3641
+ excludes.push(pattern);
3642
+ }
3643
+ }
3644
+ return excludes;
3645
+ } catch {
3646
+ return fallback;
3647
+ }
3648
+ };
3649
+
3614
3650
  const handleError = error => {
3615
3651
  console.error(`[text-search-worker] ${error}`);
3616
3652
  };
@@ -3840,7 +3876,14 @@ const getRipGrepArgs = ({
3840
3876
  const excludePatternsFromDefaults = defaultExcludes?.filter(Boolean) || [];
3841
3877
  const uniqueExcludePatterns = [...new Set([...excludePatternsFromDefaults, ...excludePatternsFromValue])];
3842
3878
  for (const excludePattern of uniqueExcludePatterns) {
3843
- ripGrepArgs.push('--glob', `!**/${excludePattern}/**`);
3879
+ if (excludePattern.includes('*')) {
3880
+ ripGrepArgs.push('--glob', `!${excludePattern}`);
3881
+ if (!excludePattern.endsWith('/**')) {
3882
+ ripGrepArgs.push('--glob', `!${excludePattern}/**`);
3883
+ }
3884
+ } else {
3885
+ ripGrepArgs.push('--glob', `!**/${excludePattern}/**`);
3886
+ }
3844
3887
  }
3845
3888
  if (isCaseSensitive) {
3846
3889
  ripGrepArgs.push('--case-sensitive');
@@ -4110,8 +4153,14 @@ const handleUpdate = async (state, update) => {
4110
4153
  }
4111
4154
  };
4112
4155
 
4113
- const refresh = state => {
4114
- return handleUpdate(state, {});
4156
+ const refresh = async state => {
4157
+ const {
4158
+ defaultExcludes: currentDefaultExcludes
4159
+ } = state;
4160
+ const defaultExcludes = await getSearchExcludes(currentDefaultExcludes);
4161
+ return handleUpdate(state, {
4162
+ defaultExcludes
4163
+ });
4115
4164
  };
4116
4165
 
4117
4166
  const viewAsTree = async state => {
@@ -4193,6 +4242,16 @@ const getReplaceElements = (items, workspacePath, replacement) => {
4193
4242
  return bulkChanges;
4194
4243
  };
4195
4244
 
4245
+ const getReplacingMessage = (fileCount, replaceCount) => {
4246
+ if (replaceCount === 1) {
4247
+ return replacingOneOccurrenceInOneFile();
4248
+ }
4249
+ if (fileCount === 1) {
4250
+ return replacingManyOccurrencesInOneFile(replaceCount);
4251
+ }
4252
+ return replacingManyOccurrencesInManyFiles(replaceCount, fileCount);
4253
+ };
4254
+
4196
4255
  const getActualIndex = state => {
4197
4256
  const {
4198
4257
  focusedIndex,
@@ -4315,6 +4374,25 @@ const replaceAll = async state => {
4315
4374
  minLineY: 0
4316
4375
  };
4317
4376
  };
4377
+ const replaceAllWithProgress = async context => {
4378
+ const state = context.getState();
4379
+ const {
4380
+ fileCount: totalFileCount,
4381
+ matchCount: totalMatchCount
4382
+ } = state;
4383
+ const actualIndex = getActualIndex(state);
4384
+ const fileIndex = getFileIndex$1(state, actualIndex);
4385
+ const fileCount = fileIndex === -1 ? totalFileCount : 1;
4386
+ const matchCount = fileIndex === -1 ? totalMatchCount : Math.max(getFileItems(state, fileIndex).length - 1, 0);
4387
+ const message = getReplacingMessage(fileCount, matchCount);
4388
+ await context.updateState(latestState => ({
4389
+ ...latestState,
4390
+ message
4391
+ }));
4392
+ await invoke$1('Search.rerender');
4393
+ const updatedState = await replaceAll(context.getState());
4394
+ await context.updateState(() => updatedState);
4395
+ };
4318
4396
 
4319
4397
  const toggleDetailsExpanded = state => {
4320
4398
  const {
@@ -5310,10 +5388,10 @@ const getRelativeFolderPath = relativePath => {
5310
5388
 
5311
5389
  const selectIndexPreview = async (state, searchResult, index) => {
5312
5390
  const {
5313
- items,
5391
+ listItems,
5314
5392
  workspacePath
5315
5393
  } = state;
5316
- const fileIndex = getFileIndex(items, index);
5394
+ const fileIndex = getFileIndex(listItems, index);
5317
5395
  if (fileIndex === -1) {
5318
5396
  throw new Error('Search result is missing file');
5319
5397
  }
@@ -5325,7 +5403,7 @@ const selectIndexPreview = async (state, searchResult, index) => {
5325
5403
  start,
5326
5404
  startColumnIndex = start
5327
5405
  } = searchResult;
5328
- const fileResult = items[fileIndex];
5406
+ const fileResult = listItems[fileIndex];
5329
5407
  const relativePath = getRelativePath(fileResult.text);
5330
5408
  const absolutePath = `${workspacePath}${relativePath}`;
5331
5409
  await openUri(absolutePath, true, {
@@ -7061,7 +7139,7 @@ const commandMap = {
7061
7139
  'TextSearch.renderActions': wrapGetter(renderActions),
7062
7140
  'TextSearch.renderEventListeners': renderEventListeners,
7063
7141
  'TextSearch.renderIncremental': renderIncremental,
7064
- 'TextSearch.replaceAll': wrapCommand(replaceAll),
7142
+ 'TextSearch.replaceAll': wrapAsyncCommand(replaceAllWithProgress),
7065
7143
  // TODO needed?
7066
7144
  'TextSearch.replaceAllAndPrompt': replaceAllAndPrompt,
7067
7145
  'TextSearch.replaceAllInFile': wrapCommand(replaceAllInFile),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "7.5.1",
3
+ "version": "7.5.3",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"