@lvce-editor/text-search-worker 4.9.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.
- package/dist/textSearchWorkerMain.js +330 -148
- package/package.json +1 -1
|
@@ -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,
|
|
@@ -599,7 +588,7 @@ const create$4 = (method, params) => {
|
|
|
599
588
|
};
|
|
600
589
|
};
|
|
601
590
|
const callbacks = Object.create(null);
|
|
602
|
-
const set$
|
|
591
|
+
const set$2 = (id, fn) => {
|
|
603
592
|
callbacks[id] = fn;
|
|
604
593
|
};
|
|
605
594
|
const get$2 = id => {
|
|
@@ -618,7 +607,7 @@ const registerPromise = () => {
|
|
|
618
607
|
resolve,
|
|
619
608
|
promise
|
|
620
609
|
} = Promise.withResolvers();
|
|
621
|
-
set$
|
|
610
|
+
set$2(id, resolve);
|
|
622
611
|
return {
|
|
623
612
|
id,
|
|
624
613
|
promise
|
|
@@ -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
|
|
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 = (
|
|
824
|
+
const create$1$2 = (id, error) => {
|
|
818
825
|
return {
|
|
819
826
|
jsonrpc: Two,
|
|
820
|
-
id
|
|
827
|
+
id,
|
|
821
828
|
error
|
|
822
829
|
};
|
|
823
830
|
};
|
|
824
|
-
const getErrorResponse = (
|
|
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(
|
|
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
|
-
|
|
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$
|
|
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$
|
|
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$
|
|
1028
|
+
const create$9 = async ({
|
|
1007
1029
|
commandMap,
|
|
1008
1030
|
messagePort,
|
|
1009
1031
|
isMessagePortOpen
|
|
@@ -1021,7 +1043,7 @@ const create$8 = async ({
|
|
|
1021
1043
|
};
|
|
1022
1044
|
const MessagePortRpcParent = {
|
|
1023
1045
|
__proto__: null,
|
|
1024
|
-
create: create$
|
|
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$
|
|
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$
|
|
1078
|
+
create: create$4
|
|
1057
1079
|
};
|
|
1058
1080
|
|
|
1059
1081
|
const User = 1;
|
|
@@ -1119,31 +1141,45 @@ const collapseDetails = state => {
|
|
|
1119
1141
|
};
|
|
1120
1142
|
|
|
1121
1143
|
const rpcs = Object.create(null);
|
|
1122
|
-
const set$
|
|
1144
|
+
const set$d = (id, rpc) => {
|
|
1123
1145
|
rpcs[id] = rpc;
|
|
1124
1146
|
};
|
|
1125
1147
|
const get$1 = id => {
|
|
1126
1148
|
return rpcs[id];
|
|
1127
1149
|
};
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
return
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1150
|
+
|
|
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
|
+
};
|
|
1141
1171
|
};
|
|
1172
|
+
const RendererWorker$1 = 1;
|
|
1173
|
+
const {
|
|
1174
|
+
invoke: invoke$3,
|
|
1175
|
+
invokeAndTransfer: invokeAndTransfer$3,
|
|
1176
|
+
set: set$3
|
|
1177
|
+
} = create$3(RendererWorker$1);
|
|
1142
1178
|
const RendererWorker = {
|
|
1143
1179
|
__proto__: null,
|
|
1144
|
-
invoke: invoke$
|
|
1145
|
-
invokeAndTransfer: invokeAndTransfer$
|
|
1146
|
-
set: set$
|
|
1180
|
+
invoke: invoke$3,
|
|
1181
|
+
invokeAndTransfer: invokeAndTransfer$3,
|
|
1182
|
+
set: set$3
|
|
1147
1183
|
};
|
|
1148
1184
|
|
|
1149
1185
|
const {
|
|
@@ -1232,6 +1268,8 @@ const {
|
|
|
1232
1268
|
wrapCommand
|
|
1233
1269
|
} = create$2();
|
|
1234
1270
|
|
|
1271
|
+
const List$1 = 1;
|
|
1272
|
+
|
|
1235
1273
|
const create$1 = ({
|
|
1236
1274
|
itemHeight,
|
|
1237
1275
|
headerHeight = 0,
|
|
@@ -1261,7 +1299,6 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
|
|
|
1261
1299
|
uid,
|
|
1262
1300
|
searchResults: [],
|
|
1263
1301
|
stats: {},
|
|
1264
|
-
searchId: -1,
|
|
1265
1302
|
value,
|
|
1266
1303
|
disposed: false,
|
|
1267
1304
|
fileCount: 0,
|
|
@@ -1299,7 +1336,10 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
|
|
|
1299
1336
|
platform,
|
|
1300
1337
|
searchInputErrorMessage: '',
|
|
1301
1338
|
history: [],
|
|
1302
|
-
historyIndex: -1
|
|
1339
|
+
historyIndex: -1,
|
|
1340
|
+
viewMode: List$1,
|
|
1341
|
+
incrementalSearch: false,
|
|
1342
|
+
searchId: ''
|
|
1303
1343
|
};
|
|
1304
1344
|
set(uid, state, state);
|
|
1305
1345
|
return state;
|
|
@@ -1833,7 +1873,7 @@ const focusSearchValueNext = state => {
|
|
|
1833
1873
|
return focusMatchCase$1(state);
|
|
1834
1874
|
};
|
|
1835
1875
|
|
|
1836
|
-
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'];
|
|
1837
1877
|
|
|
1838
1878
|
const getCommandIds = () => {
|
|
1839
1879
|
return commandIds;
|
|
@@ -1920,6 +1960,42 @@ const handleError = error => {
|
|
|
1920
1960
|
console.error(`[text-search-worker] ${error}`);
|
|
1921
1961
|
};
|
|
1922
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
|
+
|
|
1923
1999
|
const getFileIcon = async result => {
|
|
1924
2000
|
if (result.type === File) {
|
|
1925
2001
|
return invoke$2('IconTheme.getFileIcon', {
|
|
@@ -1970,12 +2046,6 @@ const getTextSearchResultCounts = results => {
|
|
|
1970
2046
|
};
|
|
1971
2047
|
};
|
|
1972
2048
|
|
|
1973
|
-
const EmptyString = '';
|
|
1974
|
-
|
|
1975
|
-
const isEmptyString = string => {
|
|
1976
|
-
return string === EmptyString;
|
|
1977
|
-
};
|
|
1978
|
-
|
|
1979
2049
|
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
1980
2050
|
if (size >= contentSize) {
|
|
1981
2051
|
return 0;
|
|
@@ -2071,7 +2141,6 @@ const state$1 = {
|
|
|
2071
2141
|
};
|
|
2072
2142
|
const getOrCreate$1 = () => {
|
|
2073
2143
|
if (!state$1.rpc) {
|
|
2074
|
-
// @ts-ignore
|
|
2075
2144
|
state$1.rpc = launchSearchProcess();
|
|
2076
2145
|
}
|
|
2077
2146
|
return state$1.rpc;
|
|
@@ -2148,7 +2217,7 @@ const textSearch$2 = async (scheme, root, query, options, assetDir, platform) =>
|
|
|
2148
2217
|
return results.results;
|
|
2149
2218
|
};
|
|
2150
2219
|
|
|
2151
|
-
const textSearch$1 = (scheme, root, query) => {
|
|
2220
|
+
const textSearch$1 = async (scheme, root, query) => {
|
|
2152
2221
|
// TODO ask renderer worker for files
|
|
2153
2222
|
const entries = Object.entries({});
|
|
2154
2223
|
const results = [];
|
|
@@ -2190,6 +2259,185 @@ const textSearch = async (root, query, options, assetDir, platform) => {
|
|
|
2190
2259
|
return results;
|
|
2191
2260
|
};
|
|
2192
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
|
+
|
|
2193
2441
|
// Based on https://github.com/microsoft/vscode/blob/ad375c92764b72a1f28f3e1626563e9e41e5c740/src/vs/workbench/contrib/search/browser/searchWidget.ts#L393 by Microsoft (License MIT)
|
|
2194
2442
|
|
|
2195
2443
|
const validateSearchInput = (value, flags) => {
|
|
@@ -2211,105 +2459,32 @@ const validateSearchInput = (value, flags) => {
|
|
|
2211
2459
|
};
|
|
2212
2460
|
|
|
2213
2461
|
const handleUpdate = async (state, update) => {
|
|
2462
|
+
const {
|
|
2463
|
+
incrementalSearch
|
|
2464
|
+
} = state;
|
|
2214
2465
|
const partialNewState = {
|
|
2215
2466
|
...state,
|
|
2216
2467
|
...update
|
|
2217
2468
|
};
|
|
2218
2469
|
try {
|
|
2219
2470
|
const {
|
|
2220
|
-
height,
|
|
2221
|
-
itemHeight,
|
|
2222
|
-
minimumSliderSize,
|
|
2223
|
-
headerHeight,
|
|
2224
2471
|
flags,
|
|
2225
|
-
value
|
|
2226
|
-
threads,
|
|
2227
|
-
includeValue,
|
|
2228
|
-
excludeValue
|
|
2472
|
+
value
|
|
2229
2473
|
} = partialNewState;
|
|
2230
2474
|
if (isEmptyString(value)) {
|
|
2231
|
-
return
|
|
2232
|
-
...partialNewState,
|
|
2233
|
-
minLineY: 0,
|
|
2234
|
-
maxLineY: 0,
|
|
2235
|
-
deltaY: 0,
|
|
2236
|
-
items: [],
|
|
2237
|
-
listItems: [],
|
|
2238
|
-
matchCount: 0,
|
|
2239
|
-
message: '',
|
|
2240
|
-
loaded: true,
|
|
2241
|
-
searchInputErrorMessage: ''
|
|
2242
|
-
};
|
|
2475
|
+
return handleUpdateEmpty(state, update);
|
|
2243
2476
|
}
|
|
2244
2477
|
const searchInputErrorMessage = validateSearchInput(value, flags);
|
|
2245
2478
|
if (searchInputErrorMessage) {
|
|
2246
|
-
return
|
|
2247
|
-
...partialNewState,
|
|
2248
|
-
searchInputErrorMessage: searchInputErrorMessage
|
|
2249
|
-
};
|
|
2479
|
+
return handleUpdateValidationError(state, update, searchInputErrorMessage);
|
|
2250
2480
|
}
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
const results = await textSearch(root, value, {
|
|
2254
|
-
threads,
|
|
2255
|
-
isCaseSensitive: Boolean(flags & MatchCase$2),
|
|
2256
|
-
useRegularExpression: Boolean(flags & UseRegularExpression$2),
|
|
2257
|
-
exclude: excludeValue,
|
|
2258
|
-
include: includeValue,
|
|
2259
|
-
assetDir: state.assetDir,
|
|
2260
|
-
root,
|
|
2261
|
-
query: value,
|
|
2262
|
-
scheme,
|
|
2263
|
-
flags,
|
|
2264
|
-
matchWholeWord: Boolean(flags & MatchWholeWord$2)
|
|
2265
|
-
}, state.assetDir, state.platform);
|
|
2266
|
-
if (!Array.isArray(results)) {
|
|
2267
|
-
throw new TypeError('results must be of type array');
|
|
2481
|
+
if (incrementalSearch) {
|
|
2482
|
+
return await handleUpdateIncremental(state, update);
|
|
2268
2483
|
}
|
|
2269
|
-
|
|
2270
|
-
fileCount,
|
|
2271
|
-
resultCount
|
|
2272
|
-
} = getTextSearchResultCounts(results);
|
|
2273
|
-
const message = getStatusMessage(resultCount, fileCount);
|
|
2274
|
-
const total = results.length;
|
|
2275
|
-
const contentHeight = total * itemHeight;
|
|
2276
|
-
const listHeight = height - headerHeight;
|
|
2277
|
-
const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
|
|
2278
|
-
const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
|
|
2279
|
-
const maxLineY = Math.min(numberOfVisible, total);
|
|
2280
|
-
const finalDeltaY = Math.max(contentHeight - listHeight, 0);
|
|
2281
|
-
const visible = results.slice(0, maxLineY);
|
|
2282
|
-
const icons = await getFileIcons(visible);
|
|
2283
|
-
return {
|
|
2284
|
-
...partialNewState,
|
|
2285
|
-
minLineY: 0,
|
|
2286
|
-
deltaY: 0,
|
|
2287
|
-
value,
|
|
2288
|
-
items: results,
|
|
2289
|
-
listItems: results,
|
|
2290
|
-
message,
|
|
2291
|
-
maxLineY: maxLineY,
|
|
2292
|
-
scrollBarHeight,
|
|
2293
|
-
finalDeltaY,
|
|
2294
|
-
threads,
|
|
2295
|
-
fileCount,
|
|
2296
|
-
matchCount: resultCount,
|
|
2297
|
-
loaded: true,
|
|
2298
|
-
icons,
|
|
2299
|
-
searchInputErrorMessage: ''
|
|
2300
|
-
};
|
|
2484
|
+
return await handleUpdateFull(state, update);
|
|
2301
2485
|
} catch (error) {
|
|
2302
2486
|
handleError(error);
|
|
2303
|
-
return
|
|
2304
|
-
...partialNewState,
|
|
2305
|
-
message: `${error}`,
|
|
2306
|
-
items: [],
|
|
2307
|
-
listItems: [],
|
|
2308
|
-
matchCount: 0,
|
|
2309
|
-
fileCount: 0,
|
|
2310
|
-
minLineY: 0,
|
|
2311
|
-
maxLineY: 0
|
|
2312
|
-
};
|
|
2487
|
+
return handleUpdateError(state, update, error);
|
|
2313
2488
|
}
|
|
2314
2489
|
};
|
|
2315
2490
|
|
|
@@ -4464,6 +4639,12 @@ const replaceAllAndPrompt = async (workspacePath, items, replacement, matchCount
|
|
|
4464
4639
|
return true;
|
|
4465
4640
|
};
|
|
4466
4641
|
|
|
4642
|
+
const rerender = state => {
|
|
4643
|
+
return {
|
|
4644
|
+
...state
|
|
4645
|
+
};
|
|
4646
|
+
};
|
|
4647
|
+
|
|
4467
4648
|
const saveState = uid => {
|
|
4468
4649
|
const {
|
|
4469
4650
|
newState
|
|
@@ -4700,6 +4881,7 @@ const commandMap = {
|
|
|
4700
4881
|
'TextSearch.previousHistoryResult': wrapCommand(previousHistoryResult),
|
|
4701
4882
|
'TextSearch.refresh': wrapCommand(refresh),
|
|
4702
4883
|
'TextSearch.replaceAll': wrapCommand(replaceAll),
|
|
4884
|
+
'TextSearch.rerender': rerender,
|
|
4703
4885
|
'TextSearch.selectIndex': wrapCommand(selectIndex),
|
|
4704
4886
|
'TextSearch.submit': wrapCommand(submit),
|
|
4705
4887
|
'TextSearch.toggleMatchCase': wrapCommand(toggleMatchCase),
|