@lvce-editor/text-search-worker 1.3.0 → 2.0.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 +556 -89
- package/package.json +5 -3
|
@@ -18,48 +18,401 @@ const execute = (command, ...args) => {
|
|
|
18
18
|
return fn(...args);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
const FocusSearchInput = 21;
|
|
22
|
+
const FocusSearchReplaceInput = 31;
|
|
23
|
+
const FocusSearchMatchCase = 32;
|
|
24
|
+
const FocusSearchRegex = 33;
|
|
25
|
+
const FocusSearchWholeWord = 34;
|
|
26
|
+
const FocusSearchReplaceAll = 35;
|
|
27
|
+
const FocusSearchPreserveCase = 36;
|
|
28
|
+
|
|
29
|
+
const focusMatchCase$1 = state => {
|
|
30
|
+
return {
|
|
31
|
+
...state,
|
|
32
|
+
focus: FocusSearchMatchCase
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const focusReplaceValue$1 = state => {
|
|
37
|
+
return {
|
|
38
|
+
...state,
|
|
39
|
+
focus: FocusSearchReplaceInput
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const focusSearchValue$1 = state => {
|
|
44
|
+
return {
|
|
45
|
+
...state,
|
|
46
|
+
focus: FocusSearchInput
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const focusSearchValueNext$1 = state => {
|
|
51
|
+
const {
|
|
52
|
+
replaceExpanded
|
|
53
|
+
} = state;
|
|
54
|
+
if (replaceExpanded) {
|
|
55
|
+
return focusReplaceValue$1(state);
|
|
25
56
|
}
|
|
57
|
+
return focusMatchCase$1(state);
|
|
26
58
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
|
|
60
|
+
const CheckBox = 'checkbox';
|
|
61
|
+
const None = 'none';
|
|
62
|
+
const Status = 'status';
|
|
63
|
+
const Tree = 'tree';
|
|
64
|
+
const TreeItem$1 = 'treeitem';
|
|
65
|
+
|
|
66
|
+
const Chevron = 'Chevron';
|
|
67
|
+
const CloseMaskIcon = 'MaskIcon MaskIconClose';
|
|
68
|
+
const Empty = '';
|
|
69
|
+
const FileIcon = 'FileIcon';
|
|
70
|
+
const FocusOutline = 'FocusOutline';
|
|
71
|
+
const Highlight = 'Highlight';
|
|
72
|
+
const HighlightDeleted = 'HighlightDeleted';
|
|
73
|
+
const HighlightInserted = 'HighlightInserted';
|
|
74
|
+
const Label = 'Label';
|
|
75
|
+
const List = 'List';
|
|
76
|
+
const MaskIcon = 'MaskIcon';
|
|
77
|
+
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
78
|
+
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
79
|
+
const MultilineInputBox = 'MultilineInputBox';
|
|
80
|
+
const Search = 'Search';
|
|
81
|
+
const SearchField = 'SearchField';
|
|
82
|
+
const SearchFieldButtons = 'SearchFieldButtons';
|
|
83
|
+
const SearchFieldContainer = 'SearchFieldContainer';
|
|
84
|
+
const SearchHeader = 'SearchHeader';
|
|
85
|
+
const SearchHeaderTop = 'SearchHeaderTop';
|
|
86
|
+
const SearchRemove = 'SearchRemove';
|
|
87
|
+
const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
|
|
88
|
+
const SourceControlBadge = 'SourceControlBadge';
|
|
89
|
+
const TreeItem = 'TreeItem';
|
|
90
|
+
const TreeItemActive = 'TreeItemActive';
|
|
91
|
+
const Viewlet = 'Viewlet';
|
|
92
|
+
const ViewletSearchMessage = 'ViewletSearchMessage';
|
|
93
|
+
|
|
94
|
+
const HandleClick = 'handleClick';
|
|
95
|
+
const HandleHeaderClick = 'handleHeaderClick';
|
|
96
|
+
const HandleHeaderFocusIn = 'handleHeaderFocusIn';
|
|
97
|
+
const HandleListBlur = 'handleListBlur';
|
|
98
|
+
|
|
99
|
+
const Button = 1;
|
|
100
|
+
const Div = 4;
|
|
101
|
+
const Input = 6;
|
|
102
|
+
const Span = 8;
|
|
103
|
+
const Text = 12;
|
|
104
|
+
const Img = 17;
|
|
105
|
+
const Ins = 20;
|
|
106
|
+
const Del = 21;
|
|
107
|
+
const TextArea = 62;
|
|
108
|
+
|
|
109
|
+
const getSearchFieldButtonVirtualDom = button => {
|
|
110
|
+
const {
|
|
111
|
+
icon,
|
|
112
|
+
checked,
|
|
113
|
+
title
|
|
114
|
+
} = button;
|
|
115
|
+
return [{
|
|
116
|
+
type: Div,
|
|
117
|
+
className: `SearchFieldButton ${checked ? 'SearchFieldButtonChecked' : ''}`,
|
|
118
|
+
title,
|
|
119
|
+
role: CheckBox,
|
|
120
|
+
ariaChecked: checked,
|
|
121
|
+
tabIndex: 0,
|
|
122
|
+
childCount: 1
|
|
123
|
+
}, {
|
|
124
|
+
type: Div,
|
|
125
|
+
className: `MaskIcon ${icon}`,
|
|
126
|
+
childCount: 0
|
|
127
|
+
}];
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '') => {
|
|
131
|
+
const dom = [{
|
|
132
|
+
type: Div,
|
|
133
|
+
className: SearchField,
|
|
134
|
+
role: None,
|
|
135
|
+
childCount: 2
|
|
136
|
+
}, {
|
|
137
|
+
type: TextArea,
|
|
138
|
+
className: MultilineInputBox,
|
|
139
|
+
spellcheck: false,
|
|
140
|
+
autocapitalize: 'off',
|
|
141
|
+
autocorrect: 'off',
|
|
142
|
+
placeholder,
|
|
143
|
+
name,
|
|
144
|
+
onInput,
|
|
145
|
+
onFocus,
|
|
146
|
+
childCount: 0
|
|
147
|
+
}, {
|
|
148
|
+
type: Div,
|
|
149
|
+
className: SearchFieldButtons,
|
|
150
|
+
childCount: insideButtons.length
|
|
151
|
+
}, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom)];
|
|
152
|
+
if (outsideButtons.length > 0) {
|
|
153
|
+
dom.unshift({
|
|
154
|
+
type: Div,
|
|
155
|
+
className: SearchFieldContainer,
|
|
156
|
+
role: None,
|
|
157
|
+
childCount: 1 + outsideButtons.length
|
|
158
|
+
});
|
|
159
|
+
dom.push(...outsideButtons.flatMap(getSearchFieldButtonVirtualDom));
|
|
47
160
|
}
|
|
161
|
+
return dom;
|
|
48
162
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
163
|
+
|
|
164
|
+
const text = data => {
|
|
165
|
+
return {
|
|
166
|
+
type: Text,
|
|
167
|
+
text: data,
|
|
168
|
+
childCount: 0
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const getSearchHeaderVirtualDom = (replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded) => {
|
|
173
|
+
const dom = [{
|
|
174
|
+
type: Div,
|
|
175
|
+
className: SearchHeader,
|
|
176
|
+
role: None,
|
|
177
|
+
childCount: 2,
|
|
178
|
+
onClick: HandleHeaderClick,
|
|
179
|
+
onFocusIn: HandleHeaderFocusIn
|
|
180
|
+
}, {
|
|
181
|
+
type: Div,
|
|
182
|
+
className: SearchHeaderTop,
|
|
183
|
+
role: None,
|
|
184
|
+
childCount: 2
|
|
185
|
+
}, {
|
|
186
|
+
type: Button,
|
|
187
|
+
className: `IconButton SearchToggleButton ${replaceExpanded ? SearchToggleButtonExpanded : ''}`,
|
|
188
|
+
title: 'Toggle Replace',
|
|
189
|
+
ariaLabel: 'Toggle Replace',
|
|
190
|
+
ariaExpanded: replaceExpanded,
|
|
191
|
+
childCount: 1,
|
|
192
|
+
'data-command': 'toggleReplace'
|
|
193
|
+
}, {
|
|
194
|
+
type: Div,
|
|
195
|
+
className: `${MaskIcon} ${replaceExpanded ? MaskIconChevronDown : MaskIconChevronRight}`,
|
|
196
|
+
childCount: 0
|
|
197
|
+
}, {
|
|
198
|
+
type: Div,
|
|
199
|
+
className: 'SearchHeaderTopRight',
|
|
200
|
+
role: None,
|
|
201
|
+
childCount: replaceExpanded ? 2 : 1
|
|
202
|
+
}, ...getSearchFieldVirtualDom('search-value', 'Search', 'handleInput', [{
|
|
203
|
+
icon: 'MaskIconCaseSensitive',
|
|
204
|
+
checked: matchCase,
|
|
205
|
+
title: 'Match Case'
|
|
206
|
+
}, {
|
|
207
|
+
icon: 'MaskIconWholeWord',
|
|
208
|
+
checked: matchWholeWord,
|
|
209
|
+
title: 'Match Whole Word'
|
|
210
|
+
}, {
|
|
211
|
+
icon: 'MaskIconRegex',
|
|
212
|
+
checked: useRegularExpression,
|
|
213
|
+
title: 'Use Regular Expression'
|
|
214
|
+
}], [])];
|
|
215
|
+
if (replaceExpanded) {
|
|
216
|
+
dom.push(...getSearchFieldVirtualDom('search-replace-value', 'Replace', 'handleReplaceInput', [{
|
|
217
|
+
icon: 'MaskIconPreserveCase',
|
|
218
|
+
checked: false,
|
|
219
|
+
title: 'Preserve Case'
|
|
220
|
+
}], [{
|
|
221
|
+
icon: 'MaskIconReplaceAll',
|
|
222
|
+
checked: false,
|
|
223
|
+
title: 'Replace All'
|
|
224
|
+
}]));
|
|
225
|
+
}
|
|
226
|
+
if (detailsExpanded) {
|
|
227
|
+
console.log({
|
|
228
|
+
detailsExpanded
|
|
229
|
+
});
|
|
230
|
+
dom[0].childCount++;
|
|
231
|
+
dom.push({
|
|
232
|
+
type: Div,
|
|
233
|
+
className: 'SearchHeaderDetails',
|
|
234
|
+
childCount: 4
|
|
235
|
+
}, text('files to include'), {
|
|
236
|
+
type: Input,
|
|
237
|
+
childCount: 0
|
|
238
|
+
}, text('files to exclude'), {
|
|
239
|
+
type: Input,
|
|
240
|
+
childCount: 0
|
|
241
|
+
});
|
|
53
242
|
}
|
|
243
|
+
return dom;
|
|
54
244
|
};
|
|
55
245
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
246
|
+
const getBadgeVirtualDom = (className, count) => {
|
|
247
|
+
return [{
|
|
248
|
+
type: Div,
|
|
249
|
+
className: `Badge ${className}`,
|
|
250
|
+
childCount: 1
|
|
251
|
+
}, text(`${count}`)];
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
const getChevronDownVirtualDom = (extraClassName = '') => {
|
|
255
|
+
return {
|
|
256
|
+
type: Div,
|
|
257
|
+
className: `${Chevron} MaskIconChevronDown ${extraClassName}`,
|
|
258
|
+
childCount: 0
|
|
259
|
+
};
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const getFileIconVirtualDom = icon => {
|
|
263
|
+
return {
|
|
264
|
+
type: Img,
|
|
265
|
+
className: FileIcon,
|
|
266
|
+
src: icon,
|
|
267
|
+
role: None,
|
|
268
|
+
childCount: 0
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
const File$1 = 1;
|
|
273
|
+
const Match = 2;
|
|
274
|
+
|
|
275
|
+
const PaddingRight = '12px';
|
|
276
|
+
|
|
277
|
+
const deleted = {
|
|
278
|
+
type: Del,
|
|
279
|
+
className: HighlightDeleted,
|
|
280
|
+
childCount: 1
|
|
281
|
+
};
|
|
282
|
+
const inserted = {
|
|
283
|
+
type: Ins,
|
|
284
|
+
className: HighlightInserted,
|
|
285
|
+
childCount: 1
|
|
286
|
+
};
|
|
287
|
+
const highlighted = {
|
|
288
|
+
type: Span,
|
|
289
|
+
className: Highlight,
|
|
290
|
+
childCount: 1
|
|
291
|
+
};
|
|
292
|
+
const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) => {
|
|
293
|
+
const dom = [];
|
|
294
|
+
const label = {
|
|
295
|
+
type: Div,
|
|
296
|
+
className: Label + ' Grow',
|
|
297
|
+
childCount: 1
|
|
298
|
+
};
|
|
299
|
+
dom.push(label);
|
|
300
|
+
if (matchLength) {
|
|
301
|
+
const before = displayText.slice(0, matchStart);
|
|
302
|
+
const highlight = displayText.slice(matchStart, matchStart + matchLength);
|
|
303
|
+
const after = displayText.slice(matchStart + matchLength);
|
|
304
|
+
if (replacement) {
|
|
305
|
+
dom.push(text(before), deleted, text(highlight), inserted, text(replacement), text(after));
|
|
306
|
+
label.childCount = 4;
|
|
307
|
+
} else {
|
|
308
|
+
label.childCount = 3;
|
|
309
|
+
dom.push(text(before), highlighted, text(highlight), text(after));
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
dom.push(text(displayText));
|
|
61
313
|
}
|
|
62
|
-
return
|
|
314
|
+
return dom;
|
|
315
|
+
};
|
|
316
|
+
const renderRow = rowInfo => {
|
|
317
|
+
// @ts-ignore
|
|
318
|
+
const {
|
|
319
|
+
top,
|
|
320
|
+
type,
|
|
321
|
+
matchStart,
|
|
322
|
+
matchLength,
|
|
323
|
+
text: displayText,
|
|
324
|
+
title,
|
|
325
|
+
icon,
|
|
326
|
+
setSize,
|
|
327
|
+
posInSet,
|
|
328
|
+
depth,
|
|
329
|
+
replacement,
|
|
330
|
+
matchCount,
|
|
331
|
+
focused
|
|
332
|
+
} = rowInfo;
|
|
333
|
+
const treeItem = {
|
|
334
|
+
type: Div,
|
|
335
|
+
role: TreeItem$1,
|
|
336
|
+
className: TreeItem,
|
|
337
|
+
title,
|
|
338
|
+
ariaSetSize: setSize,
|
|
339
|
+
ariaLevel: depth,
|
|
340
|
+
ariaPosInSet: posInSet,
|
|
341
|
+
ariaLabel: title,
|
|
342
|
+
ariaDescription: '',
|
|
343
|
+
childCount: 1,
|
|
344
|
+
paddingLeft: `${Number(depth) + 1}rem`,
|
|
345
|
+
// TODO use classname and dynamic css
|
|
346
|
+
paddingRight: PaddingRight
|
|
347
|
+
};
|
|
348
|
+
if (focused) {
|
|
349
|
+
treeItem.className += ' ' + TreeItemActive;
|
|
350
|
+
}
|
|
351
|
+
switch (type) {
|
|
352
|
+
case File$1:
|
|
353
|
+
treeItem.ariaExpanded = 'true';
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
const dom = [];
|
|
357
|
+
dom.push(treeItem);
|
|
358
|
+
if (type === File$1) {
|
|
359
|
+
treeItem.childCount += 2;
|
|
360
|
+
dom.push(getChevronDownVirtualDom(), getFileIconVirtualDom(icon));
|
|
361
|
+
}
|
|
362
|
+
dom.push(...getLabelVirtualDom(displayText, matchLength, matchStart, replacement));
|
|
363
|
+
if (matchCount) {
|
|
364
|
+
treeItem.childCount++;
|
|
365
|
+
dom.push(...getBadgeVirtualDom(SourceControlBadge, matchCount));
|
|
366
|
+
}
|
|
367
|
+
treeItem.childCount++;
|
|
368
|
+
dom.push({
|
|
369
|
+
type: Div,
|
|
370
|
+
className: SearchRemove,
|
|
371
|
+
childCount: 1
|
|
372
|
+
}, {
|
|
373
|
+
type: Div,
|
|
374
|
+
className: CloseMaskIcon,
|
|
375
|
+
childCount: 0
|
|
376
|
+
});
|
|
377
|
+
return dom;
|
|
378
|
+
};
|
|
379
|
+
const getSearchResultsVirtualDom = visibleItems => {
|
|
380
|
+
return visibleItems.flatMap(renderRow);
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
const mergeClassNames = (...classNames) => {
|
|
384
|
+
return classNames.filter(Boolean).join(' ');
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWholeWord, useRegularExpression, message, detailsExpanded, focusOutline) => {
|
|
388
|
+
/**
|
|
389
|
+
* @type {any[]}
|
|
390
|
+
*/
|
|
391
|
+
const dom = [];
|
|
392
|
+
dom.push({
|
|
393
|
+
type: Div,
|
|
394
|
+
className: mergeClassNames(Viewlet, Search),
|
|
395
|
+
childCount: 2
|
|
396
|
+
});
|
|
397
|
+
dom.push(...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded));
|
|
398
|
+
dom.push({
|
|
399
|
+
type: Div,
|
|
400
|
+
className: ViewletSearchMessage,
|
|
401
|
+
role: Status,
|
|
402
|
+
tabIndex: 0,
|
|
403
|
+
childCount: 1
|
|
404
|
+
}, text(message));
|
|
405
|
+
dom.push({
|
|
406
|
+
type: Div,
|
|
407
|
+
className: mergeClassNames(Viewlet, List, focusOutline ? FocusOutline : Empty),
|
|
408
|
+
role: Tree,
|
|
409
|
+
tabIndex: 0,
|
|
410
|
+
childCount: visibleItems.length,
|
|
411
|
+
onClick: HandleClick,
|
|
412
|
+
onBlur: HandleListBlur
|
|
413
|
+
});
|
|
414
|
+
dom.push(...getSearchResultsVirtualDom(visibleItems));
|
|
415
|
+
return dom;
|
|
63
416
|
};
|
|
64
417
|
|
|
65
418
|
const state$3 = {
|
|
@@ -76,12 +429,12 @@ const set$1 = ipc => {
|
|
|
76
429
|
};
|
|
77
430
|
|
|
78
431
|
const Two = '2.0';
|
|
79
|
-
class AssertionError extends Error {
|
|
432
|
+
let AssertionError$1 = class AssertionError extends Error {
|
|
80
433
|
constructor(message) {
|
|
81
434
|
super(message);
|
|
82
435
|
this.name = 'AssertionError';
|
|
83
436
|
}
|
|
84
|
-
}
|
|
437
|
+
};
|
|
85
438
|
const getType$1 = value => {
|
|
86
439
|
switch (typeof value) {
|
|
87
440
|
case 'number':
|
|
@@ -107,7 +460,7 @@ const getType$1 = value => {
|
|
|
107
460
|
const number = value => {
|
|
108
461
|
const type = getType$1(value);
|
|
109
462
|
if (type !== 'number') {
|
|
110
|
-
throw new AssertionError('expected value to be of type number');
|
|
463
|
+
throw new AssertionError$1('expected value to be of type number');
|
|
111
464
|
}
|
|
112
465
|
};
|
|
113
466
|
const state$1 = {
|
|
@@ -131,25 +484,12 @@ const create$3 = () => {
|
|
|
131
484
|
const warn = (...args) => {
|
|
132
485
|
console.warn(...args);
|
|
133
486
|
};
|
|
134
|
-
const withResolvers$1 = () => {
|
|
135
|
-
/**
|
|
136
|
-
* @type {any}
|
|
137
|
-
*/
|
|
138
|
-
let _resolve;
|
|
139
|
-
const promise = new Promise(resolve => {
|
|
140
|
-
_resolve = resolve;
|
|
141
|
-
});
|
|
142
|
-
return {
|
|
143
|
-
resolve: _resolve,
|
|
144
|
-
promise
|
|
145
|
-
};
|
|
146
|
-
};
|
|
147
487
|
const registerPromise = () => {
|
|
148
488
|
const id = create$3();
|
|
149
489
|
const {
|
|
150
490
|
resolve,
|
|
151
491
|
promise
|
|
152
|
-
} = withResolvers
|
|
492
|
+
} = Promise.withResolvers();
|
|
153
493
|
set(id, resolve);
|
|
154
494
|
return {
|
|
155
495
|
id,
|
|
@@ -315,7 +655,7 @@ const unwrapJsonRpcResult = responseMessage => {
|
|
|
315
655
|
throw new JsonRpcError('unexpected response message');
|
|
316
656
|
};
|
|
317
657
|
const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
|
|
318
|
-
const
|
|
658
|
+
const getErrorType = prettyError => {
|
|
319
659
|
if (prettyError && prettyError.type) {
|
|
320
660
|
return prettyError.type;
|
|
321
661
|
}
|
|
@@ -338,7 +678,7 @@ const getErrorProperty = (error, prettyError) => {
|
|
|
338
678
|
data: {
|
|
339
679
|
stack: prettyError.stack,
|
|
340
680
|
codeFrame: prettyError.codeFrame,
|
|
341
|
-
type:
|
|
681
|
+
type: getErrorType(prettyError),
|
|
342
682
|
code: prettyError.code,
|
|
343
683
|
name: prettyError.name
|
|
344
684
|
}
|
|
@@ -451,6 +791,117 @@ const listen$2 = ipc => {
|
|
|
451
791
|
set$1(ipc);
|
|
452
792
|
};
|
|
453
793
|
|
|
794
|
+
const focusSearchValue = state => {
|
|
795
|
+
return {
|
|
796
|
+
...state,
|
|
797
|
+
focus: FocusSearchInput
|
|
798
|
+
};
|
|
799
|
+
};
|
|
800
|
+
const focusSearchValueNext = state => {
|
|
801
|
+
const {
|
|
802
|
+
replaceExpanded
|
|
803
|
+
} = state;
|
|
804
|
+
if (replaceExpanded) {
|
|
805
|
+
return focusReplaceValue(state);
|
|
806
|
+
}
|
|
807
|
+
return focusMatchCase(state);
|
|
808
|
+
};
|
|
809
|
+
const focusMatchCasePrevious = state => {
|
|
810
|
+
const {
|
|
811
|
+
replaceExpanded
|
|
812
|
+
} = state;
|
|
813
|
+
if (replaceExpanded) {
|
|
814
|
+
return focusReplaceValue(state);
|
|
815
|
+
}
|
|
816
|
+
return focusSearchValue(state);
|
|
817
|
+
};
|
|
818
|
+
const focusReplaceValueNext = state => {
|
|
819
|
+
return focusMatchCase(state);
|
|
820
|
+
};
|
|
821
|
+
const focusRegexNext = state => {
|
|
822
|
+
return focusPreserveCase(state);
|
|
823
|
+
};
|
|
824
|
+
const focusReplaceValue = state => {
|
|
825
|
+
return {
|
|
826
|
+
...state,
|
|
827
|
+
focus: FocusSearchReplaceInput
|
|
828
|
+
};
|
|
829
|
+
};
|
|
830
|
+
const focusMatchCase = state => {
|
|
831
|
+
return {
|
|
832
|
+
...state,
|
|
833
|
+
focus: FocusSearchMatchCase
|
|
834
|
+
};
|
|
835
|
+
};
|
|
836
|
+
const focusPreserveCase = state => {
|
|
837
|
+
return {
|
|
838
|
+
...state,
|
|
839
|
+
focus: FocusSearchPreserveCase
|
|
840
|
+
};
|
|
841
|
+
};
|
|
842
|
+
const focusMatchWholeWord = state => {
|
|
843
|
+
return {
|
|
844
|
+
...state,
|
|
845
|
+
focus: FocusSearchWholeWord
|
|
846
|
+
};
|
|
847
|
+
};
|
|
848
|
+
const focusRegex = state => {
|
|
849
|
+
return {
|
|
850
|
+
...state,
|
|
851
|
+
focus: FocusSearchRegex
|
|
852
|
+
};
|
|
853
|
+
};
|
|
854
|
+
const focusReplaceAll = state => {
|
|
855
|
+
return {
|
|
856
|
+
...state,
|
|
857
|
+
focus: FocusSearchReplaceAll
|
|
858
|
+
};
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
class AssertionError extends Error {
|
|
862
|
+
constructor(message) {
|
|
863
|
+
super(message);
|
|
864
|
+
this.name = 'AssertionError';
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
const getType = value => {
|
|
868
|
+
switch (typeof value) {
|
|
869
|
+
case 'number':
|
|
870
|
+
return 'number';
|
|
871
|
+
case 'function':
|
|
872
|
+
return 'function';
|
|
873
|
+
case 'string':
|
|
874
|
+
return 'string';
|
|
875
|
+
case 'object':
|
|
876
|
+
if (value === null) {
|
|
877
|
+
return 'null';
|
|
878
|
+
}
|
|
879
|
+
if (Array.isArray(value)) {
|
|
880
|
+
return 'array';
|
|
881
|
+
}
|
|
882
|
+
return 'object';
|
|
883
|
+
case 'boolean':
|
|
884
|
+
return 'boolean';
|
|
885
|
+
default:
|
|
886
|
+
return 'unknown';
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
const string = value => {
|
|
890
|
+
const type = getType(value);
|
|
891
|
+
if (type !== 'string') {
|
|
892
|
+
throw new AssertionError('expected value to be of type string');
|
|
893
|
+
}
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
const RE_PROTOCOL = /^([a-z\-]+):\/\//;
|
|
897
|
+
const getProtocol = uri => {
|
|
898
|
+
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
899
|
+
if (protocolMatch) {
|
|
900
|
+
return protocolMatch[1];
|
|
901
|
+
}
|
|
902
|
+
return '';
|
|
903
|
+
};
|
|
904
|
+
|
|
454
905
|
const textSearch$5 = async (scheme, root, query) => {
|
|
455
906
|
string(scheme);
|
|
456
907
|
string(query);
|
|
@@ -544,9 +995,6 @@ const splitLines$1 = lines => {
|
|
|
544
995
|
return lines.split('\n');
|
|
545
996
|
};
|
|
546
997
|
|
|
547
|
-
const File$1 = 1;
|
|
548
|
-
const Match = 2;
|
|
549
|
-
|
|
550
998
|
const textSearchInFile$1 = (file, content, query) => {
|
|
551
999
|
const results = [];
|
|
552
1000
|
const lines = splitLines$1(content);
|
|
@@ -592,42 +1040,9 @@ const textSearch$4 = async (scheme, root, query, options, assetDir) => {
|
|
|
592
1040
|
return allResults;
|
|
593
1041
|
};
|
|
594
1042
|
|
|
595
|
-
// based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
|
|
596
|
-
|
|
597
|
-
const insertInto = (array, start, newItems) => {
|
|
598
|
-
const originalLength = array.length;
|
|
599
|
-
const newItemsLength = newItems.length;
|
|
600
|
-
array.length = originalLength + newItemsLength;
|
|
601
|
-
// Move the items after the start index, start from the end so that we don't overwrite any value.
|
|
602
|
-
for (let i = originalLength - 1; i >= start; i--) {
|
|
603
|
-
array[i + newItemsLength] = array[i];
|
|
604
|
-
}
|
|
605
|
-
for (let i = 0; i < newItemsLength; i++) {
|
|
606
|
-
array[i + start] = newItems[i];
|
|
607
|
-
}
|
|
608
|
-
};
|
|
609
|
-
const push = (array, newItems) => {
|
|
610
|
-
insertInto(array, array.length, newItems);
|
|
611
|
-
};
|
|
612
|
-
|
|
613
|
-
const NotReadableError = 'NotReadableError';
|
|
614
|
-
|
|
615
|
-
const isNotReadableError = error => {
|
|
616
|
-
return error && error.name === NotReadableError;
|
|
617
|
-
};
|
|
618
|
-
|
|
619
1043
|
const Directory = 'directory';
|
|
620
1044
|
const File = 'file';
|
|
621
1045
|
|
|
622
|
-
/**
|
|
623
|
-
*
|
|
624
|
-
* @param {FileSystemFileHandle} handle
|
|
625
|
-
* @returns
|
|
626
|
-
*/
|
|
627
|
-
const getFile = handle => {
|
|
628
|
-
return handle.getFile();
|
|
629
|
-
};
|
|
630
|
-
|
|
631
1046
|
const dirname = (pathSeparator, path) => {
|
|
632
1047
|
const index = path.lastIndexOf(pathSeparator);
|
|
633
1048
|
if (index === -1) {
|
|
@@ -939,6 +1354,40 @@ const getDirectoryHandle = async uri => {
|
|
|
939
1354
|
}
|
|
940
1355
|
return getDirectoryHandle(dirname$1);
|
|
941
1356
|
};
|
|
1357
|
+
|
|
1358
|
+
// based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
|
|
1359
|
+
|
|
1360
|
+
const insertInto = (array, start, newItems) => {
|
|
1361
|
+
const originalLength = array.length;
|
|
1362
|
+
const newItemsLength = newItems.length;
|
|
1363
|
+
array.length = originalLength + newItemsLength;
|
|
1364
|
+
// Move the items after the start index, start from the end so that we don't overwrite any value.
|
|
1365
|
+
for (let i = originalLength - 1; i >= start; i--) {
|
|
1366
|
+
array[i + newItemsLength] = array[i];
|
|
1367
|
+
}
|
|
1368
|
+
for (let i = 0; i < newItemsLength; i++) {
|
|
1369
|
+
array[i + start] = newItems[i];
|
|
1370
|
+
}
|
|
1371
|
+
};
|
|
1372
|
+
const push = (array, newItems) => {
|
|
1373
|
+
insertInto(array, array.length, newItems);
|
|
1374
|
+
};
|
|
1375
|
+
|
|
1376
|
+
const NotReadableError = 'NotReadableError';
|
|
1377
|
+
|
|
1378
|
+
const isNotReadableError = error => {
|
|
1379
|
+
return error && error.name === NotReadableError;
|
|
1380
|
+
};
|
|
1381
|
+
|
|
1382
|
+
/**
|
|
1383
|
+
*
|
|
1384
|
+
* @param {FileSystemFileHandle} handle
|
|
1385
|
+
* @returns
|
|
1386
|
+
*/
|
|
1387
|
+
const getFile = handle => {
|
|
1388
|
+
return handle.getFile();
|
|
1389
|
+
};
|
|
1390
|
+
|
|
942
1391
|
const textSearchInText = (file, content, query) => {
|
|
943
1392
|
const results = [];
|
|
944
1393
|
const lines = splitLines$1(content);
|
|
@@ -966,6 +1415,7 @@ const textSearchInText = (file, content, query) => {
|
|
|
966
1415
|
}
|
|
967
1416
|
return results;
|
|
968
1417
|
};
|
|
1418
|
+
|
|
969
1419
|
const textSearchInFile = async (all, handle, absolutePath, query) => {
|
|
970
1420
|
try {
|
|
971
1421
|
const file = await getFile(handle);
|
|
@@ -980,6 +1430,7 @@ const textSearchInFile = async (all, handle, absolutePath, query) => {
|
|
|
980
1430
|
throw error;
|
|
981
1431
|
}
|
|
982
1432
|
};
|
|
1433
|
+
|
|
983
1434
|
const textSearchRecursively = async (all, parent, handle, query) => {
|
|
984
1435
|
const childHandles = [];
|
|
985
1436
|
// TODO
|
|
@@ -1096,6 +1547,22 @@ const textSearch = async (root, query, options, assetDir) => {
|
|
|
1096
1547
|
};
|
|
1097
1548
|
|
|
1098
1549
|
const commandMap = {
|
|
1550
|
+
'SearchView.focusMatchCase': focusMatchCase$1,
|
|
1551
|
+
'SearchView.focusReplaceValue': focusReplaceValue$1,
|
|
1552
|
+
'SearchView.focusSearchValue': focusSearchValue$1,
|
|
1553
|
+
'SearchView.focusSearchValueNext': focusSearchValueNext$1,
|
|
1554
|
+
'TextSearch.focusMatchCase': focusMatchCase,
|
|
1555
|
+
'TextSearch.focusMatchCasePrevious': focusMatchCasePrevious,
|
|
1556
|
+
'TextSearch.focusMatchWholeWord': focusMatchWholeWord,
|
|
1557
|
+
'TextSearch.focusPreserveCase': focusPreserveCase,
|
|
1558
|
+
'TextSearch.focusRegex': focusRegex,
|
|
1559
|
+
'TextSearch.focusRegexNext': focusRegexNext,
|
|
1560
|
+
'TextSearch.focusReplaceAll': focusReplaceAll,
|
|
1561
|
+
'TextSearch.focusReplaceValue': focusReplaceValue,
|
|
1562
|
+
'TextSearch.focusReplaceValueNext': focusReplaceValueNext,
|
|
1563
|
+
'TextSearch.focusSearchValue': focusSearchValue,
|
|
1564
|
+
'TextSearch.focusSearchValueNext': focusSearchValueNext,
|
|
1565
|
+
'TextSearch.getVirtualDom': getSearchVirtualDom,
|
|
1099
1566
|
'TextSearch.textSearch': textSearch
|
|
1100
1567
|
};
|
|
1101
1568
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lvce-editor/text-search-worker",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/textSearchWorkerMain.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"keywords": [
|
|
8
|
-
|
|
7
|
+
"keywords": [
|
|
8
|
+
"text-search"
|
|
9
|
+
],
|
|
10
|
+
"author": "Lvce Editor",
|
|
9
11
|
"license": "MIT"
|
|
10
12
|
}
|