@lvce-editor/text-search-worker 6.1.0 → 6.2.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.
@@ -546,7 +546,7 @@ const waitForWebSocketToBeOpen = webSocket => {
546
546
  open: Open
547
547
  });
548
548
  };
549
- const create$6 = async ({
549
+ const create$f = async ({
550
550
  webSocket
551
551
  }) => {
552
552
  const firstWebSocketEvent = await waitForWebSocketToBeOpen(webSocket);
@@ -583,10 +583,31 @@ const wrap = webSocket => {
583
583
  };
584
584
  const IpcParentWithWebSocket$1 = {
585
585
  __proto__: null,
586
- create: create$6,
586
+ create: create$f,
587
587
  wrap
588
588
  };
589
589
 
590
+ class CommandNotFoundError extends Error {
591
+ constructor(command) {
592
+ super(`Command not found ${command}`);
593
+ this.name = 'CommandNotFoundError';
594
+ }
595
+ }
596
+ const commands = Object.create(null);
597
+ const register = commandMap => {
598
+ Object.assign(commands, commandMap);
599
+ };
600
+ const getCommand = key => {
601
+ return commands[key];
602
+ };
603
+ const execute = (command, ...args) => {
604
+ const fn = getCommand(command);
605
+ if (!fn) {
606
+ throw new CommandNotFoundError(command);
607
+ }
608
+ return fn(...args);
609
+ };
610
+
590
611
  const Two$1 = '2.0';
591
612
  const callbacks = Object.create(null);
592
613
  const get$3 = id => {
@@ -801,7 +822,7 @@ const getErrorResponse = (id, error, preparePrettyError, logError) => {
801
822
  const errorProperty = getErrorProperty(error, prettyError);
802
823
  return create$1$1(id, errorProperty);
803
824
  };
804
- const create$4 = (message, result) => {
825
+ const create$e = (message, result) => {
805
826
  return {
806
827
  jsonrpc: Two$1,
807
828
  id: message.id,
@@ -810,7 +831,7 @@ const create$4 = (message, result) => {
810
831
  };
811
832
  const getSuccessResponse = (message, result) => {
812
833
  const resultProperty = result ?? null;
813
- return create$4(message, resultProperty);
834
+ return create$e(message, resultProperty);
814
835
  };
815
836
  const getErrorResponseSimple = (id, error) => {
816
837
  return {
@@ -902,36 +923,17 @@ const handleJsonRpcMessage = async (...args) => {
902
923
  throw new JsonRpcError('unexpected message');
903
924
  };
904
925
 
905
- class CommandNotFoundError extends Error {
906
- constructor(command) {
907
- super(`Command not found ${command}`);
908
- this.name = 'CommandNotFoundError';
909
- }
910
- }
911
- const commands = Object.create(null);
912
- const register = commandMap => {
913
- Object.assign(commands, commandMap);
914
- };
915
- const getCommand = key => {
916
- return commands[key];
917
- };
918
- const execute = (command, ...args) => {
919
- const fn = getCommand(command);
920
- if (!fn) {
921
- throw new CommandNotFoundError(command);
922
- }
923
- return fn(...args);
924
- };
925
-
926
926
  const Two = '2.0';
927
- const create$t = (method, params) => {
927
+
928
+ const create$d = (method, params) => {
928
929
  return {
929
930
  jsonrpc: Two,
930
931
  method,
931
932
  params
932
933
  };
933
934
  };
934
- const create$s = (id, method, params) => {
935
+
936
+ const create$c = (id, method, params) => {
935
937
  const message = {
936
938
  id,
937
939
  jsonrpc: Two,
@@ -940,15 +942,14 @@ const create$s = (id, method, params) => {
940
942
  };
941
943
  return message;
942
944
  };
945
+
943
946
  let id = 0;
944
- const create$r = () => {
947
+ const create$b = () => {
945
948
  return ++id;
946
949
  };
947
950
 
948
- /* eslint-disable n/no-unsupported-features/es-syntax */
949
-
950
951
  const registerPromise = map => {
951
- const id = create$r();
952
+ const id = create$b();
952
953
  const {
953
954
  promise,
954
955
  resolve
@@ -966,7 +967,7 @@ const invokeHelper = async (callbacks, ipc, method, params, useSendAndTransfer)
966
967
  id,
967
968
  promise
968
969
  } = registerPromise(callbacks);
969
- const message = create$s(id, method, params);
970
+ const message = create$c(id, method, params);
970
971
  if (useSendAndTransfer && ipc.sendAndTransfer) {
971
972
  ipc.sendAndTransfer(message);
972
973
  } else {
@@ -1002,12 +1003,13 @@ const createRpc = ipc => {
1002
1003
  * @deprecated
1003
1004
  */
1004
1005
  send(method, ...params) {
1005
- const message = create$t(method, params);
1006
+ const message = create$d(method, params);
1006
1007
  ipc.send(message);
1007
1008
  }
1008
1009
  };
1009
1010
  return rpc;
1010
1011
  };
1012
+
1011
1013
  const requiresSocket = () => {
1012
1014
  return false;
1013
1015
  };
@@ -1022,6 +1024,7 @@ const handleMessage = event => {
1022
1024
  const actualExecute = event?.target?.execute || execute;
1023
1025
  return handleJsonRpcMessage(event.target, event.data, actualExecute, event.target._resolve, preparePrettyError, logError, actualRequiresSocket);
1024
1026
  };
1027
+
1025
1028
  const handleIpc = ipc => {
1026
1029
  if ('addEventListener' in ipc) {
1027
1030
  ipc.addEventListener('message', handleMessage);
@@ -1030,6 +1033,7 @@ const handleIpc = ipc => {
1030
1033
  ipc.on('message', handleMessage);
1031
1034
  }
1032
1035
  };
1036
+
1033
1037
  const listen$1 = async (module, options) => {
1034
1038
  const rawIpc = await module.listen(options);
1035
1039
  if (module.signal) {
@@ -1039,8 +1043,6 @@ const listen$1 = async (module, options) => {
1039
1043
  return ipc;
1040
1044
  };
1041
1045
 
1042
- /* eslint-disable @typescript-eslint/no-misused-promises */
1043
-
1044
1046
  const createSharedLazyRpc = factory => {
1045
1047
  let rpcPromise;
1046
1048
  const getOrCreate = () => {
@@ -1068,40 +1070,42 @@ const createSharedLazyRpc = factory => {
1068
1070
  }
1069
1071
  };
1070
1072
  };
1071
- const create$j = async ({
1073
+
1074
+ const create$a = async ({
1072
1075
  commandMap,
1073
1076
  isMessagePortOpen,
1074
1077
  send
1075
1078
  }) => {
1076
1079
  return createSharedLazyRpc(() => {
1077
- return create$3$1({
1080
+ return create$5({
1078
1081
  commandMap,
1079
1082
  isMessagePortOpen,
1080
1083
  send
1081
1084
  });
1082
1085
  });
1083
1086
  };
1084
- const LazyTransferMessagePortRpcParent = {
1085
- __proto__: null,
1086
- create: create$j
1087
- };
1087
+
1088
1088
  const Https = 'https:';
1089
1089
  const Ws = 'ws:';
1090
1090
  const Wss = 'wss:';
1091
+
1091
1092
  const getWebSocketProtocol = locationProtocol => {
1092
1093
  return locationProtocol === Https ? Wss : Ws;
1093
1094
  };
1095
+
1094
1096
  const getWebSocketUrl = (type, host, locationProtocol) => {
1095
1097
  const wsProtocol = getWebSocketProtocol(locationProtocol);
1096
1098
  return `${wsProtocol}//${host}/websocket/${type}`;
1097
1099
  };
1100
+
1098
1101
  const getHost = () => {
1099
1102
  return location.host;
1100
1103
  };
1101
1104
  const getProtocol$1 = () => {
1102
1105
  return location.protocol;
1103
1106
  };
1104
- const create$i = async ({
1107
+
1108
+ const create$9 = async ({
1105
1109
  commandMap,
1106
1110
  webSocket
1107
1111
  }) => {
@@ -1115,7 +1119,8 @@ const create$i = async ({
1115
1119
  const rpc = createRpc(ipc);
1116
1120
  return rpc;
1117
1121
  };
1118
- const create$h = async ({
1122
+
1123
+ const create$8 = async ({
1119
1124
  commandMap,
1120
1125
  type
1121
1126
  }) => {
@@ -1123,28 +1128,26 @@ const create$h = async ({
1123
1128
  const protocol = getProtocol$1();
1124
1129
  const wsUrl = getWebSocketUrl(type, host, protocol);
1125
1130
  const webSocket = new WebSocket(wsUrl);
1126
- const rpc = await create$i({
1131
+ const rpc = await create$9({
1127
1132
  commandMap,
1128
1133
  webSocket
1129
1134
  });
1130
1135
  return rpc;
1131
1136
  };
1132
- const create$g = async ({
1137
+
1138
+ const create$7 = async ({
1133
1139
  commandMap,
1134
1140
  type
1135
1141
  }) => {
1136
1142
  return createSharedLazyRpc(() => {
1137
- return create$h({
1143
+ return create$8({
1138
1144
  commandMap,
1139
1145
  type
1140
1146
  });
1141
1147
  });
1142
1148
  };
1143
- const LazyWebSocketRpcParent2 = {
1144
- __proto__: null,
1145
- create: create$g
1146
- };
1147
- const create$5 = async ({
1149
+
1150
+ const create$6 = async ({
1148
1151
  commandMap,
1149
1152
  isMessagePortOpen = true,
1150
1153
  messagePort
@@ -1161,7 +1164,8 @@ const create$5 = async ({
1161
1164
  messagePort.start();
1162
1165
  return rpc;
1163
1166
  };
1164
- const create$3$1 = async ({
1167
+
1168
+ const create$5 = async ({
1165
1169
  commandMap,
1166
1170
  isMessagePortOpen,
1167
1171
  send
@@ -1171,17 +1175,14 @@ const create$3$1 = async ({
1171
1175
  port2
1172
1176
  } = new MessageChannel();
1173
1177
  await send(port1);
1174
- return create$5({
1178
+ return create$6({
1175
1179
  commandMap,
1176
1180
  isMessagePortOpen,
1177
1181
  messagePort: port2
1178
1182
  });
1179
1183
  };
1180
- const TransferMessagePortRpcParent = {
1181
- __proto__: null,
1182
- create: create$3$1
1183
- };
1184
- const create$2$1 = async ({
1184
+
1185
+ const create$4 = async ({
1185
1186
  commandMap
1186
1187
  }) => {
1187
1188
  // TODO create a commandMap per rpc instance
@@ -1191,29 +1192,6 @@ const create$2$1 = async ({
1191
1192
  const rpc = createRpc(ipc);
1192
1193
  return rpc;
1193
1194
  };
1194
- const WebWorkerRpcClient = {
1195
- __proto__: null,
1196
- create: create$2$1
1197
- };
1198
- const createMockRpc = ({
1199
- commandMap
1200
- }) => {
1201
- const invocations = [];
1202
- const invoke = (method, ...params) => {
1203
- invocations.push([method, ...params]);
1204
- const command = commandMap[method];
1205
- if (!command) {
1206
- throw new Error(`command ${method} not found`);
1207
- }
1208
- return command(...params);
1209
- };
1210
- const mockRpc = {
1211
- invocations,
1212
- invoke,
1213
- invokeAndTransfer: invoke
1214
- };
1215
- return mockRpc;
1216
- };
1217
1195
 
1218
1196
  const Alert = 'alert';
1219
1197
  const Button$3 = 'button';
@@ -1349,6 +1327,26 @@ const FocusSearchWholeWord = 34;
1349
1327
  const FocusToggleDetails = 1010;
1350
1328
  const FocusToggleReplace = 1020;
1351
1329
 
1330
+ const createMockRpc = ({
1331
+ commandMap
1332
+ }) => {
1333
+ const invocations = [];
1334
+ const invoke = (method, ...params) => {
1335
+ invocations.push([method, ...params]);
1336
+ const command = commandMap[method];
1337
+ if (!command) {
1338
+ throw new Error(`command ${method} not found`);
1339
+ }
1340
+ return command(...params);
1341
+ };
1342
+ const mockRpc = {
1343
+ invocations,
1344
+ invoke,
1345
+ invokeAndTransfer: invoke
1346
+ };
1347
+ return mockRpc;
1348
+ };
1349
+
1352
1350
  const rpcs = Object.create(null);
1353
1351
  const set$4 = (id, rpc) => {
1354
1352
  rpcs[id] = rpc;
@@ -1431,6 +1429,9 @@ const sendMessagePortToSearchProcess = async port => {
1431
1429
  const writeClipBoardText = async text => {
1432
1430
  await invoke$1('ClipBoard.writeText', /* text */text);
1433
1431
  };
1432
+ const getPreference = async key => {
1433
+ return await invoke$1('Preferences.get', key);
1434
+ };
1434
1435
  const openUri$1 = async (uri, focus, options) => {
1435
1436
  await invoke$1('Main.openUri', uri, focus, options);
1436
1437
  };
@@ -2177,6 +2178,8 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
2177
2178
  threads: 0,
2178
2179
  useChevrons: true,
2179
2180
  useFileIcons: true,
2181
+ usePullBasedSearch: false,
2182
+ // TODO enable
2180
2183
  viewMode: List,
2181
2184
  workspacePath: workspacePath
2182
2185
  };
@@ -3104,12 +3107,12 @@ const getTextSearchProvider = scheme => {
3104
3107
  return get(scheme);
3105
3108
  };
3106
3109
 
3107
- const textSearch$6 = async (root, query, options, assetDir, platform) => {
3110
+ const textSearch$6 = async (root, query, options, assetDir, platform, searchId, uid) => {
3108
3111
  string(root);
3109
3112
  string(query);
3110
3113
  const scheme = getProtocol(root);
3111
3114
  const provider = getTextSearchProvider(scheme);
3112
- const results = await provider(scheme, root, query, options, assetDir, platform);
3115
+ const results = await provider(scheme, root, query, options, assetDir, platform, searchId, uid);
3113
3116
  return results;
3114
3117
  };
3115
3118
 
@@ -3131,10 +3134,15 @@ const handleUpdateFull = async (state, update) => {
3131
3134
  minimumSliderSize,
3132
3135
  platform,
3133
3136
  threads,
3137
+ uid,
3138
+ usePullBasedSearch,
3134
3139
  value
3135
3140
  } = partialNewState;
3136
3141
  const root = state.workspacePath;
3137
3142
  const scheme = getProtocol(root);
3143
+ const isFileSearch = scheme === '' || scheme === 'file';
3144
+ const shouldUsePullBasedSearch = Boolean(usePullBasedSearch) && isFileSearch;
3145
+ const searchId = shouldUsePullBasedSearch ? crypto.randomUUID() : '';
3138
3146
  const {
3139
3147
  limitHit,
3140
3148
  results
@@ -3151,8 +3159,9 @@ const handleUpdateFull = async (state, update) => {
3151
3159
  root,
3152
3160
  scheme,
3153
3161
  threads,
3162
+ usePullBasedSearch: shouldUsePullBasedSearch,
3154
3163
  useRegularExpression: Boolean(flags & UseRegularExpression$2)
3155
- }, assetDir, platform);
3164
+ }, assetDir, platform, searchId, uid);
3156
3165
  if (!Array.isArray(results)) {
3157
3166
  throw new TypeError('results must be of type array');
3158
3167
  }
@@ -3192,6 +3201,7 @@ const handleUpdateFull = async (state, update) => {
3192
3201
  message,
3193
3202
  minLineY: 0,
3194
3203
  scrollBarHeight,
3204
+ searchId,
3195
3205
  searchInputErrorMessage: '',
3196
3206
  threads,
3197
3207
  value
@@ -3298,6 +3308,7 @@ const handleUpdateIncremental = async (state, update) => {
3298
3308
  platform,
3299
3309
  threads,
3300
3310
  uid,
3311
+ usePullBasedSearch,
3301
3312
  value
3302
3313
  } = partialNewState;
3303
3314
  const root = state.workspacePath;
@@ -3325,11 +3336,76 @@ const handleUpdateIncremental = async (state, update) => {
3325
3336
  root,
3326
3337
  scheme,
3327
3338
  threads,
3339
+ usePullBasedSearch: usePullBasedSearch || false,
3328
3340
  useRegularExpression: Boolean(flags & UseRegularExpression$2)
3329
3341
  }, assetDir, platform, searchId, uid);
3330
3342
  return state;
3331
3343
  };
3332
3344
 
3345
+ const handleUpdatePullBased = async (state, update) => {
3346
+ const searchId = crypto.randomUUID();
3347
+ const partialNewState = {
3348
+ ...state,
3349
+ ...update,
3350
+ items: [],
3351
+ listItems: [],
3352
+ message: '',
3353
+ searchId,
3354
+ searchResults: []
3355
+ };
3356
+ set(state.uid, state, partialNewState);
3357
+ const {
3358
+ assetDir,
3359
+ excludeValue,
3360
+ flags,
3361
+ includeValue,
3362
+ limit,
3363
+ platform,
3364
+ threads,
3365
+ uid,
3366
+ usePullBasedSearch,
3367
+ value
3368
+ } = partialNewState;
3369
+ const root = state.workspacePath;
3370
+ const scheme = getProtocol(root);
3371
+ const isFileSearch = scheme === '' || scheme === 'file';
3372
+ const shouldUsePullBasedSearch = Boolean(usePullBasedSearch) && isFileSearch;
3373
+ const {
3374
+ limitHit
3375
+ } = await textSearch$6(root, value, {
3376
+ assetDir,
3377
+ defaultExcludes: hasUseIgnoreFiles(flags) ? partialNewState.defaultExcludes : [],
3378
+ exclude: excludeValue,
3379
+ flags,
3380
+ include: includeValue,
3381
+ isCaseSensitive: Boolean(flags & MatchCase$2),
3382
+ limit,
3383
+ matchWholeWord: Boolean(flags & MatchWholeWord$2),
3384
+ query: value,
3385
+ root,
3386
+ scheme,
3387
+ threads,
3388
+ usePullBasedSearch: shouldUsePullBasedSearch,
3389
+ useRegularExpression: Boolean(flags & UseRegularExpression$2)
3390
+ }, assetDir, platform, searchId, uid);
3391
+ const latest = get$1(uid);
3392
+ if (!latest) {
3393
+ return state;
3394
+ }
3395
+ const limitHitWarning = limitHit ? theResultSetOnlyContainsASubSetOfMatches() : '';
3396
+ const {
3397
+ fileCount,
3398
+ resultCount
3399
+ } = getTextSearchResultCounts(latest.newState.items);
3400
+ const message = getStatusMessage(resultCount, fileCount);
3401
+ return {
3402
+ ...latest.newState,
3403
+ limitHit,
3404
+ limitHitWarning,
3405
+ message
3406
+ };
3407
+ };
3408
+
3333
3409
  const handleUpdateValidationError = (state, update, searchInputErrorMessage) => {
3334
3410
  const partialNewState = {
3335
3411
  ...state,
@@ -3369,7 +3445,8 @@ const validateSearchInput = (value, flags) => {
3369
3445
 
3370
3446
  const handleUpdate = async (state, update) => {
3371
3447
  const {
3372
- incrementalSearch
3448
+ incrementalSearch,
3449
+ usePullBasedSearch
3373
3450
  } = state;
3374
3451
  const partialNewState = {
3375
3452
  ...state,
@@ -3390,6 +3467,9 @@ const handleUpdate = async (state, update) => {
3390
3467
  if (incrementalSearch) {
3391
3468
  return await handleUpdateIncremental(state, update);
3392
3469
  }
3470
+ if (usePullBasedSearch) {
3471
+ return await handleUpdatePullBased(state, update);
3472
+ }
3393
3473
  return await handleUpdateFull(state, update);
3394
3474
  } catch (error) {
3395
3475
  handleError(error);
@@ -3958,6 +4038,63 @@ const handleListFocus = async state => {
3958
4038
  };
3959
4039
  };
3960
4040
 
4041
+ const handlePullResultsFound = async (state, resultSearchId) => {
4042
+ const {
4043
+ fileIconCache,
4044
+ headerHeight,
4045
+ height,
4046
+ itemHeight,
4047
+ listItems,
4048
+ minimumSliderSize,
4049
+ platform,
4050
+ searchId,
4051
+ uid
4052
+ } = state;
4053
+ if (searchId !== resultSearchId) {
4054
+ return state;
4055
+ }
4056
+ const result = platform === Remote || platform === Electron ? await invoke('TextSearch.getPullResults', searchId) : await invoke$1('SearchProcess.invoke', 'TextSearch.getPullResults', searchId);
4057
+ const newResults = result;
4058
+ const allResults = [...listItems, ...newResults];
4059
+ const {
4060
+ fileCount,
4061
+ resultCount
4062
+ } = getTextSearchResultCounts(allResults);
4063
+ const message = getStatusMessage(resultCount, fileCount);
4064
+ const total = allResults.length;
4065
+ const contentHeight = total * itemHeight;
4066
+ const listHeight = height - headerHeight;
4067
+ const scrollBarHeight = getScrollBarSize$1(height, contentHeight, minimumSliderSize);
4068
+ const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
4069
+ const maxLineY = Math.min(numberOfVisible, total);
4070
+ const finalDeltaY = Math.max(contentHeight - listHeight, 0);
4071
+ const visible = allResults.slice(0, maxLineY);
4072
+ const {
4073
+ icons,
4074
+ newFileIconCache
4075
+ } = await getFileIcons(visible, fileIconCache);
4076
+ const latest = get$1(uid);
4077
+ const updatedState = {
4078
+ ...latest.newState,
4079
+ fileCount,
4080
+ fileIconCache: newFileIconCache,
4081
+ finalDeltaY,
4082
+ icons,
4083
+ items: allResults,
4084
+ listItems: allResults,
4085
+ loaded: true,
4086
+ matchCount: resultCount,
4087
+ maxLineY,
4088
+ message,
4089
+ minLineY: 0,
4090
+ scrollBarHeight
4091
+ };
4092
+ const oldState = latest ? latest.oldState : state;
4093
+ set(uid, oldState, updatedState);
4094
+ await invoke$1('Search.rerender');
4095
+ return state;
4096
+ };
4097
+
3961
4098
  const handleSharedInput = (state, name, value, inputSource = Script) => {
3962
4099
  const fn = getInputHandler(name);
3963
4100
  return fn(state, value, inputSource);
@@ -3968,7 +4105,7 @@ const send = async port => {
3968
4105
  };
3969
4106
  const launchIconThemeWorker = async () => {
3970
4107
  // TODO connect to icon theme worker
3971
- const rpc = await TransferMessagePortRpcParent.create({
4108
+ const rpc = await create$5({
3972
4109
  commandMap: {},
3973
4110
  send
3974
4111
  });
@@ -3981,7 +4118,7 @@ const initializeIconThemeWorker = async () => {
3981
4118
  };
3982
4119
 
3983
4120
  const launchSearchProcessElectron = async () => {
3984
- const rpc = await LazyTransferMessagePortRpcParent.create({
4121
+ const rpc = await create$a({
3985
4122
  commandMap: {},
3986
4123
  send: sendMessagePortToSearchProcess
3987
4124
  });
@@ -3989,7 +4126,7 @@ const launchSearchProcessElectron = async () => {
3989
4126
  };
3990
4127
 
3991
4128
  const launchSearchProcessNode = async () => {
3992
- const rpc = await LazyWebSocketRpcParent2.create({
4129
+ const rpc = await create$7({
3993
4130
  commandMap: {},
3994
4131
  // @ts-ignore
3995
4132
  type: 'search-process'
@@ -4503,14 +4640,29 @@ const handleListPointerDown = async (state, button, name) => {
4503
4640
  };
4504
4641
  };
4505
4642
 
4643
+ const getUsePullBasedSearch = async () => {
4644
+ try {
4645
+ return Boolean(await getPreference('Search.usePullBasedSearch'));
4646
+ } catch {
4647
+ return false;
4648
+ }
4649
+ };
4650
+
4651
+ const hasProperty = (object, key) => {
4652
+ if (!object || typeof object !== 'object' || !(key in object)) {
4653
+ return false;
4654
+ }
4655
+ return true;
4656
+ };
4657
+
4506
4658
  const getSavedFocus = savedState => {
4507
- if (savedState && typeof savedState === 'object' && 'focus' in savedState && typeof savedState.focus === 'number') {
4659
+ if (hasProperty(savedState, 'focus') && typeof savedState.focus === 'number') {
4508
4660
  return savedState.focus;
4509
4661
  }
4510
4662
  return 0;
4511
4663
  };
4512
4664
  const getSavedListFocus = savedState => {
4513
- if (savedState && typeof savedState === 'object' && 'listFocused' in savedState && typeof savedState.listFocused === 'boolean') {
4665
+ if (hasProperty(savedState, 'listFocused') && typeof savedState.listFocused === 'boolean') {
4514
4666
  return savedState.listFocused;
4515
4667
  }
4516
4668
  return false;
@@ -4520,44 +4672,44 @@ const isString = value => {
4520
4672
  return typeof value === 'string';
4521
4673
  };
4522
4674
  const getSavedHistory = savedState => {
4523
- if (savedState && typeof savedState === 'object' && 'history' in savedState && Array.isArray(savedState.history) && savedState.history.every(isString)) {
4675
+ if (hasProperty(savedState, 'history') && Array.isArray(savedState.history) && savedState.history.every(isString)) {
4524
4676
  return savedState.history;
4525
4677
  }
4526
4678
  return [];
4527
4679
  };
4528
4680
 
4529
4681
  const getSavedValue = savedState => {
4530
- if (savedState && typeof savedState === 'object' && 'value' in savedState && typeof savedState.value === 'string') {
4682
+ if (hasProperty(savedState, 'value') && typeof savedState.value === 'string') {
4531
4683
  return savedState.value;
4532
4684
  }
4533
4685
  return '';
4534
4686
  };
4535
4687
  const getSavedReplacement = savedState => {
4536
- if (savedState && typeof savedState === 'object' && 'replacement' in savedState && typeof savedState.replacement === 'string') {
4688
+ if (hasProperty(savedState, 'replacement') && typeof savedState.replacement === 'string') {
4537
4689
  return savedState.replacement;
4538
4690
  }
4539
4691
  return '';
4540
4692
  };
4541
4693
  const getSavedFlags = savedState => {
4542
- if (savedState && typeof savedState === 'object' && 'flags' in savedState && typeof savedState.flags === 'number') {
4694
+ if (hasProperty(savedState, 'flags') && typeof savedState.flags === 'number') {
4543
4695
  return savedState.flags;
4544
4696
  }
4545
4697
  return UseIgnoreFiles;
4546
4698
  };
4547
4699
  const getSavedIncludeValue = savedState => {
4548
- if (savedState && typeof savedState === 'object' && 'includeValue' in savedState && typeof savedState.includeValue === 'string') {
4700
+ if (hasProperty(savedState, 'includeValue') && typeof savedState.includeValue === 'string') {
4549
4701
  return savedState.includeValue;
4550
4702
  }
4551
4703
  return '';
4552
4704
  };
4553
4705
  const getSavedExcludeValue = savedState => {
4554
- if (savedState && typeof savedState === 'object' && 'excludeValue' in savedState && typeof savedState.excludeValue === 'string') {
4706
+ if (hasProperty(savedState, 'excludeValue') && typeof savedState.excludeValue === 'string') {
4555
4707
  return savedState.excludeValue;
4556
4708
  }
4557
4709
  return '';
4558
4710
  };
4559
4711
  const getSavedCollapsedPaths = savedState => {
4560
- if (savedState && typeof savedState === 'object' && 'collapsedPaths' in savedState && Array.isArray(savedState.collapsedPaths) && savedState.collapsedPaths.every(item => typeof item === 'string')) {
4712
+ if (hasProperty(savedState, 'collapsedPaths') && Array.isArray(savedState.collapsedPaths) && savedState.collapsedPaths.every(item => typeof item === 'string')) {
4561
4713
  return savedState.collapsedPaths;
4562
4714
  }
4563
4715
  return [];
@@ -4588,6 +4740,7 @@ const loadContent = async (state, savedState) => {
4588
4740
  savedValue,
4589
4741
  threads
4590
4742
  } = restoreState(savedState);
4743
+ const usePullBasedSearch = await getUsePullBasedSearch();
4591
4744
  const update = {
4592
4745
  collapsedPaths: savedCollapsedPaths,
4593
4746
  excludeValue,
@@ -4598,10 +4751,14 @@ const loadContent = async (state, savedState) => {
4598
4751
  inputSource: Script,
4599
4752
  replacement,
4600
4753
  threads,
4754
+ usePullBasedSearch,
4601
4755
  value: savedValue
4602
4756
  };
4603
4757
  if (savedValue) {
4604
- const result = await handleUpdate(state, update);
4758
+ const result = await handleUpdate({
4759
+ ...state,
4760
+ usePullBasedSearch
4761
+ }, update);
4605
4762
  return {
4606
4763
  ...result,
4607
4764
  initial: false,
@@ -4614,7 +4771,8 @@ const loadContent = async (state, savedState) => {
4614
4771
  flags,
4615
4772
  initial: false,
4616
4773
  loaded: true,
4617
- threads
4774
+ threads,
4775
+ usePullBasedSearch
4618
4776
  };
4619
4777
  };
4620
4778
 
@@ -6029,6 +6187,7 @@ const commandMap = {
6029
6187
  'TextSearch.handleListBlur': wrapCommand(handleListBlur),
6030
6188
  'TextSearch.handleListFocus': wrapCommand(handleListFocus),
6031
6189
  'TextSearch.handleListPointerDown': wrapCommand(handleListPointerDown),
6190
+ 'TextSearch.handlePullResultsFound': wrapCommand(handlePullResultsFound),
6032
6191
  'TextSearch.handleReplaceInput': wrapCommand(handleReplaceInput),
6033
6192
  'TextSearch.handleScrollBarCaptureLost': wrapCommand(handleScrollBarCaptureLost),
6034
6193
  'TextSearch.handleScrollBarClick': wrapCommand(handleScrollBarClick),
@@ -6114,11 +6273,28 @@ const textSearch$2 = async (scheme, root, query, options, assetDir) => {
6114
6273
  }
6115
6274
  };
6116
6275
 
6117
- const textSearch$1 = async (scheme, root, query, options, assetDir, platform) => {
6276
+ const textSearch$1 = async (scheme, root, query, options, assetDir, platform, searchId, uid) => {
6118
6277
  const ripGrepArgs = getRipGrepArgs({
6119
6278
  ...options,
6120
6279
  searchString: query
6121
6280
  });
6281
+ if (options.usePullBasedSearch && searchId && (scheme === '' || scheme === 'file')) {
6282
+ const pullSearchOptions = {
6283
+ ripGrepArgs,
6284
+ searchDir: root,
6285
+ searchId,
6286
+ uid
6287
+ };
6288
+ if (platform === Remote || platform === Electron) {
6289
+ await invoke('TextSearch.searchPull', pullSearchOptions);
6290
+ } else {
6291
+ await invoke$1('SearchProcess.invoke', 'TextSearch.searchPull', pullSearchOptions);
6292
+ }
6293
+ return {
6294
+ limitHit: false,
6295
+ results: []
6296
+ };
6297
+ }
6122
6298
  const actualOptions = {
6123
6299
  ripGrepArgs,
6124
6300
  searchDir: root
@@ -6172,7 +6348,7 @@ const textSearchProviderMap = {
6172
6348
  const listen = async () => {
6173
6349
  registerCommands(commandMap);
6174
6350
  add(textSearchProviderMap);
6175
- const rpc = await WebWorkerRpcClient.create({
6351
+ const rpc = await create$4({
6176
6352
  commandMap: commandMap
6177
6353
  });
6178
6354
  set$2(rpc);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "6.1.0",
3
+ "version": "6.2.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"