@lvce-editor/text-search-worker 4.9.0 → 4.11.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 +333 -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,48 @@ const collapseDetails = state => {
|
|
|
1119
1141
|
};
|
|
1120
1142
|
|
|
1121
1143
|
const rpcs = Object.create(null);
|
|
1122
|
-
const set$
|
|
1144
|
+
const set$g = (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$g(rpcId, rpc);
|
|
1169
|
+
},
|
|
1170
|
+
async dispose() {
|
|
1171
|
+
const rpc = get$1(rpcId);
|
|
1172
|
+
await rpc.dispose();
|
|
1173
|
+
}
|
|
1174
|
+
};
|
|
1141
1175
|
};
|
|
1176
|
+
const RendererWorker$1 = 1;
|
|
1177
|
+
const {
|
|
1178
|
+
invoke: invoke$3,
|
|
1179
|
+
invokeAndTransfer: invokeAndTransfer$3,
|
|
1180
|
+
set: set$3} = create$3(RendererWorker$1);
|
|
1142
1181
|
const RendererWorker = {
|
|
1143
1182
|
__proto__: null,
|
|
1144
|
-
invoke: invoke$
|
|
1145
|
-
invokeAndTransfer: invokeAndTransfer$
|
|
1146
|
-
set: set$
|
|
1183
|
+
invoke: invoke$3,
|
|
1184
|
+
invokeAndTransfer: invokeAndTransfer$3,
|
|
1185
|
+
set: set$3
|
|
1147
1186
|
};
|
|
1148
1187
|
|
|
1149
1188
|
const {
|
|
@@ -1232,6 +1271,8 @@ const {
|
|
|
1232
1271
|
wrapCommand
|
|
1233
1272
|
} = create$2();
|
|
1234
1273
|
|
|
1274
|
+
const List$1 = 1;
|
|
1275
|
+
|
|
1235
1276
|
const create$1 = ({
|
|
1236
1277
|
itemHeight,
|
|
1237
1278
|
headerHeight = 0,
|
|
@@ -1261,7 +1302,6 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
|
|
|
1261
1302
|
uid,
|
|
1262
1303
|
searchResults: [],
|
|
1263
1304
|
stats: {},
|
|
1264
|
-
searchId: -1,
|
|
1265
1305
|
value,
|
|
1266
1306
|
disposed: false,
|
|
1267
1307
|
fileCount: 0,
|
|
@@ -1299,7 +1339,10 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
|
|
|
1299
1339
|
platform,
|
|
1300
1340
|
searchInputErrorMessage: '',
|
|
1301
1341
|
history: [],
|
|
1302
|
-
historyIndex: -1
|
|
1342
|
+
historyIndex: -1,
|
|
1343
|
+
viewMode: List$1,
|
|
1344
|
+
incrementalSearch: false,
|
|
1345
|
+
searchId: ''
|
|
1303
1346
|
};
|
|
1304
1347
|
set(uid, state, state);
|
|
1305
1348
|
return state;
|
|
@@ -1833,7 +1876,7 @@ const focusSearchValueNext = state => {
|
|
|
1833
1876
|
return focusMatchCase$1(state);
|
|
1834
1877
|
};
|
|
1835
1878
|
|
|
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'];
|
|
1879
|
+
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
1880
|
|
|
1838
1881
|
const getCommandIds = () => {
|
|
1839
1882
|
return commandIds;
|
|
@@ -1920,6 +1963,42 @@ const handleError = error => {
|
|
|
1920
1963
|
console.error(`[text-search-worker] ${error}`);
|
|
1921
1964
|
};
|
|
1922
1965
|
|
|
1966
|
+
const handleUpdateEmpty = (state, update) => {
|
|
1967
|
+
const partialNewState = {
|
|
1968
|
+
...state,
|
|
1969
|
+
...update
|
|
1970
|
+
};
|
|
1971
|
+
return {
|
|
1972
|
+
...partialNewState,
|
|
1973
|
+
minLineY: 0,
|
|
1974
|
+
maxLineY: 0,
|
|
1975
|
+
deltaY: 0,
|
|
1976
|
+
items: [],
|
|
1977
|
+
listItems: [],
|
|
1978
|
+
matchCount: 0,
|
|
1979
|
+
message: '',
|
|
1980
|
+
loaded: true,
|
|
1981
|
+
searchInputErrorMessage: ''
|
|
1982
|
+
};
|
|
1983
|
+
};
|
|
1984
|
+
|
|
1985
|
+
const handleUpdateError = async (state, update, error) => {
|
|
1986
|
+
const partialNewState = {
|
|
1987
|
+
...state,
|
|
1988
|
+
...update
|
|
1989
|
+
};
|
|
1990
|
+
return {
|
|
1991
|
+
...partialNewState,
|
|
1992
|
+
message: `${error}`,
|
|
1993
|
+
items: [],
|
|
1994
|
+
listItems: [],
|
|
1995
|
+
matchCount: 0,
|
|
1996
|
+
fileCount: 0,
|
|
1997
|
+
minLineY: 0,
|
|
1998
|
+
maxLineY: 0
|
|
1999
|
+
};
|
|
2000
|
+
};
|
|
2001
|
+
|
|
1923
2002
|
const getFileIcon = async result => {
|
|
1924
2003
|
if (result.type === File) {
|
|
1925
2004
|
return invoke$2('IconTheme.getFileIcon', {
|
|
@@ -1970,12 +2049,6 @@ const getTextSearchResultCounts = results => {
|
|
|
1970
2049
|
};
|
|
1971
2050
|
};
|
|
1972
2051
|
|
|
1973
|
-
const EmptyString = '';
|
|
1974
|
-
|
|
1975
|
-
const isEmptyString = string => {
|
|
1976
|
-
return string === EmptyString;
|
|
1977
|
-
};
|
|
1978
|
-
|
|
1979
2052
|
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
1980
2053
|
if (size >= contentSize) {
|
|
1981
2054
|
return 0;
|
|
@@ -2071,7 +2144,6 @@ const state$1 = {
|
|
|
2071
2144
|
};
|
|
2072
2145
|
const getOrCreate$1 = () => {
|
|
2073
2146
|
if (!state$1.rpc) {
|
|
2074
|
-
// @ts-ignore
|
|
2075
2147
|
state$1.rpc = launchSearchProcess();
|
|
2076
2148
|
}
|
|
2077
2149
|
return state$1.rpc;
|
|
@@ -2148,7 +2220,7 @@ const textSearch$2 = async (scheme, root, query, options, assetDir, platform) =>
|
|
|
2148
2220
|
return results.results;
|
|
2149
2221
|
};
|
|
2150
2222
|
|
|
2151
|
-
const textSearch$1 = (scheme, root, query) => {
|
|
2223
|
+
const textSearch$1 = async (scheme, root, query) => {
|
|
2152
2224
|
// TODO ask renderer worker for files
|
|
2153
2225
|
const entries = Object.entries({});
|
|
2154
2226
|
const results = [];
|
|
@@ -2190,6 +2262,185 @@ const textSearch = async (root, query, options, assetDir, platform) => {
|
|
|
2190
2262
|
return results;
|
|
2191
2263
|
};
|
|
2192
2264
|
|
|
2265
|
+
const handleUpdateFull = async (state, update) => {
|
|
2266
|
+
const partialNewState = {
|
|
2267
|
+
...state,
|
|
2268
|
+
...update
|
|
2269
|
+
};
|
|
2270
|
+
const {
|
|
2271
|
+
height,
|
|
2272
|
+
itemHeight,
|
|
2273
|
+
minimumSliderSize,
|
|
2274
|
+
headerHeight,
|
|
2275
|
+
flags,
|
|
2276
|
+
value,
|
|
2277
|
+
threads,
|
|
2278
|
+
includeValue,
|
|
2279
|
+
excludeValue
|
|
2280
|
+
} = partialNewState;
|
|
2281
|
+
const root = state.workspacePath;
|
|
2282
|
+
const scheme = getProtocol$1(root);
|
|
2283
|
+
const results = await textSearch(root, value, {
|
|
2284
|
+
threads,
|
|
2285
|
+
isCaseSensitive: Boolean(flags & MatchCase$2),
|
|
2286
|
+
useRegularExpression: Boolean(flags & UseRegularExpression$2),
|
|
2287
|
+
exclude: excludeValue,
|
|
2288
|
+
include: includeValue,
|
|
2289
|
+
assetDir: state.assetDir,
|
|
2290
|
+
root,
|
|
2291
|
+
query: value,
|
|
2292
|
+
scheme,
|
|
2293
|
+
flags,
|
|
2294
|
+
matchWholeWord: Boolean(flags & MatchWholeWord$2)
|
|
2295
|
+
}, state.assetDir, state.platform);
|
|
2296
|
+
if (!Array.isArray(results)) {
|
|
2297
|
+
throw new TypeError('results must be of type array');
|
|
2298
|
+
}
|
|
2299
|
+
const {
|
|
2300
|
+
fileCount,
|
|
2301
|
+
resultCount
|
|
2302
|
+
} = getTextSearchResultCounts(results);
|
|
2303
|
+
const message = getStatusMessage(resultCount, fileCount);
|
|
2304
|
+
const total = results.length;
|
|
2305
|
+
const contentHeight = total * itemHeight;
|
|
2306
|
+
const listHeight = height - headerHeight;
|
|
2307
|
+
const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
|
|
2308
|
+
const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
|
|
2309
|
+
const maxLineY = Math.min(numberOfVisible, total);
|
|
2310
|
+
const finalDeltaY = Math.max(contentHeight - listHeight, 0);
|
|
2311
|
+
const visible = results.slice(0, maxLineY);
|
|
2312
|
+
const icons = await getFileIcons(visible);
|
|
2313
|
+
return {
|
|
2314
|
+
...partialNewState,
|
|
2315
|
+
minLineY: 0,
|
|
2316
|
+
deltaY: 0,
|
|
2317
|
+
value,
|
|
2318
|
+
items: results,
|
|
2319
|
+
listItems: results,
|
|
2320
|
+
message,
|
|
2321
|
+
maxLineY: maxLineY,
|
|
2322
|
+
scrollBarHeight,
|
|
2323
|
+
finalDeltaY,
|
|
2324
|
+
threads,
|
|
2325
|
+
fileCount,
|
|
2326
|
+
matchCount: resultCount,
|
|
2327
|
+
loaded: true,
|
|
2328
|
+
icons,
|
|
2329
|
+
searchInputErrorMessage: ''
|
|
2330
|
+
};
|
|
2331
|
+
};
|
|
2332
|
+
|
|
2333
|
+
const waitForNextFrame = async () => {
|
|
2334
|
+
await new Promise(r => {
|
|
2335
|
+
requestAnimationFrame(r);
|
|
2336
|
+
});
|
|
2337
|
+
};
|
|
2338
|
+
const textSearchIncremental = async (root, query, options, assetDir, platform, searchId, uid) => {
|
|
2339
|
+
string(root);
|
|
2340
|
+
string(query);
|
|
2341
|
+
const ripGrepArgs = getRipGrepArgs({
|
|
2342
|
+
...options,
|
|
2343
|
+
searchString: query
|
|
2344
|
+
});
|
|
2345
|
+
const actualOptions = {
|
|
2346
|
+
ripGrepArgs,
|
|
2347
|
+
searchDir: root,
|
|
2348
|
+
id: searchId
|
|
2349
|
+
};
|
|
2350
|
+
const resultPromise = invoke$1('TextSearch.searchIncremental', actualOptions);
|
|
2351
|
+
for (let i = 0; i < 100; i++) {
|
|
2352
|
+
const latest = get(uid);
|
|
2353
|
+
const {
|
|
2354
|
+
newState
|
|
2355
|
+
} = latest;
|
|
2356
|
+
const {
|
|
2357
|
+
minLineY,
|
|
2358
|
+
height,
|
|
2359
|
+
headerHeight,
|
|
2360
|
+
itemHeight
|
|
2361
|
+
} = newState;
|
|
2362
|
+
const listHeight = height - headerHeight;
|
|
2363
|
+
const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
|
|
2364
|
+
const visible = await invoke$1('TextSearch.getIncrementalResults', searchId, minLineY, minLineY + numberOfVisible);
|
|
2365
|
+
const latest2 = get(uid);
|
|
2366
|
+
if (!latest2 || latest2.newState.searchId !== searchId) {
|
|
2367
|
+
return;
|
|
2368
|
+
}
|
|
2369
|
+
const updatedState2 = {
|
|
2370
|
+
...latest2.newState,
|
|
2371
|
+
items: visible,
|
|
2372
|
+
listItems: visible,
|
|
2373
|
+
minLineY: 0,
|
|
2374
|
+
maxLineY: visible.length
|
|
2375
|
+
};
|
|
2376
|
+
set(uid, latest2.oldState, updatedState2);
|
|
2377
|
+
// @ts-ignore
|
|
2378
|
+
await invoke$2('Search.rerender');
|
|
2379
|
+
await waitForNextFrame();
|
|
2380
|
+
}
|
|
2381
|
+
await resultPromise;
|
|
2382
|
+
};
|
|
2383
|
+
|
|
2384
|
+
const handleUpdateIncremental = async (state, update) => {
|
|
2385
|
+
const partialNewState = {
|
|
2386
|
+
...state,
|
|
2387
|
+
...update
|
|
2388
|
+
};
|
|
2389
|
+
const {
|
|
2390
|
+
flags,
|
|
2391
|
+
value,
|
|
2392
|
+
threads,
|
|
2393
|
+
includeValue,
|
|
2394
|
+
excludeValue,
|
|
2395
|
+
uid,
|
|
2396
|
+
assetDir,
|
|
2397
|
+
platform
|
|
2398
|
+
} = partialNewState;
|
|
2399
|
+
const root = state.workspacePath;
|
|
2400
|
+
const scheme = getProtocol$1(root);
|
|
2401
|
+
const searchId = crypto.randomUUID(); // TODO try to avoid side effect
|
|
2402
|
+
const latest1 = get(uid);
|
|
2403
|
+
const updatedState1 = {
|
|
2404
|
+
...latest1.newState,
|
|
2405
|
+
...partialNewState,
|
|
2406
|
+
searchId
|
|
2407
|
+
};
|
|
2408
|
+
set(uid, latest1.oldState, updatedState1);
|
|
2409
|
+
|
|
2410
|
+
// TODO await promise?
|
|
2411
|
+
void textSearchIncremental(root, value, {
|
|
2412
|
+
threads,
|
|
2413
|
+
isCaseSensitive: Boolean(flags & MatchCase$2),
|
|
2414
|
+
useRegularExpression: Boolean(flags & UseRegularExpression$2),
|
|
2415
|
+
exclude: excludeValue,
|
|
2416
|
+
include: includeValue,
|
|
2417
|
+
assetDir: assetDir,
|
|
2418
|
+
root,
|
|
2419
|
+
query: value,
|
|
2420
|
+
scheme,
|
|
2421
|
+
flags,
|
|
2422
|
+
matchWholeWord: Boolean(flags & MatchWholeWord$2)
|
|
2423
|
+
}, assetDir, platform, searchId, uid);
|
|
2424
|
+
return state;
|
|
2425
|
+
};
|
|
2426
|
+
|
|
2427
|
+
const handleUpdateValidationError = (state, update, searchInputErrorMessage) => {
|
|
2428
|
+
const partialNewState = {
|
|
2429
|
+
...state,
|
|
2430
|
+
...update
|
|
2431
|
+
};
|
|
2432
|
+
return {
|
|
2433
|
+
...partialNewState,
|
|
2434
|
+
searchInputErrorMessage: searchInputErrorMessage
|
|
2435
|
+
};
|
|
2436
|
+
};
|
|
2437
|
+
|
|
2438
|
+
const EmptyString = '';
|
|
2439
|
+
|
|
2440
|
+
const isEmptyString = string => {
|
|
2441
|
+
return string === EmptyString;
|
|
2442
|
+
};
|
|
2443
|
+
|
|
2193
2444
|
// Based on https://github.com/microsoft/vscode/blob/ad375c92764b72a1f28f3e1626563e9e41e5c740/src/vs/workbench/contrib/search/browser/searchWidget.ts#L393 by Microsoft (License MIT)
|
|
2194
2445
|
|
|
2195
2446
|
const validateSearchInput = (value, flags) => {
|
|
@@ -2211,105 +2462,32 @@ const validateSearchInput = (value, flags) => {
|
|
|
2211
2462
|
};
|
|
2212
2463
|
|
|
2213
2464
|
const handleUpdate = async (state, update) => {
|
|
2465
|
+
const {
|
|
2466
|
+
incrementalSearch
|
|
2467
|
+
} = state;
|
|
2214
2468
|
const partialNewState = {
|
|
2215
2469
|
...state,
|
|
2216
2470
|
...update
|
|
2217
2471
|
};
|
|
2218
2472
|
try {
|
|
2219
2473
|
const {
|
|
2220
|
-
height,
|
|
2221
|
-
itemHeight,
|
|
2222
|
-
minimumSliderSize,
|
|
2223
|
-
headerHeight,
|
|
2224
2474
|
flags,
|
|
2225
|
-
value
|
|
2226
|
-
threads,
|
|
2227
|
-
includeValue,
|
|
2228
|
-
excludeValue
|
|
2475
|
+
value
|
|
2229
2476
|
} = partialNewState;
|
|
2230
2477
|
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
|
-
};
|
|
2478
|
+
return handleUpdateEmpty(state, update);
|
|
2243
2479
|
}
|
|
2244
2480
|
const searchInputErrorMessage = validateSearchInput(value, flags);
|
|
2245
2481
|
if (searchInputErrorMessage) {
|
|
2246
|
-
return
|
|
2247
|
-
...partialNewState,
|
|
2248
|
-
searchInputErrorMessage: searchInputErrorMessage
|
|
2249
|
-
};
|
|
2482
|
+
return handleUpdateValidationError(state, update, searchInputErrorMessage);
|
|
2250
2483
|
}
|
|
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');
|
|
2484
|
+
if (incrementalSearch) {
|
|
2485
|
+
return await handleUpdateIncremental(state, update);
|
|
2268
2486
|
}
|
|
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
|
-
};
|
|
2487
|
+
return await handleUpdateFull(state, update);
|
|
2301
2488
|
} catch (error) {
|
|
2302
2489
|
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
|
-
};
|
|
2490
|
+
return handleUpdateError(state, update, error);
|
|
2313
2491
|
}
|
|
2314
2492
|
};
|
|
2315
2493
|
|
|
@@ -4464,6 +4642,12 @@ const replaceAllAndPrompt = async (workspacePath, items, replacement, matchCount
|
|
|
4464
4642
|
return true;
|
|
4465
4643
|
};
|
|
4466
4644
|
|
|
4645
|
+
const rerender = state => {
|
|
4646
|
+
return {
|
|
4647
|
+
...state
|
|
4648
|
+
};
|
|
4649
|
+
};
|
|
4650
|
+
|
|
4467
4651
|
const saveState = uid => {
|
|
4468
4652
|
const {
|
|
4469
4653
|
newState
|
|
@@ -4700,6 +4884,7 @@ const commandMap = {
|
|
|
4700
4884
|
'TextSearch.previousHistoryResult': wrapCommand(previousHistoryResult),
|
|
4701
4885
|
'TextSearch.refresh': wrapCommand(refresh),
|
|
4702
4886
|
'TextSearch.replaceAll': wrapCommand(replaceAll),
|
|
4887
|
+
'TextSearch.rerender': rerender,
|
|
4703
4888
|
'TextSearch.selectIndex': wrapCommand(selectIndex),
|
|
4704
4889
|
'TextSearch.submit': wrapCommand(submit),
|
|
4705
4890
|
'TextSearch.toggleMatchCase': wrapCommand(toggleMatchCase),
|