@lvce-editor/text-search-worker 3.24.0 → 3.25.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.
@@ -1196,7 +1196,8 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
1196
1196
  handleOffset: 0,
1197
1197
  focusSource: User,
1198
1198
  flags: 0,
1199
- platform
1199
+ platform,
1200
+ searchInputErrorMessage: ''
1200
1201
  };
1201
1202
  set(uid, state, state);
1202
1203
  return state;
@@ -1245,6 +1246,8 @@ const PreserveCase$2 = 'Preserve Case';
1245
1246
  const Refresh$1 = 'Refresh';
1246
1247
  const Replace = 'Replace';
1247
1248
  const ReplaceAll$1 = 'Replace All';
1249
+ const ReplacedManyOccurrencesInManyFiles = "Replaced {PH1} occurrences across {PH2} files with '{PH3}'";
1250
+ const ReplacedOneOccurrenceInOneFile = "Replaced 1 occurrence across 1 file with '{PH1}'";
1248
1251
  const ToggleReplace$1 = 'Toggle Replace';
1249
1252
  const UseRegularExpression$2 = 'Use Regular Expression';
1250
1253
  const ViewAsTree = 'View as Tree';
@@ -1321,6 +1324,24 @@ const confirmReplaceManyOccurrencesInManyFilesNoValue = (matchCount, fileCount)
1321
1324
  PH2: fileCount
1322
1325
  });
1323
1326
  };
1327
+ const replacedOneOccurrenceInOneFile = replacement => {
1328
+ return i18nString(ReplacedOneOccurrenceInOneFile, {
1329
+ PH1: replacement
1330
+ });
1331
+ };
1332
+ const replacedManyOccurrencesInOneFile = (matchCount, replacement) => {
1333
+ return i18nString(ReplacedOneOccurrenceInOneFile, {
1334
+ PH1: matchCount,
1335
+ PH2: replacement
1336
+ });
1337
+ };
1338
+ const replacedManyOccurrencesInManyFiles = (matchCount, fileCount, replacement) => {
1339
+ return i18nString(ReplacedManyOccurrencesInManyFiles, {
1340
+ PH1: matchCount,
1341
+ PH2: fileCount,
1342
+ PH3: replacement
1343
+ });
1344
+ };
1324
1345
  const replaceAll$1 = () => {
1325
1346
  return i18nString(ReplaceAll$1);
1326
1347
  };
@@ -1513,22 +1534,6 @@ const MatchCase$1 = 1 << 4; // 16
1513
1534
  const DetailsExpanded = 1 << 5; // 32
1514
1535
  const OpenEditors = 1 << 6; // 64
1515
1536
  const UseIgnoreFiles = 1 << 7; // 128
1516
-
1517
- const hasPreserveCase = flags => {
1518
- return (flags & PreserveCase$1) === PreserveCase$1;
1519
- };
1520
- const hasUseRegularExpression = flags => {
1521
- return (flags & UseRegularExpression$1) === UseRegularExpression$1;
1522
- };
1523
- const hasReplaceExpanded = flags => {
1524
- return (flags & ReplaceExpanded) === ReplaceExpanded;
1525
- };
1526
- const hasMatchWholeWord = flags => {
1527
- return (flags & MatchWholeWord$1) === MatchWholeWord$1;
1528
- };
1529
- const hasMatchCase = flags => {
1530
- return (flags & MatchCase$1) === MatchCase$1;
1531
- };
1532
1537
  const hasDetailsExpanded = flags => {
1533
1538
  return (flags & DetailsExpanded) === DetailsExpanded;
1534
1539
  };
@@ -1641,7 +1646,7 @@ const focusSearchValue$1 = state => {
1641
1646
  };
1642
1647
 
1643
1648
  const focusSearchValueNext = state => {
1644
- if (hasReplaceExpanded(state.flags)) {
1649
+ if (state.flags & ReplaceExpanded) {
1645
1650
  return focusReplaceValue$1(state);
1646
1651
  }
1647
1652
  return focusMatchCase$1(state);
@@ -1654,6 +1659,7 @@ const Tree = 'tree';
1654
1659
  const TreeItem$1 = 'treeitem';
1655
1660
  const ToolBar = 'toolbar';
1656
1661
  const Button$2 = 'button';
1662
+ const Alert = 'alert';
1657
1663
 
1658
1664
  const Actions = 'Actions';
1659
1665
  const Badge = 'Badge';
@@ -1667,6 +1673,7 @@ const Highlight = 'Highlight';
1667
1673
  const HighlightDeleted = 'HighlightDeleted';
1668
1674
  const HighlightInserted = 'HighlightInserted';
1669
1675
  const IconButton = 'IconButton';
1676
+ const SearchInputError = 'SearchInputError';
1670
1677
  const Label = 'Label';
1671
1678
  const List = 'List';
1672
1679
  const MaskIcon = 'MaskIcon';
@@ -2155,17 +2162,17 @@ const getSearchHeaderDetailsVirtualDom = (flags, message) => {
2155
2162
  const getInputActionsInput = flags => {
2156
2163
  const inside = [{
2157
2164
  icon: MaskIconCaseSensitive,
2158
- checked: hasMatchCase(flags),
2165
+ checked: Boolean(flags & MatchCase$1),
2159
2166
  title: matchCase(),
2160
2167
  name: MatchCase
2161
2168
  }, {
2162
2169
  icon: MaskIconWholeWord,
2163
- checked: hasMatchWholeWord(flags),
2170
+ checked: Boolean(flags & MatchWholeWord$1),
2164
2171
  title: matchWholeWord(),
2165
2172
  name: MatchWholeWord
2166
2173
  }, {
2167
2174
  icon: MaskIconRegex,
2168
- checked: hasUseRegularExpression(flags),
2175
+ checked: Boolean(flags & UseRegularExpression$1),
2169
2176
  title: useRegularExpression(),
2170
2177
  name: UseRegularExpression
2171
2178
  }];
@@ -2179,7 +2186,7 @@ const getInputActionsInput = flags => {
2179
2186
  const getInputActionsReplace = flags => {
2180
2187
  const inside = [{
2181
2188
  icon: MaskIconPreserveCase,
2182
- checked: hasPreserveCase(flags),
2189
+ checked: Boolean(flags & PreserveCase$1),
2183
2190
  title: preserveCase(),
2184
2191
  name: PreserveCase
2185
2192
  }];
@@ -2198,16 +2205,16 @@ const getInputActionsReplace = flags => {
2198
2205
  const getSearchToggleVirtualDom = flags => {
2199
2206
  return [{
2200
2207
  type: Button,
2201
- className: mergeClassNames(IconButton, SearchToggleButton, hasReplaceExpanded(flags) ? SearchToggleButtonExpanded : ''),
2208
+ className: mergeClassNames(IconButton, SearchToggleButton, flags & ReplaceExpanded ? SearchToggleButtonExpanded : ''),
2202
2209
  title: toggleReplace$1(),
2203
2210
  ariaLabel: toggleReplace$1(),
2204
- ariaExpanded: hasReplaceExpanded(flags),
2211
+ ariaExpanded: Boolean(flags & ReplaceExpanded),
2205
2212
  childCount: 1,
2206
2213
  'data-command': 'toggleReplace',
2207
2214
  name: ToggleReplace
2208
2215
  }, {
2209
2216
  type: Div,
2210
- className: mergeClassNames(MaskIcon, hasReplaceExpanded(flags) ? MaskIconChevronDown : MaskIconChevronRight),
2217
+ className: mergeClassNames(MaskIcon, flags & ReplaceExpanded ? MaskIconChevronDown : MaskIconChevronRight),
2211
2218
  childCount: 0
2212
2219
  }];
2213
2220
  };
@@ -2224,9 +2231,9 @@ const getSearchHeaderTopVirtualDom = flags => {
2224
2231
  type: Div,
2225
2232
  className: SearchHeaderTopRight,
2226
2233
  role: None,
2227
- childCount: hasReplaceExpanded(flags) ? 2 : 1
2234
+ childCount: flags & ReplaceExpanded ? 2 : 1
2228
2235
  }, ...getSearchFieldVirtualDom(SearchValue, 'Search', HandleInput, inputActions.inside, inputActions.outside)];
2229
- if (hasReplaceExpanded(flags)) {
2236
+ if (flags & ReplaceExpanded) {
2230
2237
  dom.push(...getSearchFieldVirtualDom(ReplaceValue, 'Replace', HandleReplaceInput, replaceActions.inside, replaceActions.outside));
2231
2238
  }
2232
2239
  return dom;
@@ -2244,6 +2251,18 @@ const getSearchHeaderVirtualDom = (flags, message) => {
2244
2251
  return dom;
2245
2252
  };
2246
2253
 
2254
+ const getSearchInputErrorVirtualDom = errorMessage => {
2255
+ if (!errorMessage) {
2256
+ return [];
2257
+ }
2258
+ return [{
2259
+ type: Div,
2260
+ className: SearchInputError,
2261
+ role: Alert,
2262
+ childCount: 1
2263
+ }, text(errorMessage)];
2264
+ };
2265
+
2247
2266
  const getBadgeVirtualDom = (className, count) => {
2248
2267
  return [{
2249
2268
  type: Div,
@@ -2390,13 +2409,14 @@ const getSearchResultsVirtualDom = (visibleItems, focusOutline) => {
2390
2409
  }, ...visibleItems.flatMap(getSearchResultVirtualDom)];
2391
2410
  };
2392
2411
 
2393
- const getSearchVirtualDom = (visibleItems, flags, message, focusOutline) => {
2394
- const dom = [{
2412
+ const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchInputErrorMessage) => {
2413
+ const errorDom = getSearchInputErrorVirtualDom(searchInputErrorMessage);
2414
+ const childCount = 2 + (errorDom.length > 0 ? 1 : 0);
2415
+ return [{
2395
2416
  type: Div,
2396
2417
  className: mergeClassNames(Viewlet, Search$1),
2397
- childCount: 2
2398
- }, ...getSearchHeaderVirtualDom(flags, message), ...getSearchResultsVirtualDom(visibleItems, focusOutline)];
2399
- return dom;
2418
+ childCount
2419
+ }, ...getSearchHeaderVirtualDom(flags, message), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline)];
2400
2420
  };
2401
2421
 
2402
2422
  const handleError = error => {
@@ -2430,6 +2450,15 @@ const getNumberOfVisibleItems = (listHeight, itemHeight) => {
2430
2450
  return Math.ceil(listHeight / itemHeight) + 1;
2431
2451
  };
2432
2452
 
2453
+ const RE_PROTOCOL = /^([a-z-\d]+):\/\//;
2454
+ const getProtocol$1 = uri => {
2455
+ const protocolMatch = uri.match(RE_PROTOCOL);
2456
+ if (protocolMatch) {
2457
+ return protocolMatch[1];
2458
+ }
2459
+ return '';
2460
+ };
2461
+
2433
2462
  const getTextSearchResultCounts = results => {
2434
2463
  let resultCount = 0;
2435
2464
  let fileCount = 0;
@@ -2489,15 +2518,6 @@ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
2489
2518
  };
2490
2519
  };
2491
2520
 
2492
- const RE_PROTOCOL = /^([a-z-\d]+):\/\//;
2493
- const getProtocol$1 = uri => {
2494
- const protocolMatch = uri.match(RE_PROTOCOL);
2495
- if (protocolMatch) {
2496
- return protocolMatch[1];
2497
- }
2498
- return '';
2499
- };
2500
-
2501
2521
  const textSearch$6 = async (scheme, root, query) => {
2502
2522
  string(scheme);
2503
2523
  string(query);
@@ -2700,6 +2720,26 @@ const textSearch = async (root, query, options, assetDir, platform) => {
2700
2720
  return results;
2701
2721
  };
2702
2722
 
2723
+ // Based on https://github.com/microsoft/vscode/blob/ad375c92764b72a1f28f3e1626563e9e41e5c740/src/vs/workbench/contrib/search/browser/searchWidget.ts#L393 by Microsoft (License MIT)
2724
+
2725
+ const validateSearchInput = (value, flags) => {
2726
+ if (value.length === 0) {
2727
+ return '';
2728
+ }
2729
+ if (!(flags & UseRegularExpression$1)) {
2730
+ return '';
2731
+ }
2732
+ try {
2733
+ new RegExp(value, 'u');
2734
+ } catch (error) {
2735
+ if (error && error instanceof Error) {
2736
+ return error.message;
2737
+ }
2738
+ return '';
2739
+ }
2740
+ return '';
2741
+ };
2742
+
2703
2743
  const handleUpdate = async (state, update) => {
2704
2744
  const partialNewState = {
2705
2745
  ...state,
@@ -2713,7 +2753,9 @@ const handleUpdate = async (state, update) => {
2713
2753
  headerHeight,
2714
2754
  flags,
2715
2755
  value,
2716
- threads
2756
+ threads,
2757
+ includeValue,
2758
+ excludeValue
2717
2759
  } = partialNewState;
2718
2760
  if (isEmptyString(value)) {
2719
2761
  return {
@@ -2725,14 +2767,30 @@ const handleUpdate = async (state, update) => {
2725
2767
  listItems: [],
2726
2768
  matchCount: 0,
2727
2769
  message: '',
2728
- loaded: true
2770
+ loaded: true,
2771
+ searchInputErrorMessage: ''
2772
+ };
2773
+ }
2774
+ const searchInputErrorMessage = validateSearchInput(value, flags);
2775
+ if (searchInputErrorMessage) {
2776
+ return {
2777
+ ...partialNewState,
2778
+ searchInputErrorMessage: searchInputErrorMessage
2729
2779
  };
2730
2780
  }
2731
2781
  const root = state.workspacePath;
2782
+ const scheme = getProtocol$1(root);
2732
2783
  const results = await textSearch(root, value, {
2733
2784
  threads,
2734
- isCaseSensitive: hasMatchCase(flags),
2735
- useRegularExpression: hasUseRegularExpression(flags)
2785
+ isCaseSensitive: Boolean(flags & MatchCase$1),
2786
+ useRegularExpression: Boolean(flags & UseRegularExpression$1),
2787
+ exclude: excludeValue,
2788
+ include: includeValue,
2789
+ assetDir: state.assetDir,
2790
+ root,
2791
+ query: value,
2792
+ scheme,
2793
+ flags
2736
2794
  }, state.assetDir, state.platform);
2737
2795
  if (!Array.isArray(results)) {
2738
2796
  throw new TypeError('results must be of type array');
@@ -2794,6 +2852,16 @@ const noop = state => {
2794
2852
  return state;
2795
2853
  };
2796
2854
 
2855
+ const getReplacedMessage = (fileCount, replaceCount, replacement) => {
2856
+ if (replaceCount === 1) {
2857
+ return replacedOneOccurrenceInOneFile(replacement);
2858
+ }
2859
+ if (fileCount === 1) {
2860
+ return replacedManyOccurrencesInOneFile(replaceCount, replacement);
2861
+ }
2862
+ return replacedManyOccurrencesInManyFiles(replaceCount, fileCount, replacement);
2863
+ };
2864
+
2797
2865
  const getFileName = text => {
2798
2866
  // TODO make api stricter so that results always have the same shape
2799
2867
  if (text.startsWith('./')) {
@@ -2844,31 +2912,40 @@ const replaceAll = async state => {
2844
2912
  const {
2845
2913
  workspacePath,
2846
2914
  items,
2847
- replacement
2915
+ replacement,
2916
+ matchCount
2848
2917
  } = state;
2849
2918
  const bulkEdits = getReplaceElements(items, workspacePath, replacement);
2850
2919
  await invoke$2('BulkReplacement.applyBulkReplacement', bulkEdits);
2851
- return state;
2920
+ const fileCount = bulkEdits.length;
2921
+ const message = getReplacedMessage(fileCount, matchCount, replacement);
2922
+ return {
2923
+ ...state,
2924
+ items: [],
2925
+ listItems: [],
2926
+ minLineY: 0,
2927
+ maxLineY: 0,
2928
+ message
2929
+ };
2852
2930
  };
2853
2931
 
2854
2932
  const toggleSearchFlag = (state, flag) => {
2855
- return {
2856
- ...state,
2933
+ return handleUpdate(state, {
2857
2934
  flags: state.flags ^ flag
2858
- };
2935
+ });
2859
2936
  };
2860
2937
 
2861
- const collapseDetails = state => {
2938
+ const collapseDetails = async state => {
2862
2939
  return {
2863
- ...toggleSearchFlag(state, DetailsExpanded),
2940
+ ...(await toggleSearchFlag(state, DetailsExpanded)),
2864
2941
  focus: FocusSearchInput,
2865
2942
  focusSource: Script
2866
2943
  };
2867
2944
  };
2868
2945
 
2869
- const expandDetails = state => {
2946
+ const expandDetails = async state => {
2870
2947
  return {
2871
- ...toggleSearchFlag(state, DetailsExpanded),
2948
+ ...(await toggleSearchFlag(state, DetailsExpanded)),
2872
2949
  focus: FocusSearchIncludeInput,
2873
2950
  focusSource: Script
2874
2951
  };
@@ -2967,12 +3044,11 @@ const handleIconThemeChange = async state => {
2967
3044
  };
2968
3045
  };
2969
3046
 
2970
- const handleIncludeInput = (state, includeValue) => {
2971
- return {
2972
- ...state,
3047
+ const handleIncludeInput = (state, includeValue, inputSource = Script) => {
3048
+ return handleUpdate(state, {
2973
3049
  includeValue,
2974
- focusSource: User
2975
- };
3050
+ inputSource
3051
+ });
2976
3052
  };
2977
3053
 
2978
3054
  const handleInput = (state, value, inputSource = Script) => {
@@ -3492,12 +3568,12 @@ const getFocusSelector = focusKey => {
3492
3568
 
3493
3569
  const renderItems = {
3494
3570
  isEqual(oldState, newState) {
3495
- return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.replacement === newState.replacement && oldState.flags === newState.flags && oldState.message === newState.message && oldState.loaded === newState.loaded && oldState.collapsedPaths === newState.collapsedPaths && oldState.listFocusedIndex === newState.listFocusedIndex && oldState.listFocused === newState.listFocused && oldState.icons === newState.icons;
3571
+ return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.replacement === newState.replacement && oldState.flags === newState.flags && oldState.message === newState.message && oldState.loaded === newState.loaded && oldState.collapsedPaths === newState.collapsedPaths && oldState.listFocusedIndex === newState.listFocusedIndex && oldState.listFocused === newState.listFocused && oldState.icons === newState.icons && oldState.searchInputErrorMessage === newState.searchInputErrorMessage;
3496
3572
  },
3497
3573
  apply(oldState, newState) {
3498
3574
  const displayResults = getDisplayResults(newState.listItems, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.icons, newState.listFocusedIndex);
3499
3575
  const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
3500
- const dom = getSearchVirtualDom(displayResults, newState.flags, newState.message, focusOutline);
3576
+ const dom = getSearchVirtualDom(displayResults, newState.flags, newState.message, focusOutline, newState.searchInputErrorMessage);
3501
3577
  return ['Viewlet.setDom2', newState.uid, dom];
3502
3578
  }
3503
3579
  };
@@ -3531,8 +3607,7 @@ const renderIncludeValue = {
3531
3607
  return oldState.includeValue === newState.includeValue || newState.inputSource === User;
3532
3608
  },
3533
3609
  apply(oldState, newState) {
3534
- const selector = getFocusSelector(FocusSearchIncludeInput);
3535
- return ['Viewlet.send', newState.uid, 'setValue', newState.includeValue, selector];
3610
+ return ['Viewlet.send', newState.uid, 'setValue', newState.includeValue, `[name=${FilesToInclude}]`];
3536
3611
  }
3537
3612
  };
3538
3613
  const renderExcludeValue = {
@@ -3540,8 +3615,7 @@ const renderExcludeValue = {
3540
3615
  return oldState.excludeValue === newState.excludeValue || newState.inputSource === User;
3541
3616
  },
3542
3617
  apply(oldState, newState) {
3543
- const selector = getFocusSelector(FocusSearchExcludeInput);
3544
- return ['Viewlet.send', newState.uid, 'setValue', newState.excludeValue, selector];
3618
+ return ['Viewlet.send', newState.uid, 'setValue', newState.excludeValue, `[name=${FilesToExclude}]`];
3545
3619
  }
3546
3620
  };
3547
3621
  const render = [renderItems, renderValue, renderIncludeValue, renderExcludeValue, renderReplacement, renderFocus];
@@ -3666,7 +3740,7 @@ const focusSearchValue = state => {
3666
3740
  return focusElement(state, FocusSearchInput);
3667
3741
  };
3668
3742
  const focusMatchCasePrevious = state => {
3669
- if (hasReplaceExpanded(state.flags)) {
3743
+ if (state.flags & ReplaceExpanded) {
3670
3744
  return focusReplaceValue(state);
3671
3745
  }
3672
3746
  return focusSearchValue(state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "3.24.0",
3
+ "version": "3.25.0",
4
4
  "description": "Text Search Worker",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",