@lvce-editor/text-search-worker 7.5.2 → 7.6.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.
@@ -54,52 +54,64 @@ class VError extends Error {
54
54
  }
55
55
  }
56
56
 
57
- let AssertionError$1 = class AssertionError extends Error {
57
+ class AssertionError extends Error {
58
58
  constructor(message) {
59
59
  super(message);
60
60
  this.name = 'AssertionError';
61
61
  }
62
- };
63
- const Object$1$1 = 1;
64
- const Number$2 = 2;
65
- const Array$1$1 = 3;
66
- const String$2 = 4;
67
- const Boolean$2 = 5;
68
- const Function$1 = 6;
69
- const Null$1 = 7;
70
- const Unknown$1 = 8;
71
- const getType$1 = value => {
62
+ }
63
+ const Object$1 = 1;
64
+ const Number$1 = 2;
65
+ const Array$1 = 3;
66
+ const String$1 = 4;
67
+ const Boolean$1 = 5;
68
+ const Function = 6;
69
+ const Null = 7;
70
+ const Unknown = 8;
71
+ const getType = value => {
72
72
  switch (typeof value) {
73
73
  case 'number':
74
- return Number$2;
74
+ return Number$1;
75
75
  case 'function':
76
- return Function$1;
76
+ return Function;
77
77
  case 'string':
78
- return String$2;
78
+ return String$1;
79
79
  case 'object':
80
80
  if (value === null) {
81
- return Null$1;
81
+ return Null;
82
82
  }
83
83
  if (Array.isArray(value)) {
84
- return Array$1$1;
84
+ return Array$1;
85
85
  }
86
- return Object$1$1;
86
+ return Object$1;
87
87
  case 'boolean':
88
- return Boolean$2;
88
+ return Boolean$1;
89
89
  default:
90
- return Unknown$1;
90
+ return Unknown;
91
91
  }
92
92
  };
93
93
  const object = value => {
94
- const type = getType$1(value);
95
- if (type !== Object$1$1) {
96
- throw new AssertionError$1('expected value to be of type object');
94
+ const type = getType(value);
95
+ if (type !== Object$1) {
96
+ throw new AssertionError('expected value to be of type object');
97
+ }
98
+ };
99
+ const number = value => {
100
+ const type = getType(value);
101
+ if (type !== Number$1) {
102
+ throw new AssertionError('expected value to be of type number');
97
103
  }
98
104
  };
99
- const number$1 = value => {
100
- const type = getType$1(value);
101
- if (type !== Number$2) {
102
- throw new AssertionError$1('expected value to be of type number');
105
+ const array = value => {
106
+ const type = getType(value);
107
+ if (type !== Array$1) {
108
+ throw new AssertionError('expected value to be of type array');
109
+ }
110
+ };
111
+ const string = value => {
112
+ const type = getType(value);
113
+ if (type !== String$1) {
114
+ throw new AssertionError('expected value to be of type string');
103
115
  }
104
116
  };
105
117
 
@@ -1602,61 +1614,6 @@ const getIcons = async iconRequests => {
1602
1614
  return invoke$2('IconTheme.getIcons', iconRequests);
1603
1615
  };
1604
1616
 
1605
- class AssertionError extends Error {
1606
- constructor(message) {
1607
- super(message);
1608
- this.name = 'AssertionError';
1609
- }
1610
- }
1611
- const Object$1 = 1;
1612
- const Number$1 = 2;
1613
- const Array$1 = 3;
1614
- const String$1 = 4;
1615
- const Boolean$1 = 5;
1616
- const Function = 6;
1617
- const Null = 7;
1618
- const Unknown = 8;
1619
- const getType = value => {
1620
- switch (typeof value) {
1621
- case 'number':
1622
- return Number$1;
1623
- case 'function':
1624
- return Function;
1625
- case 'string':
1626
- return String$1;
1627
- case 'object':
1628
- if (value === null) {
1629
- return Null;
1630
- }
1631
- if (Array.isArray(value)) {
1632
- return Array$1;
1633
- }
1634
- return Object$1;
1635
- case 'boolean':
1636
- return Boolean$1;
1637
- default:
1638
- return Unknown;
1639
- }
1640
- };
1641
- const number = value => {
1642
- const type = getType(value);
1643
- if (type !== Number$1) {
1644
- throw new AssertionError('expected value to be of type number');
1645
- }
1646
- };
1647
- const array = value => {
1648
- const type = getType(value);
1649
- if (type !== Array$1) {
1650
- throw new AssertionError('expected value to be of type array');
1651
- }
1652
- };
1653
- const string = value => {
1654
- const type = getType(value);
1655
- if (type !== String$1) {
1656
- throw new AssertionError('expected value to be of type string');
1657
- }
1658
- };
1659
-
1660
1617
  const {
1661
1618
  invoke: invoke$1,
1662
1619
  invokeAndTransfer,
@@ -2592,6 +2549,7 @@ const {
2592
2549
  getCommandIds,
2593
2550
  registerCommands,
2594
2551
  set,
2552
+ wrapAsyncCommand,
2595
2553
  wrapCommand,
2596
2554
  wrapGetter
2597
2555
  } = create$2();
@@ -2927,6 +2885,9 @@ const PreserveCase$1 = 'Preserve Case';
2927
2885
  const Refresh$2 = 'Refresh';
2928
2886
  const Replace = 'Replace';
2929
2887
  const ReplaceAll$1 = 'Replace All';
2888
+ const ReplacingManyOccurrencesInManyFiles = 'Replacing {PH1} occurrences across {PH2} files…';
2889
+ const ReplacingManyOccurrencesInOneFile = 'Replacing {PH1} occurrences across 1 file…';
2890
+ const ReplacingOneOccurrenceInOneFile = 'Replacing 1 occurrence across 1 file…';
2930
2891
  const ReplacedManyOccurrencesInManyFiles = "Replaced {PH1} occurrences across {PH2} files with '{PH3}'";
2931
2892
  const ReplacedOneOccurrenceInOneFile = "Replaced 1 occurrence across 1 file with '{PH1}'";
2932
2893
  const ReplaceForHistory = 'Replace (⇅ for history)';
@@ -3028,6 +2989,20 @@ const replacedManyOccurrencesInManyFiles = (matchCount, fileCount, replacement)
3028
2989
  PH3: replacement
3029
2990
  });
3030
2991
  };
2992
+ const replacingOneOccurrenceInOneFile = () => {
2993
+ return i18nString(ReplacingOneOccurrenceInOneFile);
2994
+ };
2995
+ const replacingManyOccurrencesInOneFile = matchCount => {
2996
+ return i18nString(ReplacingManyOccurrencesInOneFile, {
2997
+ PH1: matchCount
2998
+ });
2999
+ };
3000
+ const replacingManyOccurrencesInManyFiles = (matchCount, fileCount) => {
3001
+ return i18nString(ReplacingManyOccurrencesInManyFiles, {
3002
+ PH1: matchCount,
3003
+ PH2: fileCount
3004
+ });
3005
+ };
3031
3006
  const replaceAll$1 = () => {
3032
3007
  return i18nString(ReplaceAll$1);
3033
3008
  };
@@ -3611,6 +3586,24 @@ const openSearchEditor = async state => {
3611
3586
  return state;
3612
3587
  };
3613
3588
 
3589
+ const getSearchExcludes = async (fallback = []) => {
3590
+ try {
3591
+ const value = await invoke$1('Preferences.get', 'search.exclude');
3592
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
3593
+ return [];
3594
+ }
3595
+ const excludes = [];
3596
+ for (const [pattern, enabled] of Object.entries(value)) {
3597
+ if (enabled === true) {
3598
+ excludes.push(pattern);
3599
+ }
3600
+ }
3601
+ return excludes;
3602
+ } catch {
3603
+ return fallback;
3604
+ }
3605
+ };
3606
+
3614
3607
  const handleError = error => {
3615
3608
  console.error(`[text-search-worker] ${error}`);
3616
3609
  };
@@ -3840,7 +3833,14 @@ const getRipGrepArgs = ({
3840
3833
  const excludePatternsFromDefaults = defaultExcludes?.filter(Boolean) || [];
3841
3834
  const uniqueExcludePatterns = [...new Set([...excludePatternsFromDefaults, ...excludePatternsFromValue])];
3842
3835
  for (const excludePattern of uniqueExcludePatterns) {
3843
- ripGrepArgs.push('--glob', `!**/${excludePattern}/**`);
3836
+ if (excludePattern.includes('*')) {
3837
+ ripGrepArgs.push('--glob', `!${excludePattern}`);
3838
+ if (!excludePattern.endsWith('/**')) {
3839
+ ripGrepArgs.push('--glob', `!${excludePattern}/**`);
3840
+ }
3841
+ } else {
3842
+ ripGrepArgs.push('--glob', `!**/${excludePattern}/**`);
3843
+ }
3844
3844
  }
3845
3845
  if (isCaseSensitive) {
3846
3846
  ripGrepArgs.push('--case-sensitive');
@@ -4110,8 +4110,14 @@ const handleUpdate = async (state, update) => {
4110
4110
  }
4111
4111
  };
4112
4112
 
4113
- const refresh = state => {
4114
- return handleUpdate(state, {});
4113
+ const refresh = async state => {
4114
+ const {
4115
+ defaultExcludes: currentDefaultExcludes
4116
+ } = state;
4117
+ const defaultExcludes = await getSearchExcludes(currentDefaultExcludes);
4118
+ return handleUpdate(state, {
4119
+ defaultExcludes
4120
+ });
4115
4121
  };
4116
4122
 
4117
4123
  const viewAsTree = async state => {
@@ -4193,6 +4199,16 @@ const getReplaceElements = (items, workspacePath, replacement) => {
4193
4199
  return bulkChanges;
4194
4200
  };
4195
4201
 
4202
+ const getReplacingMessage = (fileCount, replaceCount) => {
4203
+ if (replaceCount === 1) {
4204
+ return replacingOneOccurrenceInOneFile();
4205
+ }
4206
+ if (fileCount === 1) {
4207
+ return replacingManyOccurrencesInOneFile(replaceCount);
4208
+ }
4209
+ return replacingManyOccurrencesInManyFiles(replaceCount, fileCount);
4210
+ };
4211
+
4196
4212
  const getActualIndex = state => {
4197
4213
  const {
4198
4214
  focusedIndex,
@@ -4315,6 +4331,25 @@ const replaceAll = async state => {
4315
4331
  minLineY: 0
4316
4332
  };
4317
4333
  };
4334
+ const replaceAllWithProgress = async context => {
4335
+ const state = context.getState();
4336
+ const {
4337
+ fileCount: totalFileCount,
4338
+ matchCount: totalMatchCount
4339
+ } = state;
4340
+ const actualIndex = getActualIndex(state);
4341
+ const fileIndex = getFileIndex$1(state, actualIndex);
4342
+ const fileCount = fileIndex === -1 ? totalFileCount : 1;
4343
+ const matchCount = fileIndex === -1 ? totalMatchCount : Math.max(getFileItems(state, fileIndex).length - 1, 0);
4344
+ const message = getReplacingMessage(fileCount, matchCount);
4345
+ await context.updateState(latestState => ({
4346
+ ...latestState,
4347
+ message
4348
+ }));
4349
+ await invoke$1('Search.rerender');
4350
+ const updatedState = await replaceAll(context.getState());
4351
+ await context.updateState(() => updatedState);
4352
+ };
4318
4353
 
4319
4354
  const toggleDetailsExpanded = state => {
4320
4355
  const {
@@ -5045,7 +5080,7 @@ const focusIndex = (state, index) => {
5045
5080
  if (itemsLength === 0) {
5046
5081
  return state;
5047
5082
  }
5048
- number$1(itemHeight);
5083
+ number(itemHeight);
5049
5084
  if (index === -1) {
5050
5085
  return {
5051
5086
  ...state,
@@ -5161,7 +5196,7 @@ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
5161
5196
  };
5162
5197
  const setDeltaY = (state, value) => {
5163
5198
  object(state);
5164
- number$1(value);
5199
+ number(value);
5165
5200
  const {
5166
5201
  deltaY,
5167
5202
  finalDeltaY,
@@ -5248,8 +5283,8 @@ const handleScrollBarMove = (state, eventY) => {
5248
5283
  return setDeltaY(state, newDeltaY);
5249
5284
  };
5250
5285
  const handleWheel = (state, deltaMode, deltaY) => {
5251
- number$1(deltaMode);
5252
- number$1(deltaY);
5286
+ number(deltaMode);
5287
+ number(deltaY);
5253
5288
  return setDeltaY(state, state.deltaY + deltaY);
5254
5289
  };
5255
5290
 
@@ -5893,16 +5928,17 @@ const getSearchDetailsToggleVirtualDom = () => {
5893
5928
  }];
5894
5929
  };
5895
5930
 
5896
- const getClassName$1 = indented => {
5931
+ const getSearchMessageClassName = indented => {
5897
5932
  if (indented) {
5898
5933
  return mergeClassNames(ViewletSearchMessage, ViewletSearchMessageIndented);
5899
5934
  }
5900
5935
  return ViewletSearchMessage;
5901
5936
  };
5937
+
5902
5938
  const getSearchMessageVirtualDom = (message, indented) => {
5903
5939
  return [{
5904
5940
  childCount: 1,
5905
- className: getClassName$1(indented),
5941
+ className: getSearchMessageClassName(indented),
5906
5942
  role: Status,
5907
5943
  type: Div
5908
5944
  }, text(message)];
@@ -7061,7 +7097,7 @@ const commandMap = {
7061
7097
  'TextSearch.renderActions': wrapGetter(renderActions),
7062
7098
  'TextSearch.renderEventListeners': renderEventListeners,
7063
7099
  'TextSearch.renderIncremental': renderIncremental,
7064
- 'TextSearch.replaceAll': wrapCommand(replaceAll),
7100
+ 'TextSearch.replaceAll': wrapAsyncCommand(replaceAllWithProgress),
7065
7101
  // TODO needed?
7066
7102
  'TextSearch.replaceAllAndPrompt': replaceAllAndPrompt,
7067
7103
  '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.2",
3
+ "version": "7.6.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"