@lvce-editor/text-search-worker 4.8.0 → 4.10.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.
@@ -356,22 +356,11 @@ class IpcChildWithModuleWorker extends Ipc {
356
356
  const wrap$f = global => {
357
357
  return new IpcChildWithModuleWorker(global);
358
358
  };
359
- const withResolvers = () => {
360
- let _resolve;
361
- const promise = new Promise(resolve => {
362
- _resolve = resolve;
363
- });
364
- return {
365
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
366
- resolve: _resolve,
367
- promise
368
- };
369
- };
370
359
  const waitForFirstMessage = async port => {
371
360
  const {
372
361
  resolve,
373
362
  promise
374
- } = withResolvers();
363
+ } = Promise.withResolvers();
375
364
  port.addEventListener('message', resolve, {
376
365
  once: true
377
366
  });
@@ -453,7 +442,7 @@ const getFirstEvent = (eventEmitter, eventMap) => {
453
442
  const {
454
443
  resolve,
455
444
  promise
456
- } = withResolvers();
445
+ } = Promise.withResolvers();
457
446
  const listenerMap = Object.create(null);
458
447
  const cleanup = value => {
459
448
  for (const event of Object.keys(eventMap)) {
@@ -591,7 +580,7 @@ const IpcParentWithWebSocket$1 = {
591
580
  };
592
581
 
593
582
  const Two = '2.0';
594
- const create$4 = (method, params) => {
583
+ const create$4$1 = (method, params) => {
595
584
  return {
596
585
  jsonrpc: Two,
597
586
  method,
@@ -691,6 +680,16 @@ const constructError = (message, type, name) => {
691
680
  }
692
681
  return new ErrorConstructor(message);
693
682
  };
683
+ const joinLines = lines => {
684
+ return lines.join(NewLine);
685
+ };
686
+ const splitLines = lines => {
687
+ return lines.split(NewLine);
688
+ };
689
+ const getCurrentStack = () => {
690
+ const currentStack = joinLines(splitLines(new Error().stack || '').slice(2));
691
+ return currentStack;
692
+ };
694
693
  const getNewLineIndex = (string, startIndex = undefined) => {
695
694
  return string.indexOf(NewLine, startIndex);
696
695
  };
@@ -701,19 +700,16 @@ const getParentStack = error => {
701
700
  }
702
701
  return parentStack;
703
702
  };
704
- const joinLines = lines => {
705
- return lines.join(NewLine);
706
- };
707
703
  const MethodNotFound = -32601;
708
704
  const Custom = -32001;
709
- const splitLines = lines => {
710
- return lines.split(NewLine);
711
- };
712
705
  const restoreJsonRpcError = error => {
706
+ const currentStack = getCurrentStack();
713
707
  if (error && error instanceof Error) {
708
+ if (typeof error.stack === 'string') {
709
+ error.stack = error.stack + NewLine + currentStack;
710
+ }
714
711
  return error;
715
712
  }
716
- const currentStack = joinLines(splitLines(new Error().stack || '').slice(1));
717
713
  if (error && error.code && error.code === MethodNotFound) {
718
714
  const restoredError = new JsonRpcError(error.message);
719
715
  const parentStack = getParentStack(error);
@@ -794,6 +790,17 @@ const getErrorType = prettyError => {
794
790
  }
795
791
  return undefined;
796
792
  };
793
+ const isAlreadyStack = line => {
794
+ return line.trim().startsWith('at ');
795
+ };
796
+ const getStack = prettyError => {
797
+ const stackString = prettyError.stack || '';
798
+ const newLineIndex = stackString.indexOf('\n');
799
+ if (newLineIndex !== -1 && !isAlreadyStack(stackString.slice(0, newLineIndex))) {
800
+ return stackString.slice(newLineIndex + 1);
801
+ }
802
+ return stackString;
803
+ };
797
804
  const getErrorProperty = (error, prettyError) => {
798
805
  if (error && error.code === E_COMMAND_NOT_FOUND) {
799
806
  return {
@@ -806,7 +813,7 @@ const getErrorProperty = (error, prettyError) => {
806
813
  code: Custom,
807
814
  message: prettyError.message,
808
815
  data: {
809
- stack: prettyError.stack,
816
+ stack: getStack(prettyError),
810
817
  codeFrame: prettyError.codeFrame,
811
818
  type: getErrorType(prettyError),
812
819
  code: prettyError.code,
@@ -814,18 +821,18 @@ const getErrorProperty = (error, prettyError) => {
814
821
  }
815
822
  };
816
823
  };
817
- const create$1$2 = (message, error) => {
824
+ const create$1$2 = (id, error) => {
818
825
  return {
819
826
  jsonrpc: Two,
820
- id: message.id,
827
+ id,
821
828
  error
822
829
  };
823
830
  };
824
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
831
+ const getErrorResponse = (id, error, preparePrettyError, logError) => {
825
832
  const prettyError = preparePrettyError(error);
826
833
  logError(error, prettyError);
827
834
  const errorProperty = getErrorProperty(error, prettyError);
828
- return create$1$2(message, errorProperty);
835
+ return create$1$2(id, errorProperty);
829
836
  };
830
837
  const create$5 = (message, result) => {
831
838
  return {
@@ -838,12 +845,27 @@ const getSuccessResponse = (message, result) => {
838
845
  const resultProperty = result ?? null;
839
846
  return create$5(message, resultProperty);
840
847
  };
848
+ const getErrorResponseSimple = (id, error) => {
849
+ return {
850
+ jsonrpc: Two,
851
+ id,
852
+ error: {
853
+ code: Custom,
854
+ // @ts-ignore
855
+ message: error.message,
856
+ data: error
857
+ }
858
+ };
859
+ };
841
860
  const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
842
861
  try {
843
862
  const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
844
863
  return getSuccessResponse(message, result);
845
864
  } catch (error) {
846
- return getErrorResponse(message, error, preparePrettyError, logError);
865
+ if (ipc.canUseSimpleErrorResponse) {
866
+ return getErrorResponseSimple(message.id, error);
867
+ }
868
+ return getErrorResponse(message.id, error, preparePrettyError, logError);
847
869
  }
848
870
  };
849
871
  const defaultPreparePrettyError = error => {
@@ -898,7 +920,7 @@ const handleJsonRpcMessage = async (...args) => {
898
920
  try {
899
921
  ipc.send(response);
900
922
  } catch (error) {
901
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
923
+ const errorResponse = getErrorResponse(message.id, error, preparePrettyError, logError);
902
924
  ipc.send(errorResponse);
903
925
  }
904
926
  return;
@@ -926,10 +948,10 @@ const invokeHelper = async (ipc, method, params, useSendAndTransfer) => {
926
948
  return unwrapJsonRpcResult(responseMessage);
927
949
  };
928
950
  const send = (transport, method, ...params) => {
929
- const message = create$4(method, params);
951
+ const message = create$4$1(method, params);
930
952
  transport.send(message);
931
953
  };
932
- const invoke$3 = (ipc, method, ...params) => {
954
+ const invoke$4 = (ipc, method, ...params) => {
933
955
  return invokeHelper(ipc, method, params, false);
934
956
  };
935
957
  const invokeAndTransfer$1 = (ipc, method, ...params) => {
@@ -962,7 +984,7 @@ const createRpc = ipc => {
962
984
  send(ipc, method, ...params);
963
985
  },
964
986
  invoke(method, ...params) {
965
- return invoke$3(ipc, method, ...params);
987
+ return invoke$4(ipc, method, ...params);
966
988
  },
967
989
  invokeAndTransfer(method, ...params) {
968
990
  return invokeAndTransfer$1(ipc, method, ...params);
@@ -1003,7 +1025,7 @@ const listen$1 = async (module, options) => {
1003
1025
  const ipc = module.wrap(rawIpc);
1004
1026
  return ipc;
1005
1027
  };
1006
- const create$7 = async ({
1028
+ const create$9 = async ({
1007
1029
  commandMap,
1008
1030
  messagePort,
1009
1031
  isMessagePortOpen
@@ -1021,7 +1043,7 @@ const create$7 = async ({
1021
1043
  };
1022
1044
  const MessagePortRpcParent = {
1023
1045
  __proto__: null,
1024
- create: create$7
1046
+ create: create$9
1025
1047
  };
1026
1048
  const create$1$1 = async ({
1027
1049
  commandMap,
@@ -1041,7 +1063,7 @@ const WebSocketRpcParent = {
1041
1063
  __proto__: null,
1042
1064
  create: create$1$1
1043
1065
  };
1044
- const create$3 = async ({
1066
+ const create$4 = async ({
1045
1067
  commandMap
1046
1068
  }) => {
1047
1069
  // TODO create a commandMap per rpc instance
@@ -1053,7 +1075,7 @@ const create$3 = async ({
1053
1075
  };
1054
1076
  const WebWorkerRpcClient = {
1055
1077
  __proto__: null,
1056
- create: create$3
1078
+ create: create$4
1057
1079
  };
1058
1080
 
1059
1081
  const User = 1;
@@ -1118,27 +1140,54 @@ const collapseDetails = state => {
1118
1140
  };
1119
1141
  };
1120
1142
 
1121
- const RendererWorker = 1;
1122
-
1123
1143
  const rpcs = Object.create(null);
1124
- const set$1 = (id, rpc) => {
1144
+ const set$d = (id, rpc) => {
1125
1145
  rpcs[id] = rpc;
1126
1146
  };
1127
1147
  const get$1 = id => {
1128
1148
  return rpcs[id];
1129
1149
  };
1130
1150
 
1131
- const invoke$2 = (method, ...params) => {
1132
- const rpc = get$1(RendererWorker);
1133
- // @ts-ignore
1134
- return rpc.invoke(method, ...params);
1151
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
1152
+
1153
+ const create$3 = rpcId => {
1154
+ return {
1155
+ // @ts-ignore
1156
+ invoke(method, ...params) {
1157
+ const rpc = get$1(rpcId);
1158
+ // @ts-ignore
1159
+ return rpc.invoke(method, ...params);
1160
+ },
1161
+ // @ts-ignore
1162
+ invokeAndTransfer(method, ...params) {
1163
+ const rpc = get$1(rpcId);
1164
+ // @ts-ignore
1165
+ return rpc.invokeAndTransfer(method, ...params);
1166
+ },
1167
+ set(rpc) {
1168
+ set$d(rpcId, rpc);
1169
+ }
1170
+ };
1135
1171
  };
1136
- const invokeAndTransfer = (method, ...params) => {
1137
- const rpc = get$1(RendererWorker);
1138
- // @ts-ignore
1139
- return rpc.invokeAndTransfer(method, ...params);
1172
+ const RendererWorker$1 = 1;
1173
+ const {
1174
+ invoke: invoke$3,
1175
+ invokeAndTransfer: invokeAndTransfer$3,
1176
+ set: set$3
1177
+ } = create$3(RendererWorker$1);
1178
+ const RendererWorker = {
1179
+ __proto__: null,
1180
+ invoke: invoke$3,
1181
+ invokeAndTransfer: invokeAndTransfer$3,
1182
+ set: set$3
1140
1183
  };
1141
1184
 
1185
+ const {
1186
+ invoke: invoke$2,
1187
+ invokeAndTransfer,
1188
+ set: set$1
1189
+ } = RendererWorker;
1190
+
1142
1191
  const copy = async state => {
1143
1192
  const {
1144
1193
  items,
@@ -1219,6 +1268,8 @@ const {
1219
1268
  wrapCommand
1220
1269
  } = create$2();
1221
1270
 
1271
+ const List$1 = 1;
1272
+
1222
1273
  const create$1 = ({
1223
1274
  itemHeight,
1224
1275
  headerHeight = 0,
@@ -1248,7 +1299,6 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
1248
1299
  uid,
1249
1300
  searchResults: [],
1250
1301
  stats: {},
1251
- searchId: -1,
1252
1302
  value,
1253
1303
  disposed: false,
1254
1304
  fileCount: 0,
@@ -1286,7 +1336,10 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
1286
1336
  platform,
1287
1337
  searchInputErrorMessage: '',
1288
1338
  history: [],
1289
- historyIndex: -1
1339
+ historyIndex: -1,
1340
+ viewMode: List$1,
1341
+ incrementalSearch: false,
1342
+ searchId: ''
1290
1343
  };
1291
1344
  set(uid, state, state);
1292
1345
  return state;
@@ -1820,7 +1873,7 @@ const focusSearchValueNext = state => {
1820
1873
  return focusMatchCase$1(state);
1821
1874
  };
1822
1875
 
1823
- const commandIds = ['clearSearchResults', 'collapseAll', 'collapseDetails', 'copy', 'dismissItem', 'dispose', 'expandDetails', 'focusFirst', 'focusIndex', 'focusLast', 'focusMatchCase', 'focusMatchCasePrevious', 'focusMatchWholeWord', 'focusNext', 'focusNextInput', 'focusNextPage', 'focusPreserveCasePrevious', 'focusPrevious', 'focusPreviousInput', 'focusPreviousPage', 'focusRegex', 'focusRegexNext', 'focusReplaceAll', 'focusReplaceValue', 'focusReplaceValueNext', 'focusReplaceValuePrevious', 'focusSearchValue', 'focusSearchValueNext', 'handleClick', 'handleClickAt', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleContextMenuMouseAt', 'handleExcludeInput', 'handleFocusIn', 'handleHeaderClick', 'handleHeaderContextMenu', 'handleHeaderFocusIn', 'handleHeaderFocusOut', 'handleIconThemeChange', 'handleIconThemeChange', 'handleIncludeInput', 'handleInput', 'handleInput2', 'handleListBlur', 'handleListFocus', 'handleReplaceInput', 'handleScrollBarCaptureLost', 'handleScrollBarClick', 'handleScrollBarMove', 'handleScrollBarThumbPointerMove', 'handleTouchEnd', 'handleTouchMove', 'handleTouchStart', 'handleUpdate', 'handleWheel', 'nextHistoryResult', 'previousHistoryResult', 'refresh', 'replaceAll', 'scrollDown', 'selectIndex', 'submit', 'toggleMatchCase', 'toggleMatchWholeWord', 'togglePreserveCase', 'toggleReplace', 'toggleSearchDetails', 'toggleUseRegularExpression', 'viewAsTree'];
1876
+ const commandIds = ['clearSearchResults', 'collapseAll', 'collapseDetails', 'copy', 'dismissItem', 'dispose', 'expandDetails', 'focusFirst', 'focusIndex', 'focusLast', 'focusMatchCase', 'focusMatchCasePrevious', 'focusMatchWholeWord', 'focusNext', 'focusNextInput', 'focusNextPage', 'focusPreserveCasePrevious', 'focusPrevious', 'focusPreviousInput', 'focusPreviousPage', 'focusRegex', 'focusRegexNext', 'focusReplaceAll', 'focusReplaceValue', 'focusReplaceValueNext', 'focusReplaceValuePrevious', 'focusSearchValue', 'focusSearchValueNext', 'handleClick', 'handleClickAt', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleContextMenuMouseAt', 'handleExcludeInput', 'handleFocusIn', 'handleHeaderClick', 'handleHeaderContextMenu', 'handleHeaderFocusIn', 'handleHeaderFocusOut', 'handleIconThemeChange', 'handleIconThemeChange', 'handleIncludeInput', 'handleInput', 'handleInput2', 'handleListBlur', 'handleListFocus', 'handleReplaceInput', 'handleScrollBarCaptureLost', 'handleScrollBarClick', 'handleScrollBarMove', 'handleScrollBarThumbPointerMove', 'handleTouchEnd', 'handleTouchMove', 'handleTouchStart', 'handleUpdate', 'handleWheel', 'nextHistoryResult', 'previousHistoryResult', 'refresh', 'replaceAll', 'rerender', 'scrollDown', 'selectIndex', 'submit', 'toggleMatchCase', 'toggleMatchWholeWord', 'togglePreserveCase', 'toggleReplace', 'toggleSearchDetails', 'toggleUseRegularExpression', 'viewAsTree'];
1824
1877
 
1825
1878
  const getCommandIds = () => {
1826
1879
  return commandIds;
@@ -1907,6 +1960,42 @@ const handleError = error => {
1907
1960
  console.error(`[text-search-worker] ${error}`);
1908
1961
  };
1909
1962
 
1963
+ const handleUpdateEmpty = (state, update) => {
1964
+ const partialNewState = {
1965
+ ...state,
1966
+ ...update
1967
+ };
1968
+ return {
1969
+ ...partialNewState,
1970
+ minLineY: 0,
1971
+ maxLineY: 0,
1972
+ deltaY: 0,
1973
+ items: [],
1974
+ listItems: [],
1975
+ matchCount: 0,
1976
+ message: '',
1977
+ loaded: true,
1978
+ searchInputErrorMessage: ''
1979
+ };
1980
+ };
1981
+
1982
+ const handleUpdateError = async (state, update, error) => {
1983
+ const partialNewState = {
1984
+ ...state,
1985
+ ...update
1986
+ };
1987
+ return {
1988
+ ...partialNewState,
1989
+ message: `${error}`,
1990
+ items: [],
1991
+ listItems: [],
1992
+ matchCount: 0,
1993
+ fileCount: 0,
1994
+ minLineY: 0,
1995
+ maxLineY: 0
1996
+ };
1997
+ };
1998
+
1910
1999
  const getFileIcon = async result => {
1911
2000
  if (result.type === File) {
1912
2001
  return invoke$2('IconTheme.getFileIcon', {
@@ -1957,12 +2046,6 @@ const getTextSearchResultCounts = results => {
1957
2046
  };
1958
2047
  };
1959
2048
 
1960
- const EmptyString = '';
1961
-
1962
- const isEmptyString = string => {
1963
- return string === EmptyString;
1964
- };
1965
-
1966
2049
  const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
1967
2050
  if (size >= contentSize) {
1968
2051
  return 0;
@@ -2058,7 +2141,6 @@ const state$1 = {
2058
2141
  };
2059
2142
  const getOrCreate$1 = () => {
2060
2143
  if (!state$1.rpc) {
2061
- // @ts-ignore
2062
2144
  state$1.rpc = launchSearchProcess();
2063
2145
  }
2064
2146
  return state$1.rpc;
@@ -2135,7 +2217,7 @@ const textSearch$2 = async (scheme, root, query, options, assetDir, platform) =>
2135
2217
  return results.results;
2136
2218
  };
2137
2219
 
2138
- const textSearch$1 = (scheme, root, query) => {
2220
+ const textSearch$1 = async (scheme, root, query) => {
2139
2221
  // TODO ask renderer worker for files
2140
2222
  const entries = Object.entries({});
2141
2223
  const results = [];
@@ -2177,6 +2259,185 @@ const textSearch = async (root, query, options, assetDir, platform) => {
2177
2259
  return results;
2178
2260
  };
2179
2261
 
2262
+ const handleUpdateFull = async (state, update) => {
2263
+ const partialNewState = {
2264
+ ...state,
2265
+ ...update
2266
+ };
2267
+ const {
2268
+ height,
2269
+ itemHeight,
2270
+ minimumSliderSize,
2271
+ headerHeight,
2272
+ flags,
2273
+ value,
2274
+ threads,
2275
+ includeValue,
2276
+ excludeValue
2277
+ } = partialNewState;
2278
+ const root = state.workspacePath;
2279
+ const scheme = getProtocol$1(root);
2280
+ const results = await textSearch(root, value, {
2281
+ threads,
2282
+ isCaseSensitive: Boolean(flags & MatchCase$2),
2283
+ useRegularExpression: Boolean(flags & UseRegularExpression$2),
2284
+ exclude: excludeValue,
2285
+ include: includeValue,
2286
+ assetDir: state.assetDir,
2287
+ root,
2288
+ query: value,
2289
+ scheme,
2290
+ flags,
2291
+ matchWholeWord: Boolean(flags & MatchWholeWord$2)
2292
+ }, state.assetDir, state.platform);
2293
+ if (!Array.isArray(results)) {
2294
+ throw new TypeError('results must be of type array');
2295
+ }
2296
+ const {
2297
+ fileCount,
2298
+ resultCount
2299
+ } = getTextSearchResultCounts(results);
2300
+ const message = getStatusMessage(resultCount, fileCount);
2301
+ const total = results.length;
2302
+ const contentHeight = total * itemHeight;
2303
+ const listHeight = height - headerHeight;
2304
+ const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
2305
+ const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
2306
+ const maxLineY = Math.min(numberOfVisible, total);
2307
+ const finalDeltaY = Math.max(contentHeight - listHeight, 0);
2308
+ const visible = results.slice(0, maxLineY);
2309
+ const icons = await getFileIcons(visible);
2310
+ return {
2311
+ ...partialNewState,
2312
+ minLineY: 0,
2313
+ deltaY: 0,
2314
+ value,
2315
+ items: results,
2316
+ listItems: results,
2317
+ message,
2318
+ maxLineY: maxLineY,
2319
+ scrollBarHeight,
2320
+ finalDeltaY,
2321
+ threads,
2322
+ fileCount,
2323
+ matchCount: resultCount,
2324
+ loaded: true,
2325
+ icons,
2326
+ searchInputErrorMessage: ''
2327
+ };
2328
+ };
2329
+
2330
+ const waitForNextFrame = async () => {
2331
+ await new Promise(r => {
2332
+ requestAnimationFrame(r);
2333
+ });
2334
+ };
2335
+ const textSearchIncremental = async (root, query, options, assetDir, platform, searchId, uid) => {
2336
+ string(root);
2337
+ string(query);
2338
+ const ripGrepArgs = getRipGrepArgs({
2339
+ ...options,
2340
+ searchString: query
2341
+ });
2342
+ const actualOptions = {
2343
+ ripGrepArgs,
2344
+ searchDir: root,
2345
+ id: searchId
2346
+ };
2347
+ const resultPromise = invoke$1('TextSearch.searchIncremental', actualOptions);
2348
+ for (let i = 0; i < 100; i++) {
2349
+ const latest = get(uid);
2350
+ const {
2351
+ newState
2352
+ } = latest;
2353
+ const {
2354
+ minLineY,
2355
+ height,
2356
+ headerHeight,
2357
+ itemHeight
2358
+ } = newState;
2359
+ const listHeight = height - headerHeight;
2360
+ const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
2361
+ const visible = await invoke$1('TextSearch.getIncrementalResults', searchId, minLineY, minLineY + numberOfVisible);
2362
+ const latest2 = get(uid);
2363
+ if (!latest2 || latest2.newState.searchId !== searchId) {
2364
+ return;
2365
+ }
2366
+ const updatedState2 = {
2367
+ ...latest2.newState,
2368
+ items: visible,
2369
+ listItems: visible,
2370
+ minLineY: 0,
2371
+ maxLineY: visible.length
2372
+ };
2373
+ set(uid, latest2.oldState, updatedState2);
2374
+ // @ts-ignore
2375
+ await invoke$2('Search.rerender');
2376
+ await waitForNextFrame();
2377
+ }
2378
+ await resultPromise;
2379
+ };
2380
+
2381
+ const handleUpdateIncremental = async (state, update) => {
2382
+ const partialNewState = {
2383
+ ...state,
2384
+ ...update
2385
+ };
2386
+ const {
2387
+ flags,
2388
+ value,
2389
+ threads,
2390
+ includeValue,
2391
+ excludeValue,
2392
+ uid,
2393
+ assetDir,
2394
+ platform
2395
+ } = partialNewState;
2396
+ const root = state.workspacePath;
2397
+ const scheme = getProtocol$1(root);
2398
+ const searchId = crypto.randomUUID(); // TODO try to avoid side effect
2399
+ const latest1 = get(uid);
2400
+ const updatedState1 = {
2401
+ ...latest1.newState,
2402
+ ...partialNewState,
2403
+ searchId
2404
+ };
2405
+ set(uid, latest1.oldState, updatedState1);
2406
+
2407
+ // TODO await promise?
2408
+ void textSearchIncremental(root, value, {
2409
+ threads,
2410
+ isCaseSensitive: Boolean(flags & MatchCase$2),
2411
+ useRegularExpression: Boolean(flags & UseRegularExpression$2),
2412
+ exclude: excludeValue,
2413
+ include: includeValue,
2414
+ assetDir: assetDir,
2415
+ root,
2416
+ query: value,
2417
+ scheme,
2418
+ flags,
2419
+ matchWholeWord: Boolean(flags & MatchWholeWord$2)
2420
+ }, assetDir, platform, searchId, uid);
2421
+ return state;
2422
+ };
2423
+
2424
+ const handleUpdateValidationError = (state, update, searchInputErrorMessage) => {
2425
+ const partialNewState = {
2426
+ ...state,
2427
+ ...update
2428
+ };
2429
+ return {
2430
+ ...partialNewState,
2431
+ searchInputErrorMessage: searchInputErrorMessage
2432
+ };
2433
+ };
2434
+
2435
+ const EmptyString = '';
2436
+
2437
+ const isEmptyString = string => {
2438
+ return string === EmptyString;
2439
+ };
2440
+
2180
2441
  // Based on https://github.com/microsoft/vscode/blob/ad375c92764b72a1f28f3e1626563e9e41e5c740/src/vs/workbench/contrib/search/browser/searchWidget.ts#L393 by Microsoft (License MIT)
2181
2442
 
2182
2443
  const validateSearchInput = (value, flags) => {
@@ -2198,105 +2459,32 @@ const validateSearchInput = (value, flags) => {
2198
2459
  };
2199
2460
 
2200
2461
  const handleUpdate = async (state, update) => {
2462
+ const {
2463
+ incrementalSearch
2464
+ } = state;
2201
2465
  const partialNewState = {
2202
2466
  ...state,
2203
2467
  ...update
2204
2468
  };
2205
2469
  try {
2206
2470
  const {
2207
- height,
2208
- itemHeight,
2209
- minimumSliderSize,
2210
- headerHeight,
2211
2471
  flags,
2212
- value,
2213
- threads,
2214
- includeValue,
2215
- excludeValue
2472
+ value
2216
2473
  } = partialNewState;
2217
2474
  if (isEmptyString(value)) {
2218
- return {
2219
- ...partialNewState,
2220
- minLineY: 0,
2221
- maxLineY: 0,
2222
- deltaY: 0,
2223
- items: [],
2224
- listItems: [],
2225
- matchCount: 0,
2226
- message: '',
2227
- loaded: true,
2228
- searchInputErrorMessage: ''
2229
- };
2475
+ return handleUpdateEmpty(state, update);
2230
2476
  }
2231
2477
  const searchInputErrorMessage = validateSearchInput(value, flags);
2232
2478
  if (searchInputErrorMessage) {
2233
- return {
2234
- ...partialNewState,
2235
- searchInputErrorMessage: searchInputErrorMessage
2236
- };
2479
+ return handleUpdateValidationError(state, update, searchInputErrorMessage);
2237
2480
  }
2238
- const root = state.workspacePath;
2239
- const scheme = getProtocol$1(root);
2240
- const results = await textSearch(root, value, {
2241
- threads,
2242
- isCaseSensitive: Boolean(flags & MatchCase$2),
2243
- useRegularExpression: Boolean(flags & UseRegularExpression$2),
2244
- exclude: excludeValue,
2245
- include: includeValue,
2246
- assetDir: state.assetDir,
2247
- root,
2248
- query: value,
2249
- scheme,
2250
- flags,
2251
- matchWholeWord: Boolean(flags & MatchWholeWord$2)
2252
- }, state.assetDir, state.platform);
2253
- if (!Array.isArray(results)) {
2254
- throw new TypeError('results must be of type array');
2481
+ if (incrementalSearch) {
2482
+ return await handleUpdateIncremental(state, update);
2255
2483
  }
2256
- const {
2257
- fileCount,
2258
- resultCount
2259
- } = getTextSearchResultCounts(results);
2260
- const message = getStatusMessage(resultCount, fileCount);
2261
- const total = results.length;
2262
- const contentHeight = total * itemHeight;
2263
- const listHeight = height - headerHeight;
2264
- const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
2265
- const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
2266
- const maxLineY = Math.min(numberOfVisible, total);
2267
- const finalDeltaY = Math.max(contentHeight - listHeight, 0);
2268
- const visible = results.slice(0, maxLineY);
2269
- const icons = await getFileIcons(visible);
2270
- return {
2271
- ...partialNewState,
2272
- minLineY: 0,
2273
- deltaY: 0,
2274
- value,
2275
- items: results,
2276
- listItems: results,
2277
- message,
2278
- maxLineY: maxLineY,
2279
- scrollBarHeight,
2280
- finalDeltaY,
2281
- threads,
2282
- fileCount,
2283
- matchCount: resultCount,
2284
- loaded: true,
2285
- icons,
2286
- searchInputErrorMessage: ''
2287
- };
2484
+ return await handleUpdateFull(state, update);
2288
2485
  } catch (error) {
2289
2486
  handleError(error);
2290
- return {
2291
- ...partialNewState,
2292
- message: `${error}`,
2293
- items: [],
2294
- listItems: [],
2295
- matchCount: 0,
2296
- fileCount: 0,
2297
- minLineY: 0,
2298
- maxLineY: 0
2299
- };
2487
+ return handleUpdateError(state, update, error);
2300
2488
  }
2301
2489
  };
2302
2490
 
@@ -4451,6 +4639,12 @@ const replaceAllAndPrompt = async (workspacePath, items, replacement, matchCount
4451
4639
  return true;
4452
4640
  };
4453
4641
 
4642
+ const rerender = state => {
4643
+ return {
4644
+ ...state
4645
+ };
4646
+ };
4647
+
4454
4648
  const saveState = uid => {
4455
4649
  const {
4456
4650
  newState
@@ -4682,12 +4876,12 @@ const commandMap = {
4682
4876
  'TextSearch.handleScrollBarMove': wrapCommand(handleScrollBarMove),
4683
4877
  'TextSearch.handleSharedInput': wrapCommand(handleSharedInput),
4684
4878
  'TextSearch.handleWheel': wrapCommand(handleWheel),
4685
- 'TextSearch.launchSearchProcess': wrapCommand(launchSearchProcess),
4686
4879
  'TextSearch.loadContent': wrapCommand(loadContent),
4687
4880
  'TextSearch.nextHistoryResult': wrapCommand(nextHistoryResult),
4688
4881
  'TextSearch.previousHistoryResult': wrapCommand(previousHistoryResult),
4689
4882
  'TextSearch.refresh': wrapCommand(refresh),
4690
4883
  'TextSearch.replaceAll': wrapCommand(replaceAll),
4884
+ 'TextSearch.rerender': rerender,
4691
4885
  'TextSearch.selectIndex': wrapCommand(selectIndex),
4692
4886
  'TextSearch.submit': wrapCommand(submit),
4693
4887
  'TextSearch.toggleMatchCase': wrapCommand(toggleMatchCase),
@@ -4719,7 +4913,7 @@ const listen = async () => {
4719
4913
  const rpc = await WebWorkerRpcClient.create({
4720
4914
  commandMap: commandMap
4721
4915
  });
4722
- set$1(RendererWorker, rpc);
4916
+ set$1(rpc);
4723
4917
  };
4724
4918
 
4725
4919
  const main = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "4.8.0",
3
+ "version": "4.10.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"