@lvce-editor/text-search-worker 3.22.0 → 3.24.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.
@@ -598,10 +598,10 @@ const create$4 = (method, params) => {
598
598
  };
599
599
  };
600
600
  const callbacks = Object.create(null);
601
- const set$1 = (id, fn) => {
601
+ const set$2 = (id, fn) => {
602
602
  callbacks[id] = fn;
603
603
  };
604
- const get$1 = id => {
604
+ const get$2 = id => {
605
605
  return callbacks[id];
606
606
  };
607
607
  const remove$1 = id => {
@@ -617,7 +617,7 @@ const registerPromise = () => {
617
617
  resolve,
618
618
  promise
619
619
  } = Promise.withResolvers();
620
- set$1(id, resolve);
620
+ set$2(id, resolve);
621
621
  return {
622
622
  id,
623
623
  promise
@@ -774,7 +774,7 @@ const warn = (...args) => {
774
774
  console.warn(...args);
775
775
  };
776
776
  const resolve = (id, response) => {
777
- const fn = get$1(id);
777
+ const fn = get$2(id);
778
778
  if (!fn) {
779
779
  console.log(response);
780
780
  warn(`callback ${id} may already be disposed`);
@@ -1085,22 +1085,26 @@ const clearSearchResults$1 = state => {
1085
1085
  };
1086
1086
  };
1087
1087
 
1088
- const state$2 = {
1089
- rpc: undefined
1088
+ const RendererWorker = 1;
1089
+
1090
+ const rpcs = Object.create(null);
1091
+ const set$1 = (id, rpc) => {
1092
+ rpcs[id] = rpc;
1093
+ };
1094
+ const get$1 = id => {
1095
+ return rpcs[id];
1090
1096
  };
1097
+
1091
1098
  const invoke$2 = (method, ...params) => {
1092
- const rpc = state$2.rpc;
1099
+ const rpc = get$1(RendererWorker);
1093
1100
  // @ts-ignore
1094
1101
  return rpc.invoke(method, ...params);
1095
1102
  };
1096
1103
  const invokeAndTransfer = (method, ...params) => {
1097
- const rpc = state$2.rpc;
1104
+ const rpc = get$1(RendererWorker);
1098
1105
  // @ts-ignore
1099
1106
  return rpc.invokeAndTransfer(method, ...params);
1100
1107
  };
1101
- const setRpc = rpc => {
1102
- state$2.rpc = rpc;
1103
- };
1104
1108
 
1105
1109
  const copy = async state => {
1106
1110
  const {
@@ -1200,21 +1204,6 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
1200
1204
 
1201
1205
  // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1202
1206
 
1203
- const insertInto = (array, start, newItems) => {
1204
- const originalLength = array.length;
1205
- const newItemsLength = newItems.length;
1206
- array.length = originalLength + newItemsLength;
1207
- // Move the items after the start index, start from the end so that we don't overwrite any value.
1208
- for (let i = originalLength - 1; i >= start; i--) {
1209
- array[i + newItemsLength] = array[i];
1210
- }
1211
- for (let i = 0; i < newItemsLength; i++) {
1212
- array[i + start] = newItems[i];
1213
- }
1214
- };
1215
- const push = (array, newItems) => {
1216
- insertInto(array, array.length, newItems);
1217
- };
1218
1207
  const isLastIndex = (array, index) => {
1219
1208
  return index === array.length - 1;
1220
1209
  };
@@ -2509,21 +2498,25 @@ const getProtocol$1 = uri => {
2509
2498
  return '';
2510
2499
  };
2511
2500
 
2512
- const textSearch$5 = async (scheme, root, query) => {
2501
+ const textSearch$6 = async (scheme, root, query) => {
2513
2502
  string(scheme);
2514
2503
  string(query);
2515
2504
  const result = await invoke$2('ExtensionHostTextSearch.executeTextSearchProvider', scheme, query);
2516
2505
  return result;
2517
2506
  };
2518
2507
 
2519
- const textSearch$4 = async (scheme, root, query, options, assetDir) => {
2508
+ const textSearch$5 = async (scheme, root, query, options, assetDir) => {
2520
2509
  return invoke$2('ExtensionHostTextSearch.textSearchFetch', scheme, root, query, options, assetDir);
2521
2510
  };
2522
2511
 
2523
- const textSearch$3 = async (scheme, root, query) => {
2512
+ const textSearch$4 = async (scheme, root, query) => {
2524
2513
  return invoke$2('ExtensionHostTextSearch.textSearchHtml', scheme, root, query);
2525
2514
  };
2526
2515
 
2516
+ const textSearch$3 = async (scheme, root, query, options, assetDir) => {
2517
+ return invoke$2('ExtensionHostTextSearch.textSearchMemory', scheme, root, query, options, assetDir);
2518
+ };
2519
+
2527
2520
  const getRipGrepArgs = ({
2528
2521
  threads,
2529
2522
  isCaseSensitive,
@@ -2688,11 +2681,13 @@ const getProvider = scheme => {
2688
2681
  case 'web':
2689
2682
  return textSearch$1;
2690
2683
  case 'fetch':
2691
- return textSearch$4;
2684
+ return textSearch$5;
2692
2685
  case 'html':
2686
+ return textSearch$4;
2687
+ case 'memfs':
2693
2688
  return textSearch$3;
2694
2689
  default:
2695
- return textSearch$5;
2690
+ return textSearch$6;
2696
2691
  }
2697
2692
  };
2698
2693
 
@@ -2795,36 +2790,54 @@ const handleExcludeInput = (state, value, inputSource = Script) => {
2795
2790
  });
2796
2791
  };
2797
2792
 
2798
- const getBulkReplacementEdits = (workspacePath, matches) => {
2799
- string(workspacePath);
2800
- array(matches);
2801
- const files = [];
2802
- const ranges = [];
2803
- let currentRanges = [];
2804
- for (const match of matches) {
2793
+ const noop = state => {
2794
+ return state;
2795
+ };
2796
+
2797
+ const getFileName = text => {
2798
+ // TODO make api stricter so that results always have the same shape
2799
+ if (text.startsWith('./')) {
2800
+ return text.slice(2);
2801
+ }
2802
+ return text;
2803
+ };
2804
+
2805
+ const getReplaceElements = (items, workspacePath, replacement) => {
2806
+ let element = {
2807
+ uri: '',
2808
+ changes: []
2809
+ };
2810
+ const bulkChanges = [];
2811
+ let changes = [];
2812
+ // TODO simplify code by first matching files with their elements, then creating bulk edits
2813
+ for (const match of items) {
2805
2814
  const {
2806
2815
  type,
2807
- text
2816
+ text,
2817
+ lineNumber,
2818
+ end,
2819
+ start
2808
2820
  } = match;
2809
- switch (type) {
2810
- case File:
2811
- ranges.push(currentRanges.length);
2812
- push(ranges, currentRanges);
2813
- const absolutePath = `${workspacePath}/${text.slice(2)}`;
2814
- files.push(absolutePath);
2815
- currentRanges = [];
2816
- break;
2817
- case Match:
2818
- currentRanges.push(match.lineNumber - 1, match.matchStart, match.lineNumber - 1, match.matchStart + match.matchLength);
2819
- break;
2821
+ if (type === File) {
2822
+ changes = [];
2823
+ const fileName = getFileName(text);
2824
+ const absolutePath = `${workspacePath}/${fileName}`;
2825
+ element = {
2826
+ uri: absolutePath,
2827
+ changes
2828
+ };
2829
+ bulkChanges.push(element);
2830
+ } else {
2831
+ changes.push({
2832
+ text: replacement,
2833
+ startRowIndex: lineNumber - 1,
2834
+ startColumnIndex: start,
2835
+ endRowIndex: lineNumber,
2836
+ endColumnIndex: end
2837
+ });
2820
2838
  }
2821
2839
  }
2822
- ranges.push(currentRanges.length);
2823
- push(ranges, currentRanges);
2824
- return {
2825
- files,
2826
- ranges: ranges.slice(1)
2827
- };
2840
+ return bulkChanges;
2828
2841
  };
2829
2842
 
2830
2843
  const replaceAll = async state => {
@@ -2833,11 +2846,8 @@ const replaceAll = async state => {
2833
2846
  items,
2834
2847
  replacement
2835
2848
  } = state;
2836
- const {
2837
- files,
2838
- ranges
2839
- } = getBulkReplacementEdits(workspacePath, items);
2840
- await invoke$2('BulkReplacement.applyBulkReplacement', files, ranges, replacement);
2849
+ const bulkEdits = getReplaceElements(items, workspacePath, replacement);
2850
+ await invoke$2('BulkReplacement.applyBulkReplacement', bulkEdits);
2841
2851
  return state;
2842
2852
  };
2843
2853
 
@@ -2928,6 +2938,11 @@ const getClickHandler = name => {
2928
2938
  case UseExcludeSettings:
2929
2939
  // @ts-ignore
2930
2940
  return toggleUseIgnoreFiles;
2941
+ case SearchValue:
2942
+ case ReplaceValue:
2943
+ case FilesToExclude:
2944
+ case FilesToInclude:
2945
+ return noop;
2931
2946
  default:
2932
2947
  throw new Error(`Click handler not found: ${name}`);
2933
2948
  }
@@ -3500,7 +3515,7 @@ const renderValue = {
3500
3515
  return oldState.value === newState.value || newState.inputSource === User;
3501
3516
  },
3502
3517
  apply(oldState, newState) {
3503
- return ['Viewlet.send', newState.uid, 'setValue', newState.value, '[name="search-value"]'];
3518
+ return ['Viewlet.send', newState.uid, 'setValue', newState.value, `[name="${SearchValue}"]`];
3504
3519
  }
3505
3520
  };
3506
3521
  const renderReplacement = {
@@ -3508,8 +3523,7 @@ const renderReplacement = {
3508
3523
  return oldState.replacement === newState.replacement || newState.inputSource === User;
3509
3524
  },
3510
3525
  apply(oldState, newState) {
3511
- const selector = getFocusSelector(FocusSearchReplaceInput);
3512
- return ['Viewlet.send', newState.uid, 'setValue', newState.replacement, selector];
3526
+ return ['Viewlet.send', newState.uid, 'setValue', newState.replacement, `[name=${ReplaceValue}]`];
3513
3527
  }
3514
3528
  };
3515
3529
  const renderIncludeValue = {
@@ -3826,7 +3840,7 @@ const listen = async () => {
3826
3840
  const rpc = await WebWorkerRpcClient.create({
3827
3841
  commandMap: commandMap
3828
3842
  });
3829
- setRpc(rpc);
3843
+ set$1(RendererWorker, rpc);
3830
3844
  };
3831
3845
 
3832
3846
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "3.22.0",
3
+ "version": "3.24.0",
4
4
  "description": "Text Search Worker",
5
5
  "main": "dist/textSearchWorkerMain.js",
6
6
  "type": "module",