@lvce-editor/text-search-worker 2.1.0 → 2.3.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/README.md +1 -1
- package/dist/textSearchWorkerMain.js +588 -93
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,45 @@ const execute = (command, ...args) => {
|
|
|
18
18
|
return fn(...args);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
const ListItem = 22;
|
|
22
|
+
|
|
23
|
+
const User = 1;
|
|
24
|
+
const Script = 2;
|
|
25
|
+
|
|
26
|
+
const minimumSliderSize = 20;
|
|
27
|
+
|
|
28
|
+
const states = Object.create(null);
|
|
29
|
+
const get$2 = uid => {
|
|
30
|
+
return states[uid];
|
|
31
|
+
};
|
|
32
|
+
const set$2 = (uid, state) => {
|
|
33
|
+
states[uid] = state;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const create$5 = ({
|
|
37
|
+
itemHeight,
|
|
38
|
+
headerHeight = 0,
|
|
39
|
+
minimumSliderSize = 20
|
|
40
|
+
}) => {
|
|
41
|
+
return {
|
|
42
|
+
deltaY: 0,
|
|
43
|
+
minLineY: 0,
|
|
44
|
+
maxLineY: 0,
|
|
45
|
+
finalDeltaY: 0,
|
|
46
|
+
itemHeight,
|
|
47
|
+
headerHeight,
|
|
48
|
+
items: [],
|
|
49
|
+
minimumSliderSize,
|
|
50
|
+
focusedIndex: -1,
|
|
51
|
+
touchOffsetY: 0,
|
|
52
|
+
touchTimeStamp: 0,
|
|
53
|
+
touchDifference: 0,
|
|
54
|
+
scrollBarHeight: 0,
|
|
55
|
+
scrollBarActive: false
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const Empty$1 = 0;
|
|
21
60
|
const FocusSearchInput = 21;
|
|
22
61
|
const FocusSearchReplaceInput = 31;
|
|
23
62
|
const FocusSearchMatchCase = 32;
|
|
@@ -26,6 +65,46 @@ const FocusSearchWholeWord = 34;
|
|
|
26
65
|
const FocusSearchReplaceAll = 35;
|
|
27
66
|
const FocusSearchPreserveCase = 36;
|
|
28
67
|
|
|
68
|
+
const create$4 = (uid, x, y, width, height, workspacePath) => {
|
|
69
|
+
const state = {
|
|
70
|
+
uid,
|
|
71
|
+
searchResults: [],
|
|
72
|
+
stats: {},
|
|
73
|
+
searchId: -1,
|
|
74
|
+
value: '',
|
|
75
|
+
disposed: false,
|
|
76
|
+
fileCount: 0,
|
|
77
|
+
x,
|
|
78
|
+
y,
|
|
79
|
+
width,
|
|
80
|
+
height,
|
|
81
|
+
...create$5({
|
|
82
|
+
itemHeight: ListItem,
|
|
83
|
+
minimumSliderSize: minimumSliderSize,
|
|
84
|
+
headerHeight: 61 // TODO
|
|
85
|
+
}),
|
|
86
|
+
threads: 0,
|
|
87
|
+
replaceExpanded: false,
|
|
88
|
+
useRegularExpression: false,
|
|
89
|
+
matchCase: false,
|
|
90
|
+
matchWholeWord: false,
|
|
91
|
+
replacement: '',
|
|
92
|
+
matchCount: 0,
|
|
93
|
+
listFocused: false,
|
|
94
|
+
listFocusedIndex: -1,
|
|
95
|
+
inputSource: User,
|
|
96
|
+
workspacePath: workspacePath,
|
|
97
|
+
includeValue: '',
|
|
98
|
+
excludeValue: '',
|
|
99
|
+
detailsExpanded: false,
|
|
100
|
+
focus: Empty$1,
|
|
101
|
+
loaded: false,
|
|
102
|
+
message: '',
|
|
103
|
+
collapsedPaths: []
|
|
104
|
+
};
|
|
105
|
+
set$2(uid, state);
|
|
106
|
+
};
|
|
107
|
+
|
|
29
108
|
const focusMatchCase$1 = state => {
|
|
30
109
|
return {
|
|
31
110
|
...state,
|
|
@@ -80,7 +159,7 @@ const MaskIcon = 'MaskIcon';
|
|
|
80
159
|
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
81
160
|
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
82
161
|
const MultilineInputBox = 'MultilineInputBox';
|
|
83
|
-
const Search = 'Search';
|
|
162
|
+
const Search$1 = 'Search';
|
|
84
163
|
const SearchField = 'SearchField';
|
|
85
164
|
const SearchFieldButtons = 'SearchFieldButtons';
|
|
86
165
|
const SearchFieldContainer = 'SearchFieldContainer';
|
|
@@ -182,6 +261,12 @@ const getType$1 = value => {
|
|
|
182
261
|
return 'unknown';
|
|
183
262
|
}
|
|
184
263
|
};
|
|
264
|
+
const number$1 = value => {
|
|
265
|
+
const type = getType$1(value);
|
|
266
|
+
if (type !== 'number') {
|
|
267
|
+
throw new AssertionError$1('expected value to be of type number');
|
|
268
|
+
}
|
|
269
|
+
};
|
|
185
270
|
const string = value => {
|
|
186
271
|
const type = getType$1(value);
|
|
187
272
|
if (type !== 'string') {
|
|
@@ -230,6 +315,23 @@ const UiStrings = {
|
|
|
230
315
|
ViewAsTree: 'View as Tree',
|
|
231
316
|
CollapseAll: 'Collapse All'
|
|
232
317
|
};
|
|
318
|
+
const noResults = () => {
|
|
319
|
+
return i18nString(UiStrings.NoResults);
|
|
320
|
+
};
|
|
321
|
+
const oneResult = () => {
|
|
322
|
+
return i18nString(UiStrings.Oneresult);
|
|
323
|
+
};
|
|
324
|
+
const manyResultsInOneFile = resultCount => {
|
|
325
|
+
return i18nString(UiStrings.ManyResultsInOneFile, {
|
|
326
|
+
PH1: resultCount
|
|
327
|
+
});
|
|
328
|
+
};
|
|
329
|
+
const manyResultsInManyFiles = (resultCount, fileResultCount) => {
|
|
330
|
+
return i18nString(UiStrings.ManyResultsInManyFiles, {
|
|
331
|
+
PH1: resultCount,
|
|
332
|
+
PH2: fileResultCount
|
|
333
|
+
});
|
|
334
|
+
};
|
|
233
335
|
const refresh = () => {
|
|
234
336
|
return i18nString(UiStrings.Refresh);
|
|
235
337
|
};
|
|
@@ -275,6 +377,115 @@ const getActions = () => {
|
|
|
275
377
|
}];
|
|
276
378
|
};
|
|
277
379
|
|
|
380
|
+
const getFileIcon = () => {
|
|
381
|
+
return '';
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
const File$1 = 1;
|
|
385
|
+
const Match = 2;
|
|
386
|
+
|
|
387
|
+
// TODO this should be in FileSystem module
|
|
388
|
+
const pathBaseName = path => {
|
|
389
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
390
|
+
};
|
|
391
|
+
const getAbsolutePath = relativePath => {
|
|
392
|
+
if (relativePath.startsWith('./')) {
|
|
393
|
+
return `/${relativePath.slice(2)}`; // TODO support windows paths
|
|
394
|
+
}
|
|
395
|
+
return `/${relativePath}`; // TODO support windows paths
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
const getDisplayResult = (result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex) => {
|
|
399
|
+
const {
|
|
400
|
+
type,
|
|
401
|
+
text,
|
|
402
|
+
lineNumber,
|
|
403
|
+
start
|
|
404
|
+
} = result;
|
|
405
|
+
const posInSet = i + 1;
|
|
406
|
+
const top = i * itemHeight;
|
|
407
|
+
const focused = i === focusedIndex;
|
|
408
|
+
switch (type) {
|
|
409
|
+
case File$1:
|
|
410
|
+
const path = text;
|
|
411
|
+
const absolutePath = getAbsolutePath(path);
|
|
412
|
+
const baseName = pathBaseName(path);
|
|
413
|
+
return {
|
|
414
|
+
title: absolutePath,
|
|
415
|
+
type: File$1,
|
|
416
|
+
text: baseName,
|
|
417
|
+
icon: getFileIcon(),
|
|
418
|
+
posInSet,
|
|
419
|
+
setSize,
|
|
420
|
+
top,
|
|
421
|
+
lineNumber,
|
|
422
|
+
matchStart: 0,
|
|
423
|
+
matchLength: 0,
|
|
424
|
+
replacement: '',
|
|
425
|
+
depth: 0,
|
|
426
|
+
matchCount: 0,
|
|
427
|
+
focused
|
|
428
|
+
};
|
|
429
|
+
case Match:
|
|
430
|
+
return {
|
|
431
|
+
title: text,
|
|
432
|
+
type: Match,
|
|
433
|
+
text: text,
|
|
434
|
+
icon: '',
|
|
435
|
+
posInSet,
|
|
436
|
+
setSize,
|
|
437
|
+
top,
|
|
438
|
+
lineNumber,
|
|
439
|
+
matchStart: start,
|
|
440
|
+
matchLength: searchTermLength,
|
|
441
|
+
replacement,
|
|
442
|
+
depth: 1,
|
|
443
|
+
matchCount: 0,
|
|
444
|
+
focused
|
|
445
|
+
};
|
|
446
|
+
default:
|
|
447
|
+
throw new Error('unexpected search result type');
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
const getFilteredResults = (results, collapsedPaths) => {
|
|
452
|
+
const filteredResults = [];
|
|
453
|
+
let isExcluded = false;
|
|
454
|
+
for (const result of results) {
|
|
455
|
+
if (result.type === File$1) {
|
|
456
|
+
if (collapsedPaths.includes(result.text)) {
|
|
457
|
+
isExcluded = true;
|
|
458
|
+
} else {
|
|
459
|
+
isExcluded = false;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (!isExcluded) {
|
|
463
|
+
filteredResults.push(result);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
return filteredResults;
|
|
467
|
+
};
|
|
468
|
+
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, collapsedPaths, focusedIndex) => {
|
|
469
|
+
const displayResults = [];
|
|
470
|
+
const filteredResults = getFilteredResults(results, collapsedPaths);
|
|
471
|
+
const setSize = resultCount;
|
|
472
|
+
const searchTermLength = searchTerm.length;
|
|
473
|
+
let fileResult = {
|
|
474
|
+
matchCount: 0
|
|
475
|
+
};
|
|
476
|
+
for (let i = minLineY; i < maxLineY; i++) {
|
|
477
|
+
const result = filteredResults[i];
|
|
478
|
+
const displayResult = getDisplayResult(result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex);
|
|
479
|
+
displayResults.push(displayResult);
|
|
480
|
+
if (result.type === File$1) {
|
|
481
|
+
fileResult = displayResult;
|
|
482
|
+
} else {
|
|
483
|
+
fileResult.matchCount++;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return displayResults;
|
|
487
|
+
};
|
|
488
|
+
|
|
278
489
|
const HandleClick = 'handleClick';
|
|
279
490
|
const HandleHeaderClick = 'handleHeaderClick';
|
|
280
491
|
const HandleHeaderFocusIn = 'handleHeaderFocusIn';
|
|
@@ -443,11 +654,6 @@ const getFileIconVirtualDom = icon => {
|
|
|
443
654
|
};
|
|
444
655
|
};
|
|
445
656
|
|
|
446
|
-
const File$1 = 1;
|
|
447
|
-
const Match = 2;
|
|
448
|
-
|
|
449
|
-
const PaddingRight = '12px';
|
|
450
|
-
|
|
451
657
|
const deleted = {
|
|
452
658
|
type: Del,
|
|
453
659
|
className: HighlightDeleted,
|
|
@@ -487,10 +693,11 @@ const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) =
|
|
|
487
693
|
}
|
|
488
694
|
return dom;
|
|
489
695
|
};
|
|
490
|
-
|
|
491
|
-
|
|
696
|
+
|
|
697
|
+
const PaddingRight = '12px';
|
|
698
|
+
|
|
699
|
+
const getSearchResultVirtualDom = rowInfo => {
|
|
492
700
|
const {
|
|
493
|
-
top,
|
|
494
701
|
type,
|
|
495
702
|
matchStart,
|
|
496
703
|
matchLength,
|
|
@@ -550,8 +757,9 @@ const renderRow = rowInfo => {
|
|
|
550
757
|
});
|
|
551
758
|
return dom;
|
|
552
759
|
};
|
|
760
|
+
|
|
553
761
|
const getSearchResultsVirtualDom = visibleItems => {
|
|
554
|
-
return visibleItems.flatMap(
|
|
762
|
+
return visibleItems.flatMap(getSearchResultVirtualDom);
|
|
555
763
|
};
|
|
556
764
|
|
|
557
765
|
const mergeClassNames = (...classNames) => {
|
|
@@ -565,7 +773,7 @@ const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWhol
|
|
|
565
773
|
const dom = [];
|
|
566
774
|
dom.push({
|
|
567
775
|
type: Div,
|
|
568
|
-
className: mergeClassNames(Viewlet, Search),
|
|
776
|
+
className: mergeClassNames(Viewlet, Search$1),
|
|
569
777
|
childCount: 2
|
|
570
778
|
});
|
|
571
779
|
dom.push(...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded));
|
|
@@ -589,6 +797,76 @@ const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWhol
|
|
|
589
797
|
return dom;
|
|
590
798
|
};
|
|
591
799
|
|
|
800
|
+
const handleIconThemeChange = state => {
|
|
801
|
+
const {
|
|
802
|
+
items
|
|
803
|
+
} = state;
|
|
804
|
+
const newItems = [...items];
|
|
805
|
+
return {
|
|
806
|
+
...state,
|
|
807
|
+
items: newItems
|
|
808
|
+
};
|
|
809
|
+
};
|
|
810
|
+
|
|
811
|
+
const handleError = async (error, notify = true, prefix = '') => {
|
|
812
|
+
console.error(`[text-search-worker] ${error}`);
|
|
813
|
+
};
|
|
814
|
+
|
|
815
|
+
// TODO optimize this function to return the minimum number
|
|
816
|
+
// of visible items needed, e.g. when not scrolled 5 items with
|
|
817
|
+
// 20px fill 100px but when scrolled 6 items are needed
|
|
818
|
+
const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
819
|
+
return Math.ceil(listHeight / itemHeight) + 1;
|
|
820
|
+
};
|
|
821
|
+
|
|
822
|
+
const getTextSearchResultCounts = results => {
|
|
823
|
+
let resultCount = 0;
|
|
824
|
+
let fileCount = 0;
|
|
825
|
+
for (const result of results) {
|
|
826
|
+
switch (result.type) {
|
|
827
|
+
case File$1:
|
|
828
|
+
fileCount++;
|
|
829
|
+
break;
|
|
830
|
+
case Match:
|
|
831
|
+
resultCount++;
|
|
832
|
+
break;
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
return {
|
|
836
|
+
fileCount,
|
|
837
|
+
resultCount
|
|
838
|
+
};
|
|
839
|
+
};
|
|
840
|
+
|
|
841
|
+
const EmptyString = '';
|
|
842
|
+
|
|
843
|
+
const isEmptyString = string => {
|
|
844
|
+
return string === EmptyString;
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
*
|
|
849
|
+
* @param {number} size
|
|
850
|
+
* @param {number} contentSize
|
|
851
|
+
* @param {number} minimumSliderSize
|
|
852
|
+
* @returns
|
|
853
|
+
*/
|
|
854
|
+
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
855
|
+
if (size >= contentSize) {
|
|
856
|
+
return 0;
|
|
857
|
+
}
|
|
858
|
+
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
const RE_PROTOCOL = /^([a-z\-]+):\/\//;
|
|
862
|
+
const getProtocol = uri => {
|
|
863
|
+
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
864
|
+
if (protocolMatch) {
|
|
865
|
+
return protocolMatch[1];
|
|
866
|
+
}
|
|
867
|
+
return '';
|
|
868
|
+
};
|
|
869
|
+
|
|
592
870
|
const state$3 = {
|
|
593
871
|
/**
|
|
594
872
|
* @type {any}
|
|
@@ -965,82 +1243,6 @@ const listen$2 = ipc => {
|
|
|
965
1243
|
set$1(ipc);
|
|
966
1244
|
};
|
|
967
1245
|
|
|
968
|
-
const focusSearchValue = state => {
|
|
969
|
-
return {
|
|
970
|
-
...state,
|
|
971
|
-
focus: FocusSearchInput
|
|
972
|
-
};
|
|
973
|
-
};
|
|
974
|
-
const focusSearchValueNext = state => {
|
|
975
|
-
const {
|
|
976
|
-
replaceExpanded
|
|
977
|
-
} = state;
|
|
978
|
-
if (replaceExpanded) {
|
|
979
|
-
return focusReplaceValue(state);
|
|
980
|
-
}
|
|
981
|
-
return focusMatchCase(state);
|
|
982
|
-
};
|
|
983
|
-
const focusMatchCasePrevious = state => {
|
|
984
|
-
const {
|
|
985
|
-
replaceExpanded
|
|
986
|
-
} = state;
|
|
987
|
-
if (replaceExpanded) {
|
|
988
|
-
return focusReplaceValue(state);
|
|
989
|
-
}
|
|
990
|
-
return focusSearchValue(state);
|
|
991
|
-
};
|
|
992
|
-
const focusReplaceValueNext = state => {
|
|
993
|
-
return focusMatchCase(state);
|
|
994
|
-
};
|
|
995
|
-
const focusRegexNext = state => {
|
|
996
|
-
return focusPreserveCase(state);
|
|
997
|
-
};
|
|
998
|
-
const focusReplaceValue = state => {
|
|
999
|
-
return {
|
|
1000
|
-
...state,
|
|
1001
|
-
focus: FocusSearchReplaceInput
|
|
1002
|
-
};
|
|
1003
|
-
};
|
|
1004
|
-
const focusMatchCase = state => {
|
|
1005
|
-
return {
|
|
1006
|
-
...state,
|
|
1007
|
-
focus: FocusSearchMatchCase
|
|
1008
|
-
};
|
|
1009
|
-
};
|
|
1010
|
-
const focusPreserveCase = state => {
|
|
1011
|
-
return {
|
|
1012
|
-
...state,
|
|
1013
|
-
focus: FocusSearchPreserveCase
|
|
1014
|
-
};
|
|
1015
|
-
};
|
|
1016
|
-
const focusMatchWholeWord = state => {
|
|
1017
|
-
return {
|
|
1018
|
-
...state,
|
|
1019
|
-
focus: FocusSearchWholeWord
|
|
1020
|
-
};
|
|
1021
|
-
};
|
|
1022
|
-
const focusRegex = state => {
|
|
1023
|
-
return {
|
|
1024
|
-
...state,
|
|
1025
|
-
focus: FocusSearchRegex
|
|
1026
|
-
};
|
|
1027
|
-
};
|
|
1028
|
-
const focusReplaceAll = state => {
|
|
1029
|
-
return {
|
|
1030
|
-
...state,
|
|
1031
|
-
focus: FocusSearchReplaceAll
|
|
1032
|
-
};
|
|
1033
|
-
};
|
|
1034
|
-
|
|
1035
|
-
const RE_PROTOCOL = /^([a-z\-]+):\/\//;
|
|
1036
|
-
const getProtocol = uri => {
|
|
1037
|
-
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
1038
|
-
if (protocolMatch) {
|
|
1039
|
-
return protocolMatch[1];
|
|
1040
|
-
}
|
|
1041
|
-
return '';
|
|
1042
|
-
};
|
|
1043
|
-
|
|
1044
1246
|
const textSearch$5 = async (scheme, root, query) => {
|
|
1045
1247
|
string(scheme);
|
|
1046
1248
|
string(query);
|
|
@@ -1518,11 +1720,6 @@ const isNotReadableError = error => {
|
|
|
1518
1720
|
return error && error.name === NotReadableError;
|
|
1519
1721
|
};
|
|
1520
1722
|
|
|
1521
|
-
/**
|
|
1522
|
-
*
|
|
1523
|
-
* @param {FileSystemFileHandle} handle
|
|
1524
|
-
* @returns
|
|
1525
|
-
*/
|
|
1526
1723
|
const getFile = handle => {
|
|
1527
1724
|
return handle.getFile();
|
|
1528
1725
|
};
|
|
@@ -1595,7 +1792,6 @@ const textSearch$3 = async (scheme, root, query) => {
|
|
|
1595
1792
|
const relativeRoot = root.slice('html://'.length);
|
|
1596
1793
|
const handle = await getDirectoryHandle(relativeRoot);
|
|
1597
1794
|
if (!handle) {
|
|
1598
|
-
// @ts-ignore
|
|
1599
1795
|
throw new VError$1(`Folder not found ${relativeRoot}`);
|
|
1600
1796
|
}
|
|
1601
1797
|
const all = [];
|
|
@@ -1685,11 +1881,305 @@ const textSearch = async (root, query, options, assetDir) => {
|
|
|
1685
1881
|
return results;
|
|
1686
1882
|
};
|
|
1687
1883
|
|
|
1884
|
+
const getStatusMessage = (resultCount, fileResultCount) => {
|
|
1885
|
+
number$1(resultCount);
|
|
1886
|
+
number$1(fileResultCount);
|
|
1887
|
+
if (resultCount === 0) {
|
|
1888
|
+
return noResults();
|
|
1889
|
+
}
|
|
1890
|
+
if (resultCount === 1) {
|
|
1891
|
+
return oneResult();
|
|
1892
|
+
}
|
|
1893
|
+
if (fileResultCount === 1) {
|
|
1894
|
+
return manyResultsInOneFile(resultCount);
|
|
1895
|
+
}
|
|
1896
|
+
return manyResultsInManyFiles(resultCount, fileResultCount);
|
|
1897
|
+
};
|
|
1898
|
+
|
|
1899
|
+
const handleUpdate = async (state, update) => {
|
|
1900
|
+
const partialNewState = {
|
|
1901
|
+
...state,
|
|
1902
|
+
...update
|
|
1903
|
+
};
|
|
1904
|
+
try {
|
|
1905
|
+
const {
|
|
1906
|
+
height,
|
|
1907
|
+
itemHeight,
|
|
1908
|
+
minimumSliderSize,
|
|
1909
|
+
headerHeight,
|
|
1910
|
+
matchCase,
|
|
1911
|
+
value,
|
|
1912
|
+
threads,
|
|
1913
|
+
useRegularExpression
|
|
1914
|
+
} = partialNewState;
|
|
1915
|
+
if (isEmptyString(value)) {
|
|
1916
|
+
return {
|
|
1917
|
+
...partialNewState,
|
|
1918
|
+
minLineY: 0,
|
|
1919
|
+
maxLineY: 0,
|
|
1920
|
+
deltaY: 0,
|
|
1921
|
+
items: [],
|
|
1922
|
+
matchIndex: 0,
|
|
1923
|
+
matchCount: 0,
|
|
1924
|
+
message: '',
|
|
1925
|
+
loaded: true
|
|
1926
|
+
};
|
|
1927
|
+
}
|
|
1928
|
+
const root = state.workspacePath;
|
|
1929
|
+
const results = await textSearch(root, value, {
|
|
1930
|
+
threads,
|
|
1931
|
+
isCaseSensitive: matchCase,
|
|
1932
|
+
useRegularExpression
|
|
1933
|
+
}, state.assetDir);
|
|
1934
|
+
if (!Array.isArray(results)) {
|
|
1935
|
+
throw new TypeError('results must be of type array');
|
|
1936
|
+
}
|
|
1937
|
+
const {
|
|
1938
|
+
fileCount,
|
|
1939
|
+
resultCount
|
|
1940
|
+
} = getTextSearchResultCounts(results);
|
|
1941
|
+
const message = getStatusMessage(resultCount, fileCount);
|
|
1942
|
+
const total = results.length;
|
|
1943
|
+
const contentHeight = total * itemHeight;
|
|
1944
|
+
const listHeight = height - headerHeight;
|
|
1945
|
+
const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
|
|
1946
|
+
const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
1947
|
+
const maxLineY = Math.min(numberOfVisible, total);
|
|
1948
|
+
const finalDeltaY = Math.max(contentHeight - listHeight, 0);
|
|
1949
|
+
return {
|
|
1950
|
+
...partialNewState,
|
|
1951
|
+
minLineY: 0,
|
|
1952
|
+
deltaY: 0,
|
|
1953
|
+
value,
|
|
1954
|
+
items: results,
|
|
1955
|
+
message,
|
|
1956
|
+
maxLineY: maxLineY,
|
|
1957
|
+
scrollBarHeight,
|
|
1958
|
+
finalDeltaY,
|
|
1959
|
+
threads,
|
|
1960
|
+
fileCount,
|
|
1961
|
+
matchCount: resultCount,
|
|
1962
|
+
loaded: true
|
|
1963
|
+
};
|
|
1964
|
+
} catch (error) {
|
|
1965
|
+
handleError(error);
|
|
1966
|
+
return {
|
|
1967
|
+
...partialNewState,
|
|
1968
|
+
message: `${error}`,
|
|
1969
|
+
items: [],
|
|
1970
|
+
matchCount: 0,
|
|
1971
|
+
fileCount: 0,
|
|
1972
|
+
minLineY: 0,
|
|
1973
|
+
maxLineY: 0
|
|
1974
|
+
};
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1977
|
+
|
|
1978
|
+
const getSavedValue = savedState => {
|
|
1979
|
+
if (savedState && savedState.value) {
|
|
1980
|
+
return savedState.value;
|
|
1981
|
+
}
|
|
1982
|
+
return '';
|
|
1983
|
+
};
|
|
1984
|
+
const getSavedReplaceExpanded = savedState => {
|
|
1985
|
+
if (savedState && 'replaceExpanded' in savedState) {
|
|
1986
|
+
return savedState.replaceExpanded;
|
|
1987
|
+
}
|
|
1988
|
+
return false;
|
|
1989
|
+
};
|
|
1990
|
+
const getSavedCollapsedPaths = savedState => {
|
|
1991
|
+
if (savedState && 'collapsedPaths' in savedState && Array.isArray(savedState.collapsedPaths) && savedState.collapsedPaths.every(path => typeof path === 'string')) {
|
|
1992
|
+
return savedState.collapsedPaths;
|
|
1993
|
+
}
|
|
1994
|
+
return [];
|
|
1995
|
+
};
|
|
1996
|
+
const getThreads = () => {
|
|
1997
|
+
return 1;
|
|
1998
|
+
};
|
|
1999
|
+
const loadContent = async (uid, savedState) => {
|
|
2000
|
+
const state = get$2(uid);
|
|
2001
|
+
const savedValue = getSavedValue(savedState);
|
|
2002
|
+
const savedReplaceExpanded = getSavedReplaceExpanded(savedState);
|
|
2003
|
+
const savedCollapsedPaths = getSavedCollapsedPaths(savedState);
|
|
2004
|
+
const threads = getThreads();
|
|
2005
|
+
if (savedValue) {
|
|
2006
|
+
return handleUpdate(state, {
|
|
2007
|
+
value: savedValue,
|
|
2008
|
+
threads,
|
|
2009
|
+
replaceExpanded: savedReplaceExpanded,
|
|
2010
|
+
inputSource: Script,
|
|
2011
|
+
collapsedPaths: savedCollapsedPaths
|
|
2012
|
+
});
|
|
2013
|
+
}
|
|
2014
|
+
return {
|
|
2015
|
+
...state,
|
|
2016
|
+
threads,
|
|
2017
|
+
replaceExpanded: savedReplaceExpanded,
|
|
2018
|
+
loaded: true
|
|
2019
|
+
};
|
|
2020
|
+
};
|
|
2021
|
+
|
|
2022
|
+
const renderItems = {
|
|
2023
|
+
isEqual(oldState, newState) {
|
|
2024
|
+
return oldState.items === newState.items && oldState.minLineY === newState.minLineY && oldState.maxLineY === newState.maxLineY && oldState.replacement === newState.replacement && oldState.replaceExpanded === newState.replaceExpanded && oldState.matchCase === newState.matchCase && oldState.matchWholeWord === newState.matchWholeWord && oldState.useRegularExpression === newState.useRegularExpression && oldState.message === newState.message && oldState.detailsExpanded === newState.detailsExpanded && oldState.loaded === newState.loaded && oldState.collapsedPaths === newState.collapsedPaths && oldState.listFocusedIndex === newState.listFocusedIndex && oldState.listFocused === newState.listFocused;
|
|
2025
|
+
},
|
|
2026
|
+
apply(oldState, newState) {
|
|
2027
|
+
const displayResults = getDisplayResults(newState.items, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.collapsedPaths, newState.focusedIndex);
|
|
2028
|
+
const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
|
|
2029
|
+
const dom = getSearchVirtualDom(displayResults, newState.replaceExpanded, newState.matchCase, newState.matchWholeWord, newState.useRegularExpression, newState.message, newState.detailsExpanded, focusOutline);
|
|
2030
|
+
return ['Viewlet.setDom2', dom];
|
|
2031
|
+
}
|
|
2032
|
+
};
|
|
2033
|
+
const getSelector = focusKey => {
|
|
2034
|
+
switch (focusKey) {
|
|
2035
|
+
case FocusSearchInput:
|
|
2036
|
+
return '[name="search-value"]';
|
|
2037
|
+
case FocusSearchReplaceInput:
|
|
2038
|
+
return '[name="search-replace-value"]';
|
|
2039
|
+
case FocusSearchMatchCase:
|
|
2040
|
+
return '[title="Match Case"]';
|
|
2041
|
+
case FocusSearchPreserveCase:
|
|
2042
|
+
return '[title="Preserve Case"]';
|
|
2043
|
+
case FocusSearchRegex:
|
|
2044
|
+
return '[title="Use Regular Expression"]';
|
|
2045
|
+
default:
|
|
2046
|
+
return '';
|
|
2047
|
+
}
|
|
2048
|
+
};
|
|
2049
|
+
const renderFocus = {
|
|
2050
|
+
isEqual(oldState, newState) {
|
|
2051
|
+
return oldState.focus === newState.focus;
|
|
2052
|
+
},
|
|
2053
|
+
apply(oldState, newState) {
|
|
2054
|
+
const selector = getSelector(newState.focus);
|
|
2055
|
+
return ['setFocus', selector];
|
|
2056
|
+
}
|
|
2057
|
+
};
|
|
2058
|
+
const render = [renderItems, renderFocus];
|
|
2059
|
+
const doRender = (oldState, newState) => {
|
|
2060
|
+
const commands = [];
|
|
2061
|
+
for (const fn of render) {
|
|
2062
|
+
if (!fn.isEqual(oldState, newState)) {
|
|
2063
|
+
commands.push(fn.apply(oldState, newState));
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
return commands;
|
|
2067
|
+
};
|
|
2068
|
+
|
|
2069
|
+
const focusSearchValue = state => {
|
|
2070
|
+
return {
|
|
2071
|
+
...state,
|
|
2072
|
+
focus: FocusSearchInput
|
|
2073
|
+
};
|
|
2074
|
+
};
|
|
2075
|
+
const focusSearchValueNext = state => {
|
|
2076
|
+
const {
|
|
2077
|
+
replaceExpanded
|
|
2078
|
+
} = state;
|
|
2079
|
+
if (replaceExpanded) {
|
|
2080
|
+
return focusReplaceValue(state);
|
|
2081
|
+
}
|
|
2082
|
+
return focusMatchCase(state);
|
|
2083
|
+
};
|
|
2084
|
+
const focusMatchCasePrevious = state => {
|
|
2085
|
+
const {
|
|
2086
|
+
replaceExpanded
|
|
2087
|
+
} = state;
|
|
2088
|
+
if (replaceExpanded) {
|
|
2089
|
+
return focusReplaceValue(state);
|
|
2090
|
+
}
|
|
2091
|
+
return focusSearchValue(state);
|
|
2092
|
+
};
|
|
2093
|
+
const focusReplaceValueNext = state => {
|
|
2094
|
+
return focusMatchCase(state);
|
|
2095
|
+
};
|
|
2096
|
+
const focusRegexNext = state => {
|
|
2097
|
+
return focusPreserveCase(state);
|
|
2098
|
+
};
|
|
2099
|
+
const focusReplaceValue = state => {
|
|
2100
|
+
return {
|
|
2101
|
+
...state,
|
|
2102
|
+
focus: FocusSearchReplaceInput
|
|
2103
|
+
};
|
|
2104
|
+
};
|
|
2105
|
+
const focusMatchCase = state => {
|
|
2106
|
+
return {
|
|
2107
|
+
...state,
|
|
2108
|
+
focus: FocusSearchMatchCase
|
|
2109
|
+
};
|
|
2110
|
+
};
|
|
2111
|
+
const focusPreserveCase = state => {
|
|
2112
|
+
return {
|
|
2113
|
+
...state,
|
|
2114
|
+
focus: FocusSearchPreserveCase
|
|
2115
|
+
};
|
|
2116
|
+
};
|
|
2117
|
+
const focusMatchWholeWord = state => {
|
|
2118
|
+
return {
|
|
2119
|
+
...state,
|
|
2120
|
+
focus: FocusSearchWholeWord
|
|
2121
|
+
};
|
|
2122
|
+
};
|
|
2123
|
+
const focusRegex = state => {
|
|
2124
|
+
return {
|
|
2125
|
+
...state,
|
|
2126
|
+
focus: FocusSearchRegex
|
|
2127
|
+
};
|
|
2128
|
+
};
|
|
2129
|
+
const focusReplaceAll = state => {
|
|
2130
|
+
return {
|
|
2131
|
+
...state,
|
|
2132
|
+
focus: FocusSearchReplaceAll
|
|
2133
|
+
};
|
|
2134
|
+
};
|
|
2135
|
+
|
|
2136
|
+
const submit = state => {
|
|
2137
|
+
return handleUpdate(state, {
|
|
2138
|
+
value: state.value,
|
|
2139
|
+
inputSource: User
|
|
2140
|
+
});
|
|
2141
|
+
};
|
|
2142
|
+
|
|
2143
|
+
const Keyboard = -1;
|
|
2144
|
+
|
|
2145
|
+
const show = async (x, y, id, ...args) => {
|
|
2146
|
+
// TODO ask renderer worker to show context menu
|
|
2147
|
+
number$1(x);
|
|
2148
|
+
number$1(y);
|
|
2149
|
+
number$1(id);
|
|
2150
|
+
// TODO
|
|
2151
|
+
};
|
|
2152
|
+
|
|
2153
|
+
const Search = 18;
|
|
2154
|
+
|
|
2155
|
+
const handleContextMenuKeyboard = async state => {
|
|
2156
|
+
const x = state.x; // TODO
|
|
2157
|
+
const y = state.y; // TODO
|
|
2158
|
+
await show(x, y, Search);
|
|
2159
|
+
return state;
|
|
2160
|
+
};
|
|
2161
|
+
|
|
2162
|
+
const handleContextMenuMouseAt = async (state, x, y) => {
|
|
2163
|
+
await show(x, y, Search);
|
|
2164
|
+
return state;
|
|
2165
|
+
};
|
|
2166
|
+
|
|
2167
|
+
const handleContextMenu = (state, button, x, y) => {
|
|
2168
|
+
switch (button) {
|
|
2169
|
+
case Keyboard:
|
|
2170
|
+
return handleContextMenuKeyboard(state);
|
|
2171
|
+
default:
|
|
2172
|
+
return handleContextMenuMouseAt(state, x, y);
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
|
|
1688
2176
|
const commandMap = {
|
|
1689
2177
|
'SearchView.focusMatchCase': focusMatchCase$1,
|
|
1690
2178
|
'SearchView.focusReplaceValue': focusReplaceValue$1,
|
|
1691
2179
|
'SearchView.focusSearchValue': focusSearchValue$1,
|
|
1692
2180
|
'SearchView.focusSearchValueNext': focusSearchValueNext$1,
|
|
2181
|
+
'TextSearch.create': create$4,
|
|
2182
|
+
'TextSearch.doRender': doRender,
|
|
1693
2183
|
'TextSearch.focusMatchCase': focusMatchCase,
|
|
1694
2184
|
'TextSearch.focusMatchCasePrevious': focusMatchCasePrevious,
|
|
1695
2185
|
'TextSearch.focusMatchWholeWord': focusMatchWholeWord,
|
|
@@ -1703,7 +2193,12 @@ const commandMap = {
|
|
|
1703
2193
|
'TextSearch.focusSearchValueNext': focusSearchValueNext,
|
|
1704
2194
|
'TextSearch.getActions': getActions,
|
|
1705
2195
|
'TextSearch.getActionsVirtualDom': getActionsVirtualDom,
|
|
2196
|
+
'TextSearch.getSearchDisplayResults': getDisplayResults,
|
|
1706
2197
|
'TextSearch.getVirtualDom': getSearchVirtualDom,
|
|
2198
|
+
'TextSearch.handleContextMenu': handleContextMenu,
|
|
2199
|
+
'TextSearch.handleIconThemeChange': handleIconThemeChange,
|
|
2200
|
+
'TextSearch.loadContent': loadContent,
|
|
2201
|
+
'TextSearch.submit': submit,
|
|
1707
2202
|
'TextSearch.textSearch': textSearch
|
|
1708
2203
|
};
|
|
1709
2204
|
|