@lvce-editor/text-search-worker 2.3.0 → 2.4.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.
@@ -18,221 +18,31 @@ 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
- }) => {
21
+ const clearSearchResults$1 = state => {
41
22
  return {
42
- deltaY: 0,
23
+ ...state,
24
+ value: '',
25
+ items: [],
43
26
  minLineY: 0,
44
27
  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;
60
- const FocusSearchInput = 21;
61
- const FocusSearchReplaceInput = 31;
62
- const FocusSearchMatchCase = 32;
63
- const FocusSearchRegex = 33;
64
- const FocusSearchWholeWord = 34;
65
- const FocusSearchReplaceAll = 35;
66
- const FocusSearchPreserveCase = 36;
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
-
108
- const focusMatchCase$1 = state => {
109
- return {
110
- ...state,
111
- focus: FocusSearchMatchCase
112
- };
113
- };
114
-
115
- const focusReplaceValue$1 = state => {
116
- return {
117
- ...state,
118
- focus: FocusSearchReplaceInput
119
- };
120
- };
121
-
122
- const focusSearchValue$1 = state => {
123
- return {
124
- ...state,
125
- focus: FocusSearchInput
126
- };
127
- };
128
-
129
- const focusSearchValueNext$1 = state => {
130
- const {
131
- replaceExpanded
132
- } = state;
133
- if (replaceExpanded) {
134
- return focusReplaceValue$1(state);
135
- }
136
- return focusMatchCase$1(state);
137
- };
138
-
139
- const CheckBox = 'checkbox';
140
- const None = 'none';
141
- const Status = 'status';
142
- const Tree = 'tree';
143
- const TreeItem$1 = 'treeitem';
144
- const ToolBar = 'toolbar';
145
-
146
- const Chevron = 'Chevron';
147
- const CloseMaskIcon = 'MaskIcon MaskIconClose';
148
- const Empty = '';
149
- const FileIcon = 'FileIcon';
150
- const IconButton = 'IconButton';
151
- const Actions = 'Actions';
152
- const FocusOutline = 'FocusOutline';
153
- const Highlight = 'Highlight';
154
- const HighlightDeleted = 'HighlightDeleted';
155
- const HighlightInserted = 'HighlightInserted';
156
- const Label = 'Label';
157
- const List = 'List';
158
- const MaskIcon = 'MaskIcon';
159
- const MaskIconChevronDown = 'MaskIconChevronDown';
160
- const MaskIconChevronRight = 'MaskIconChevronRight';
161
- const MultilineInputBox = 'MultilineInputBox';
162
- const Search$1 = 'Search';
163
- const SearchField = 'SearchField';
164
- const SearchFieldButtons = 'SearchFieldButtons';
165
- const SearchFieldContainer = 'SearchFieldContainer';
166
- const SearchHeader = 'SearchHeader';
167
- const SearchHeaderTop = 'SearchHeaderTop';
168
- const SearchRemove = 'SearchRemove';
169
- const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
170
- const SourceControlBadge = 'SourceControlBadge';
171
- const TreeItem = 'TreeItem';
172
- const TreeItemActive = 'TreeItemActive';
173
- const Viewlet = 'Viewlet';
174
- const ViewletSearchMessage = 'ViewletSearchMessage';
175
-
176
- const Button$1 = 1;
177
-
178
- const Button = 1;
179
- const Div = 4;
180
- const Input = 6;
181
- const Span = 8;
182
- const Text = 12;
183
- const Img = 17;
184
- const Ins = 20;
185
- const Del = 21;
186
- const TextArea = 62;
187
-
188
- const getIconVirtualDom = (icon, type = Div) => {
189
- return {
190
- type,
191
- className: `MaskIcon MaskIcon${icon}`,
192
- role: None,
193
- childCount: 0
28
+ message: ''
194
29
  };
195
30
  };
196
31
 
197
- const getActionButtonVirtualDom = action => {
198
- const {
199
- id,
200
- icon,
201
- command
202
- } = action;
203
- return [{
204
- type: Button,
205
- className: IconButton,
206
- title: id,
207
- 'data-command': command,
208
- childCount: 1
209
- }, getIconVirtualDom(icon)];
32
+ const state$3 = {
33
+ /**
34
+ * @type {any}
35
+ */
36
+ ipc: undefined
210
37
  };
211
-
212
- const getActionVirtualDom = action => {
213
- switch (action.type) {
214
- case Button$1:
215
- return getActionButtonVirtualDom(action);
216
- default:
217
- return [];
218
- }
38
+ const get$2 = () => {
39
+ return state$3.ipc;
219
40
  };
220
-
221
- const getActionsVirtualDom = actions => {
222
- return [{
223
- type: Div,
224
- className: Actions,
225
- role: ToolBar,
226
- childCount: actions.length
227
- }, ...actions.flatMap(getActionVirtualDom)];
41
+ const set$2 = ipc => {
42
+ state$3.ipc = ipc;
228
43
  };
229
44
 
230
- const ClearAll = 'ClearAll';
231
- const CollapseAll = 'CollapseAll';
232
- const ListFlat = 'ListFlat';
233
- const NewFile = 'NewFile';
234
- const Refresh = 'Refresh';
235
-
45
+ const Two = '2.0';
236
46
  let AssertionError$1 = class AssertionError extends Error {
237
47
  constructor(message) {
238
48
  super(message);
@@ -267,29 +77,625 @@ const number$1 = value => {
267
77
  throw new AssertionError$1('expected value to be of type number');
268
78
  }
269
79
  };
270
- const string = value => {
271
- const type = getType$1(value);
272
- if (type !== 'string') {
273
- throw new AssertionError$1('expected value to be of type string');
274
- }
80
+ const state$1 = {
81
+ callbacks: Object.create(null)
275
82
  };
276
-
277
- const emptyObject = {};
278
- const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
279
- const i18nString = (key, placeholders = emptyObject) => {
280
- if (placeholders === emptyObject) {
281
- return key;
282
- }
283
- const replacer = (match, rest) => {
284
- // @ts-ignore
285
- return placeholders[rest];
83
+ const set$1 = (id, fn) => {
84
+ state$1.callbacks[id] = fn;
85
+ };
86
+ const get$1 = id => {
87
+ return state$1.callbacks[id];
88
+ };
89
+ const remove = id => {
90
+ delete state$1.callbacks[id];
91
+ };
92
+ const state$2 = {
93
+ id: 0
94
+ };
95
+ const create$3 = () => {
96
+ return ++state$2.id;
97
+ };
98
+ const warn = (...args) => {
99
+ console.warn(...args);
100
+ };
101
+ const registerPromise = () => {
102
+ const id = create$3();
103
+ const {
104
+ resolve,
105
+ promise
106
+ } = Promise.withResolvers();
107
+ set$1(id, resolve);
108
+ return {
109
+ id,
110
+ promise
286
111
  };
287
- return key.replaceAll(RE_PLACEHOLDER, replacer);
288
112
  };
289
-
290
- /**
291
- * @enum {string}
292
- */
113
+ const resolve = (id, args) => {
114
+ number$1(id);
115
+ const fn = get$1(id);
116
+ if (!fn) {
117
+ console.log(args);
118
+ warn(`callback ${id} may already be disposed`);
119
+ return;
120
+ }
121
+ fn(args);
122
+ remove(id);
123
+ };
124
+ const create$2 = (method, params) => {
125
+ const {
126
+ id,
127
+ promise
128
+ } = registerPromise();
129
+ const message = {
130
+ jsonrpc: Two,
131
+ method,
132
+ params,
133
+ id
134
+ };
135
+ return {
136
+ message,
137
+ promise
138
+ };
139
+ };
140
+ class JsonRpcError extends Error {
141
+ constructor(message) {
142
+ super(message);
143
+ this.name = 'JsonRpcError';
144
+ }
145
+ }
146
+ const NewLine$3 = '\n';
147
+ const DomException = 'DOMException';
148
+ const ReferenceError$1 = 'ReferenceError';
149
+ const SyntaxError$1 = 'SyntaxError';
150
+ const TypeError$1 = 'TypeError';
151
+ const getErrorConstructor = (message, type) => {
152
+ if (type) {
153
+ switch (type) {
154
+ case DomException:
155
+ return DOMException;
156
+ case TypeError$1:
157
+ return TypeError;
158
+ case SyntaxError$1:
159
+ return SyntaxError;
160
+ case ReferenceError$1:
161
+ return ReferenceError;
162
+ default:
163
+ return Error;
164
+ }
165
+ }
166
+ if (message.startsWith('TypeError: ')) {
167
+ return TypeError;
168
+ }
169
+ if (message.startsWith('SyntaxError: ')) {
170
+ return SyntaxError;
171
+ }
172
+ if (message.startsWith('ReferenceError: ')) {
173
+ return ReferenceError;
174
+ }
175
+ return Error;
176
+ };
177
+ const constructError = (message, type, name) => {
178
+ const ErrorConstructor = getErrorConstructor(message, type);
179
+ if (ErrorConstructor === DOMException && name) {
180
+ return new ErrorConstructor(message, name);
181
+ }
182
+ if (ErrorConstructor === Error) {
183
+ const error = new Error(message);
184
+ if (name && name !== 'VError') {
185
+ error.name = name;
186
+ }
187
+ return error;
188
+ }
189
+ return new ErrorConstructor(message);
190
+ };
191
+ const getNewLineIndex$2 = (string, startIndex = undefined) => {
192
+ return string.indexOf(NewLine$3, startIndex);
193
+ };
194
+ const getParentStack = error => {
195
+ let parentStack = error.stack || error.data || error.message || '';
196
+ if (parentStack.startsWith(' at')) {
197
+ parentStack = error.message + NewLine$3 + parentStack;
198
+ }
199
+ return parentStack;
200
+ };
201
+ const joinLines$1 = lines => {
202
+ return lines.join(NewLine$3);
203
+ };
204
+ const MethodNotFound = -32601;
205
+ const Custom = -32001;
206
+ const splitLines$2 = lines => {
207
+ return lines.split(NewLine$3);
208
+ };
209
+ const restoreJsonRpcError = error => {
210
+ if (error && error instanceof Error) {
211
+ return error;
212
+ }
213
+ const currentStack = joinLines$1(splitLines$2(new Error().stack || '').slice(1));
214
+ if (error && error.code && error.code === MethodNotFound) {
215
+ const restoredError = new JsonRpcError(error.message);
216
+ const parentStack = getParentStack(error);
217
+ restoredError.stack = parentStack + NewLine$3 + currentStack;
218
+ return restoredError;
219
+ }
220
+ if (error && error.message) {
221
+ const restoredError = constructError(error.message, error.type, error.name);
222
+ if (error.data) {
223
+ if (error.data.stack && error.data.type && error.message) {
224
+ restoredError.stack = error.data.type + ': ' + error.message + NewLine$3 + error.data.stack + NewLine$3 + currentStack;
225
+ } else if (error.data.stack) {
226
+ restoredError.stack = error.data.stack;
227
+ }
228
+ if (error.data.codeFrame) {
229
+ // @ts-ignore
230
+ restoredError.codeFrame = error.data.codeFrame;
231
+ }
232
+ if (error.data.code) {
233
+ // @ts-ignore
234
+ restoredError.code = error.data.code;
235
+ }
236
+ if (error.data.type) {
237
+ // @ts-ignore
238
+ restoredError.name = error.data.type;
239
+ }
240
+ } else {
241
+ if (error.stack) {
242
+ const lowerStack = restoredError.stack || '';
243
+ // @ts-ignore
244
+ const indexNewLine = getNewLineIndex$2(lowerStack);
245
+ const parentStack = getParentStack(error);
246
+ // @ts-ignore
247
+ restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
248
+ }
249
+ if (error.codeFrame) {
250
+ // @ts-ignore
251
+ restoredError.codeFrame = error.codeFrame;
252
+ }
253
+ }
254
+ return restoredError;
255
+ }
256
+ if (typeof error === 'string') {
257
+ return new Error(`JsonRpc Error: ${error}`);
258
+ }
259
+ return new Error(`JsonRpc Error: ${error}`);
260
+ };
261
+ const unwrapJsonRpcResult = responseMessage => {
262
+ if ('error' in responseMessage) {
263
+ const restoredError = restoreJsonRpcError(responseMessage.error);
264
+ throw restoredError;
265
+ }
266
+ if ('result' in responseMessage) {
267
+ return responseMessage.result;
268
+ }
269
+ throw new JsonRpcError('unexpected response message');
270
+ };
271
+ const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
272
+ const getErrorType = prettyError => {
273
+ if (prettyError && prettyError.type) {
274
+ return prettyError.type;
275
+ }
276
+ if (prettyError && prettyError.constructor && prettyError.constructor.name) {
277
+ return prettyError.constructor.name;
278
+ }
279
+ return undefined;
280
+ };
281
+ const getErrorProperty = (error, prettyError) => {
282
+ if (error && error.code === E_COMMAND_NOT_FOUND) {
283
+ return {
284
+ code: MethodNotFound,
285
+ message: error.message,
286
+ data: error.stack
287
+ };
288
+ }
289
+ return {
290
+ code: Custom,
291
+ message: prettyError.message,
292
+ data: {
293
+ stack: prettyError.stack,
294
+ codeFrame: prettyError.codeFrame,
295
+ type: getErrorType(prettyError),
296
+ code: prettyError.code,
297
+ name: prettyError.name
298
+ }
299
+ };
300
+ };
301
+ const create$1$1 = (message, error) => {
302
+ return {
303
+ jsonrpc: Two,
304
+ id: message.id,
305
+ error
306
+ };
307
+ };
308
+ const getErrorResponse = (message, error, preparePrettyError, logError) => {
309
+ const prettyError = preparePrettyError(error);
310
+ logError(error, prettyError);
311
+ const errorProperty = getErrorProperty(error, prettyError);
312
+ return create$1$1(message, errorProperty);
313
+ };
314
+ const create$4 = (message, result) => {
315
+ return {
316
+ jsonrpc: Two,
317
+ id: message.id,
318
+ result: result ?? null
319
+ };
320
+ };
321
+ const getSuccessResponse = (message, result) => {
322
+ const resultProperty = result ?? null;
323
+ return create$4(message, resultProperty);
324
+ };
325
+ const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
326
+ try {
327
+ const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
328
+ return getSuccessResponse(message, result);
329
+ } catch (error) {
330
+ return getErrorResponse(message, error, preparePrettyError, logError);
331
+ }
332
+ };
333
+ const defaultPreparePrettyError = error => {
334
+ return error;
335
+ };
336
+ const defaultLogError = () => {
337
+ // ignore
338
+ };
339
+ const defaultRequiresSocket = () => {
340
+ return false;
341
+ };
342
+ const defaultResolve = resolve;
343
+ const handleJsonRpcMessage = async (...args) => {
344
+ let message;
345
+ let ipc;
346
+ let execute;
347
+ let preparePrettyError;
348
+ let logError;
349
+ let resolve;
350
+ let requiresSocket;
351
+ if (args.length === 1) {
352
+ const arg = args[0];
353
+ message = arg.message;
354
+ ipc = arg.ipc;
355
+ execute = arg.execute;
356
+ preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
357
+ logError = arg.logError || defaultLogError;
358
+ requiresSocket = arg.requiresSocket || defaultRequiresSocket;
359
+ resolve = arg.resolve || defaultResolve;
360
+ } else {
361
+ ipc = args[0];
362
+ message = args[1];
363
+ execute = args[2];
364
+ resolve = args[3];
365
+ preparePrettyError = args[4];
366
+ logError = args[5];
367
+ requiresSocket = args[6];
368
+ }
369
+ if ('id' in message) {
370
+ if ('method' in message) {
371
+ const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
372
+ try {
373
+ ipc.send(response);
374
+ } catch (error) {
375
+ const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
376
+ ipc.send(errorResponse);
377
+ }
378
+ return;
379
+ }
380
+ resolve(message.id, message);
381
+ return;
382
+ }
383
+ if ('method' in message) {
384
+ await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
385
+ return;
386
+ }
387
+ throw new JsonRpcError('unexpected message');
388
+ };
389
+ const invoke$2 = async (ipc, method, ...params) => {
390
+ const {
391
+ message,
392
+ promise
393
+ } = create$2(method, params);
394
+ ipc.send(message);
395
+ const responseMessage = await promise;
396
+ const result = unwrapJsonRpcResult(responseMessage);
397
+ return result;
398
+ };
399
+
400
+ const invoke$1 = (method, ...params) => {
401
+ const ipc = get$2();
402
+ return invoke$2(ipc, method, ...params);
403
+ };
404
+ const listen$2 = ipc => {
405
+ set$2(ipc);
406
+ };
407
+
408
+ const copy = async state => {
409
+ const {
410
+ items,
411
+ listFocusedIndex
412
+ } = state;
413
+ if (listFocusedIndex === -1) {
414
+ return state;
415
+ }
416
+ const item = items[listFocusedIndex];
417
+ await invoke$1('ClipBoard.writeText', item.text);
418
+ return state;
419
+ };
420
+
421
+ const ListItem = 22;
422
+
423
+ const User = 1;
424
+ const Script = 2;
425
+
426
+ const minimumSliderSize = 20;
427
+
428
+ const states = Object.create(null);
429
+ const get = uid => {
430
+ return states[uid];
431
+ };
432
+ const set = (uid, state) => {
433
+ states[uid] = state;
434
+ };
435
+
436
+ const create$1 = ({
437
+ itemHeight,
438
+ headerHeight = 0,
439
+ minimumSliderSize = 20
440
+ }) => {
441
+ return {
442
+ deltaY: 0,
443
+ minLineY: 0,
444
+ maxLineY: 0,
445
+ finalDeltaY: 0,
446
+ itemHeight,
447
+ headerHeight,
448
+ items: [],
449
+ minimumSliderSize,
450
+ focusedIndex: -1,
451
+ touchOffsetY: 0,
452
+ touchTimeStamp: 0,
453
+ touchDifference: 0,
454
+ scrollBarHeight: 0,
455
+ scrollBarActive: false
456
+ };
457
+ };
458
+
459
+ const Empty$1 = 0;
460
+ const FocusSearchInput = 21;
461
+ const FocusSearchReplaceInput = 31;
462
+ const FocusSearchMatchCase = 32;
463
+ const FocusSearchRegex = 33;
464
+ const FocusSearchWholeWord = 34;
465
+ const FocusSearchReplaceAll = 35;
466
+ const FocusSearchPreserveCase = 36;
467
+
468
+ const create = (uid, x, y, width, height, workspacePath) => {
469
+ const state = {
470
+ uid,
471
+ searchResults: [],
472
+ stats: {},
473
+ searchId: -1,
474
+ value: '',
475
+ disposed: false,
476
+ fileCount: 0,
477
+ x,
478
+ y,
479
+ width,
480
+ height,
481
+ ...create$1({
482
+ itemHeight: ListItem,
483
+ minimumSliderSize: minimumSliderSize,
484
+ headerHeight: 61 // TODO
485
+ }),
486
+ threads: 0,
487
+ replaceExpanded: false,
488
+ useRegularExpression: false,
489
+ matchCase: false,
490
+ matchWholeWord: false,
491
+ replacement: '',
492
+ matchCount: 0,
493
+ listFocused: false,
494
+ listFocusedIndex: -1,
495
+ inputSource: User,
496
+ workspacePath: workspacePath,
497
+ includeValue: '',
498
+ excludeValue: '',
499
+ detailsExpanded: false,
500
+ focus: Empty$1,
501
+ loaded: false,
502
+ message: '',
503
+ collapsedPaths: []
504
+ };
505
+ set(uid, state);
506
+ };
507
+
508
+ const focusMatchCase$1 = state => {
509
+ return {
510
+ ...state,
511
+ focus: FocusSearchMatchCase
512
+ };
513
+ };
514
+
515
+ const focusReplaceValue$1 = state => {
516
+ return {
517
+ ...state,
518
+ focus: FocusSearchReplaceInput
519
+ };
520
+ };
521
+
522
+ const focusSearchValue$1 = state => {
523
+ return {
524
+ ...state,
525
+ focus: FocusSearchInput
526
+ };
527
+ };
528
+
529
+ const focusSearchValueNext$1 = state => {
530
+ const {
531
+ replaceExpanded
532
+ } = state;
533
+ if (replaceExpanded) {
534
+ return focusReplaceValue$1(state);
535
+ }
536
+ return focusMatchCase$1(state);
537
+ };
538
+
539
+ const CheckBox = 'checkbox';
540
+ const None = 'none';
541
+ const Status = 'status';
542
+ const Tree = 'tree';
543
+ const TreeItem$1 = 'treeitem';
544
+ const ToolBar = 'toolbar';
545
+
546
+ const Chevron = 'Chevron';
547
+ const CloseMaskIcon = 'MaskIcon MaskIconClose';
548
+ const Empty = '';
549
+ const FileIcon = 'FileIcon';
550
+ const IconButton = 'IconButton';
551
+ const Actions = 'Actions';
552
+ const FocusOutline = 'FocusOutline';
553
+ const Highlight = 'Highlight';
554
+ const HighlightDeleted = 'HighlightDeleted';
555
+ const HighlightInserted = 'HighlightInserted';
556
+ const Label = 'Label';
557
+ const List = 'List';
558
+ const MaskIcon = 'MaskIcon';
559
+ const MaskIconChevronDown = 'MaskIconChevronDown';
560
+ const MaskIconChevronRight = 'MaskIconChevronRight';
561
+ const MultilineInputBox = 'MultilineInputBox';
562
+ const Search$1 = 'Search';
563
+ const SearchField = 'SearchField';
564
+ const SearchFieldButtons = 'SearchFieldButtons';
565
+ const SearchFieldContainer = 'SearchFieldContainer';
566
+ const SearchHeader = 'SearchHeader';
567
+ const SearchHeaderTop = 'SearchHeaderTop';
568
+ const SearchRemove = 'SearchRemove';
569
+ const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
570
+ const SourceControlBadge = 'SourceControlBadge';
571
+ const TreeItem = 'TreeItem';
572
+ const TreeItemActive = 'TreeItemActive';
573
+ const Viewlet = 'Viewlet';
574
+ const ViewletSearchMessage = 'ViewletSearchMessage';
575
+
576
+ const Button$1 = 1;
577
+
578
+ const Button = 1;
579
+ const Div = 4;
580
+ const Input = 6;
581
+ const Span = 8;
582
+ const Text = 12;
583
+ const Img = 17;
584
+ const Ins = 20;
585
+ const Del = 21;
586
+ const TextArea = 62;
587
+
588
+ const getIconVirtualDom = (icon, type = Div) => {
589
+ return {
590
+ type,
591
+ className: `MaskIcon MaskIcon${icon}`,
592
+ role: None,
593
+ childCount: 0
594
+ };
595
+ };
596
+
597
+ const getActionButtonVirtualDom = action => {
598
+ const {
599
+ id,
600
+ icon,
601
+ command
602
+ } = action;
603
+ return [{
604
+ type: Button,
605
+ className: IconButton,
606
+ title: id,
607
+ 'data-command': command,
608
+ childCount: 1
609
+ }, getIconVirtualDom(icon)];
610
+ };
611
+
612
+ const getActionVirtualDom = action => {
613
+ switch (action.type) {
614
+ case Button$1:
615
+ return getActionButtonVirtualDom(action);
616
+ default:
617
+ return [];
618
+ }
619
+ };
620
+
621
+ const getActionsVirtualDom = actions => {
622
+ return [{
623
+ type: Div,
624
+ className: Actions,
625
+ role: ToolBar,
626
+ childCount: actions.length
627
+ }, ...actions.flatMap(getActionVirtualDom)];
628
+ };
629
+
630
+ const ClearAll = 'ClearAll';
631
+ const CollapseAll = 'CollapseAll';
632
+ const ListFlat = 'ListFlat';
633
+ const NewFile = 'NewFile';
634
+ const Refresh = 'Refresh';
635
+
636
+ class AssertionError extends Error {
637
+ constructor(message) {
638
+ super(message);
639
+ this.name = 'AssertionError';
640
+ }
641
+ }
642
+ const getType = value => {
643
+ switch (typeof value) {
644
+ case 'number':
645
+ return 'number';
646
+ case 'function':
647
+ return 'function';
648
+ case 'string':
649
+ return 'string';
650
+ case 'object':
651
+ if (value === null) {
652
+ return 'null';
653
+ }
654
+ if (Array.isArray(value)) {
655
+ return 'array';
656
+ }
657
+ return 'object';
658
+ case 'boolean':
659
+ return 'boolean';
660
+ default:
661
+ return 'unknown';
662
+ }
663
+ };
664
+ const object = value => {
665
+ const type = getType(value);
666
+ if (type !== 'object') {
667
+ throw new AssertionError('expected value to be of type object');
668
+ }
669
+ };
670
+ const number = value => {
671
+ const type = getType(value);
672
+ if (type !== 'number') {
673
+ throw new AssertionError('expected value to be of type number');
674
+ }
675
+ };
676
+ const string = value => {
677
+ const type = getType(value);
678
+ if (type !== 'string') {
679
+ throw new AssertionError('expected value to be of type string');
680
+ }
681
+ };
682
+
683
+ const emptyObject = {};
684
+ const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
685
+ const i18nString = (key, placeholders = emptyObject) => {
686
+ if (placeholders === emptyObject) {
687
+ return key;
688
+ }
689
+ const replacer = (match, rest) => {
690
+ // @ts-ignore
691
+ return placeholders[rest];
692
+ };
693
+ return key.replaceAll(RE_PLACEHOLDER, replacer);
694
+ };
695
+
696
+ /**
697
+ * @enum {string}
698
+ */
293
699
  const UiStrings = {
294
700
  NoResults: 'No results found',
295
701
  Oneresult: '1 result in 1 file',
@@ -332,7 +738,7 @@ const manyResultsInManyFiles = (resultCount, fileResultCount) => {
332
738
  PH2: fileResultCount
333
739
  });
334
740
  };
335
- const refresh = () => {
741
+ const refresh$1 = () => {
336
742
  return i18nString(UiStrings.Refresh);
337
743
  };
338
744
  const clearSearchResults = () => {
@@ -351,7 +757,7 @@ const collapseAll = () => {
351
757
  const getActions = () => {
352
758
  return [{
353
759
  type: Button$1,
354
- id: refresh(),
760
+ id: refresh$1(),
355
761
  icon: Refresh,
356
762
  command: 'refresh'
357
763
  }, {
@@ -757,490 +1163,493 @@ const getSearchResultVirtualDom = rowInfo => {
757
1163
  });
758
1164
  return dom;
759
1165
  };
760
-
761
- const getSearchResultsVirtualDom = visibleItems => {
762
- return visibleItems.flatMap(getSearchResultVirtualDom);
763
- };
764
-
765
- const mergeClassNames = (...classNames) => {
766
- return classNames.filter(Boolean).join(' ');
767
- };
768
-
769
- const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWholeWord, useRegularExpression, message, detailsExpanded, focusOutline) => {
770
- /**
771
- * @type {any[]}
772
- */
773
- const dom = [];
774
- dom.push({
775
- type: Div,
776
- className: mergeClassNames(Viewlet, Search$1),
777
- childCount: 2
778
- });
779
- dom.push(...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded));
780
- dom.push({
781
- type: Div,
782
- className: ViewletSearchMessage,
783
- role: Status,
784
- tabIndex: 0,
785
- childCount: 1
786
- }, text(message));
787
- dom.push({
788
- type: Div,
789
- className: mergeClassNames(Viewlet, List, focusOutline ? FocusOutline : Empty),
790
- role: Tree,
791
- tabIndex: 0,
792
- childCount: visibleItems.length,
793
- onClick: HandleClick,
794
- onBlur: HandleListBlur
795
- });
796
- dom.push(...getSearchResultsVirtualDom(visibleItems));
797
- return dom;
798
- };
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
-
870
- const state$3 = {
871
- /**
872
- * @type {any}
873
- */
874
- ipc: undefined
875
- };
876
- const get$1 = () => {
877
- return state$3.ipc;
878
- };
879
- const set$1 = ipc => {
880
- state$3.ipc = ipc;
881
- };
882
-
883
- const Two = '2.0';
884
- class AssertionError extends Error {
885
- constructor(message) {
886
- super(message);
887
- this.name = 'AssertionError';
888
- }
889
- }
890
- const getType = value => {
891
- switch (typeof value) {
892
- case 'number':
893
- return 'number';
894
- case 'function':
895
- return 'function';
896
- case 'string':
897
- return 'string';
898
- case 'object':
899
- if (value === null) {
900
- return 'null';
901
- }
902
- if (Array.isArray(value)) {
903
- return 'array';
904
- }
905
- return 'object';
906
- case 'boolean':
907
- return 'boolean';
908
- default:
909
- return 'unknown';
910
- }
911
- };
912
- const number = value => {
913
- const type = getType(value);
914
- if (type !== 'number') {
915
- throw new AssertionError('expected value to be of type number');
916
- }
1166
+
1167
+ const getSearchResultsVirtualDom = visibleItems => {
1168
+ return visibleItems.flatMap(getSearchResultVirtualDom);
917
1169
  };
918
- const state$1 = {
919
- callbacks: Object.create(null)
1170
+
1171
+ const mergeClassNames = (...classNames) => {
1172
+ return classNames.filter(Boolean).join(' ');
920
1173
  };
921
- const set = (id, fn) => {
922
- state$1.callbacks[id] = fn;
1174
+
1175
+ const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWholeWord, useRegularExpression, message, detailsExpanded, focusOutline) => {
1176
+ /**
1177
+ * @type {any[]}
1178
+ */
1179
+ const dom = [];
1180
+ dom.push({
1181
+ type: Div,
1182
+ className: mergeClassNames(Viewlet, Search$1),
1183
+ childCount: 2
1184
+ });
1185
+ dom.push(...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded));
1186
+ dom.push({
1187
+ type: Div,
1188
+ className: ViewletSearchMessage,
1189
+ role: Status,
1190
+ tabIndex: 0,
1191
+ childCount: 1
1192
+ }, text(message));
1193
+ dom.push({
1194
+ type: Div,
1195
+ className: mergeClassNames(Viewlet, List, focusOutline ? FocusOutline : Empty),
1196
+ role: Tree,
1197
+ tabIndex: 0,
1198
+ childCount: visibleItems.length,
1199
+ onClick: HandleClick,
1200
+ onBlur: HandleListBlur
1201
+ });
1202
+ dom.push(...getSearchResultsVirtualDom(visibleItems));
1203
+ return dom;
923
1204
  };
924
- const get = id => {
925
- return state$1.callbacks[id];
1205
+
1206
+ const handleIconThemeChange = state => {
1207
+ const {
1208
+ items
1209
+ } = state;
1210
+ const newItems = [...items];
1211
+ return {
1212
+ ...state,
1213
+ items: newItems
1214
+ };
926
1215
  };
927
- const remove = id => {
928
- delete state$1.callbacks[id];
1216
+
1217
+ const first = () => {
1218
+ return 0;
929
1219
  };
930
- const state$2 = {
931
- id: 0
1220
+ const last = items => {
1221
+ return items.length - 1;
932
1222
  };
933
- const create$3 = () => {
934
- return ++state$2.id;
1223
+ const next = (items, index) => {
1224
+ return (index + 1) % items.length;
935
1225
  };
936
- const warn = (...args) => {
937
- console.warn(...args);
1226
+ const previous = (items, index) => {
1227
+ return index === 0 ? items.length - 1 : index - 1;
938
1228
  };
939
- const registerPromise = () => {
940
- const id = create$3();
941
- const {
942
- resolve,
943
- promise
944
- } = Promise.withResolvers();
945
- set(id, resolve);
1229
+
1230
+ // TODO optimize this function to return the minimum number
1231
+ // of visible items needed, e.g. when not scrolled 5 items with
1232
+ // 20px fill 100px but when scrolled 6 items are needed
1233
+ const getNumberOfVisibleItems = (listHeight, itemHeight) => {
1234
+ return Math.ceil(listHeight / itemHeight) + 1;
1235
+ };
1236
+
1237
+ const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
1238
+ const newMinLineY = index;
1239
+ const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
1240
+ const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
1241
+ const newDeltaY = newMinLineY * itemHeight;
946
1242
  return {
947
- id,
948
- promise
1243
+ ...state,
1244
+ focusedIndex: index,
1245
+ minLineY: newMinLineY,
1246
+ maxLineY: newMaxLineY,
1247
+ focused: true,
1248
+ deltaY: newDeltaY
949
1249
  };
950
1250
  };
951
- const resolve = (id, args) => {
952
- number(id);
953
- const fn = get(id);
954
- if (!fn) {
955
- console.log(args);
956
- warn(`callback ${id} may already be disposed`);
957
- return;
958
- }
959
- fn(args);
960
- remove(id);
961
- };
962
- const create$2 = (method, params) => {
963
- const {
964
- id,
965
- promise
966
- } = registerPromise();
967
- const message = {
968
- jsonrpc: Two,
969
- method,
970
- params,
971
- id
972
- };
1251
+ const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
1252
+ const newMaxLineY = Math.min(index + 1, itemsLength);
1253
+ const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
1254
+ const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
1255
+ const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
973
1256
  return {
974
- message,
975
- promise
1257
+ ...state,
1258
+ focusedIndex: index,
1259
+ minLineY: newMinLineY,
1260
+ maxLineY: newMaxLineY,
1261
+ focused: true,
1262
+ deltaY: newDeltaY
976
1263
  };
977
1264
  };
978
- class JsonRpcError extends Error {
979
- constructor(message) {
980
- super(message);
981
- this.name = 'JsonRpcError';
982
- }
983
- }
984
- const NewLine$3 = '\n';
985
- const DomException = 'DOMException';
986
- const ReferenceError$1 = 'ReferenceError';
987
- const SyntaxError$1 = 'SyntaxError';
988
- const TypeError$1 = 'TypeError';
989
- const getErrorConstructor = (message, type) => {
990
- if (type) {
991
- switch (type) {
992
- case DomException:
993
- return DOMException;
994
- case TypeError$1:
995
- return TypeError;
996
- case SyntaxError$1:
997
- return SyntaxError;
998
- case ReferenceError$1:
999
- return ReferenceError;
1000
- default:
1001
- return Error;
1002
- }
1265
+ const focusIndex = (state, index) => {
1266
+ const {
1267
+ itemHeight,
1268
+ minLineY,
1269
+ maxLineY,
1270
+ headerHeight,
1271
+ height,
1272
+ items
1273
+ } = state;
1274
+ const itemsLength = items.length;
1275
+ if (itemsLength === 0) {
1276
+ return state;
1003
1277
  }
1004
- if (message.startsWith('TypeError: ')) {
1005
- return TypeError;
1278
+ number(itemHeight);
1279
+ if (index === -1) {
1280
+ return {
1281
+ ...state,
1282
+ focusedIndex: -1,
1283
+ focused: true
1284
+ };
1006
1285
  }
1007
- if (message.startsWith('SyntaxError: ')) {
1008
- return SyntaxError;
1286
+ const listHeight = height - headerHeight;
1287
+ if (index < minLineY + 1) {
1288
+ return focusIndexScrollUp(state, index, listHeight, itemHeight, itemsLength);
1009
1289
  }
1010
- if (message.startsWith('ReferenceError: ')) {
1011
- return ReferenceError;
1290
+ if (index >= maxLineY - 1) {
1291
+ return focusIndexScrollDown(state, index, listHeight, itemHeight, itemsLength);
1012
1292
  }
1013
- return Error;
1293
+ return {
1294
+ ...state,
1295
+ focusedIndex: index,
1296
+ focused: true
1297
+ };
1014
1298
  };
1015
- const constructError = (message, type, name) => {
1016
- const ErrorConstructor = getErrorConstructor(message, type);
1017
- if (ErrorConstructor === DOMException && name) {
1018
- return new ErrorConstructor(message, name);
1019
- }
1020
- if (ErrorConstructor === Error) {
1021
- const error = new Error(message);
1022
- if (name && name !== 'VError') {
1023
- error.name = name;
1024
- }
1025
- return error;
1026
- }
1027
- return new ErrorConstructor(message);
1299
+
1300
+ const focusFirst = state => {
1301
+ const firstIndex = first();
1302
+ return focusIndex(state, firstIndex);
1028
1303
  };
1029
- const getNewLineIndex$2 = (string, startIndex = undefined) => {
1030
- return string.indexOf(NewLine$3, startIndex);
1304
+
1305
+ const focusLast = state => {
1306
+ const {
1307
+ items
1308
+ } = state;
1309
+ const lastIndex = last(items);
1310
+ return focusIndex(state, lastIndex);
1031
1311
  };
1032
- const getParentStack = error => {
1033
- let parentStack = error.stack || error.data || error.message || '';
1034
- if (parentStack.startsWith(' at')) {
1035
- parentStack = error.message + NewLine$3 + parentStack;
1312
+
1313
+ const focusNext = state => {
1314
+ const {
1315
+ focusedIndex,
1316
+ items
1317
+ } = state;
1318
+ const nextIndex = next(items, focusedIndex);
1319
+ return focusIndex(state, nextIndex);
1320
+ };
1321
+
1322
+ // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1323
+
1324
+ const insertInto = (array, start, newItems) => {
1325
+ const originalLength = array.length;
1326
+ const newItemsLength = newItems.length;
1327
+ array.length = originalLength + newItemsLength;
1328
+ // Move the items after the start index, start from the end so that we don't overwrite any value.
1329
+ for (let i = originalLength - 1; i >= start; i--) {
1330
+ array[i + newItemsLength] = array[i];
1331
+ }
1332
+ for (let i = 0; i < newItemsLength; i++) {
1333
+ array[i + start] = newItems[i];
1036
1334
  }
1037
- return parentStack;
1038
1335
  };
1039
- const joinLines$1 = lines => {
1040
- return lines.join(NewLine$3);
1336
+ const push = (array, newItems) => {
1337
+ insertInto(array, array.length, newItems);
1041
1338
  };
1042
- const MethodNotFound = -32601;
1043
- const Custom = -32001;
1044
- const splitLines$2 = lines => {
1045
- return lines.split(NewLine$3);
1339
+ const isLastIndex = (array, index) => {
1340
+ return index === array.length - 1;
1046
1341
  };
1047
- const restoreJsonRpcError = error => {
1048
- if (error && error instanceof Error) {
1049
- return error;
1050
- }
1051
- const currentStack = joinLines$1(splitLines$2(new Error().stack || '').slice(1));
1052
- if (error && error.code && error.code === MethodNotFound) {
1053
- const restoredError = new JsonRpcError(error.message);
1054
- const parentStack = getParentStack(error);
1055
- restoredError.stack = parentStack + NewLine$3 + currentStack;
1056
- return restoredError;
1057
- }
1058
- if (error && error.message) {
1059
- const restoredError = constructError(error.message, error.type, error.name);
1060
- if (error.data) {
1061
- if (error.data.stack && error.data.type && error.message) {
1062
- restoredError.stack = error.data.type + ': ' + error.message + NewLine$3 + error.data.stack + NewLine$3 + currentStack;
1063
- } else if (error.data.stack) {
1064
- restoredError.stack = error.data.stack;
1065
- }
1066
- if (error.data.codeFrame) {
1067
- // @ts-ignore
1068
- restoredError.codeFrame = error.data.codeFrame;
1069
- }
1070
- if (error.data.code) {
1071
- // @ts-ignore
1072
- restoredError.code = error.data.code;
1073
- }
1074
- if (error.data.type) {
1075
- // @ts-ignore
1076
- restoredError.name = error.data.type;
1077
- }
1078
- } else {
1079
- if (error.stack) {
1080
- const lowerStack = restoredError.stack || '';
1081
- // @ts-ignore
1082
- const indexNewLine = getNewLineIndex$2(lowerStack);
1083
- const parentStack = getParentStack(error);
1084
- // @ts-ignore
1085
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
1086
- }
1087
- if (error.codeFrame) {
1088
- // @ts-ignore
1089
- restoredError.codeFrame = error.codeFrame;
1090
- }
1091
- }
1092
- return restoredError;
1342
+ const lastIndex = array => {
1343
+ return array.length - 1;
1344
+ };
1345
+
1346
+ const focusNextPage = state => {
1347
+ const {
1348
+ focusedIndex,
1349
+ items,
1350
+ maxLineY,
1351
+ minLineY
1352
+ } = state;
1353
+ if (isLastIndex(items, focusedIndex)) {
1354
+ return state;
1093
1355
  }
1094
- if (typeof error === 'string') {
1095
- return new Error(`JsonRpc Error: ${error}`);
1356
+ const indexNextPage = Math.min(maxLineY + (maxLineY - minLineY) - 2, lastIndex(items));
1357
+ return focusIndex(state, indexNextPage);
1358
+ };
1359
+
1360
+ const focusPreviousPage = state => {
1361
+ const {
1362
+ focusedIndex,
1363
+ minLineY,
1364
+ maxLineY
1365
+ } = state;
1366
+ if (focusedIndex === 0 || focusedIndex === -1) {
1367
+ return state;
1096
1368
  }
1097
- return new Error(`JsonRpc Error: ${error}`);
1369
+ const indexPreviousPage = Math.max(minLineY - (maxLineY - minLineY) + 1, 0);
1370
+ return focusIndex(state, indexPreviousPage);
1098
1371
  };
1099
- const unwrapJsonRpcResult = responseMessage => {
1100
- if ('error' in responseMessage) {
1101
- const restoredError = restoreJsonRpcError(responseMessage.error);
1102
- throw restoredError;
1103
- }
1104
- if ('result' in responseMessage) {
1105
- return responseMessage.result;
1372
+
1373
+ const focusPrevious = state => {
1374
+ const {
1375
+ focusedIndex,
1376
+ items
1377
+ } = state;
1378
+ if (focusedIndex === 0 || focusedIndex === -1) {
1379
+ return state;
1106
1380
  }
1107
- throw new JsonRpcError('unexpected response message');
1381
+ const previousIndex = previous(items, focusedIndex);
1382
+ return focusIndex(state, previousIndex);
1108
1383
  };
1109
- const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
1110
- const getErrorType = prettyError => {
1111
- if (prettyError && prettyError.type) {
1112
- return prettyError.type;
1384
+
1385
+ const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight) => {
1386
+ const relativeY = eventY - y + deltaY;
1387
+ const index = Math.floor(relativeY / itemHeight);
1388
+ return index;
1389
+ };
1390
+
1391
+ const openUri = async (path, focus = true, props = {}) => {
1392
+ await invoke$1(/* Main.openUri */'Main.openUri', /* uri */path, /* focus */focus, props);
1393
+ };
1394
+
1395
+ const getFileIndex = (items, index) => {
1396
+ for (let i = index; i >= 0; i--) {
1397
+ const item = items[i];
1398
+ if (item.type === File$1) {
1399
+ return i;
1400
+ }
1113
1401
  }
1114
- if (prettyError && prettyError.constructor && prettyError.constructor.name) {
1115
- return prettyError.constructor.name;
1402
+ return -1;
1403
+ };
1404
+ const selectIndexFile = async (state, searchResult, index) => {
1405
+ const {
1406
+ collapsedPaths
1407
+ } = state;
1408
+ const path = getAbsolutePath(searchResult.text);
1409
+ string(path);
1410
+ return {
1411
+ ...state,
1412
+ collapsedPaths: [...collapsedPaths, path],
1413
+ listFocusedIndex: index,
1414
+ listFocused: true
1415
+ };
1416
+ };
1417
+ const selectIndexPreview = async (state, searchResult, index) => {
1418
+ const {
1419
+ items
1420
+ } = state;
1421
+ const fileIndex = getFileIndex(items, index);
1422
+ if (fileIndex === -1) {
1423
+ throw new Error('Search result is missing file');
1116
1424
  }
1117
- return undefined;
1425
+ const {
1426
+ lineNumber
1427
+ } = searchResult;
1428
+ // console.log({ searchResult })
1429
+ const fileResult = items[fileIndex];
1430
+ const path = getAbsolutePath(fileResult.text);
1431
+ string(path);
1432
+ await openUri(path, true, {
1433
+ selections: new Uint32Array([lineNumber, 0, lineNumber, 0])
1434
+ });
1435
+ return {
1436
+ ...state,
1437
+ listFocusedIndex: index,
1438
+ listFocused: false
1439
+ };
1118
1440
  };
1119
- const getErrorProperty = (error, prettyError) => {
1120
- if (error && error.code === E_COMMAND_NOT_FOUND) {
1441
+ const selectIndex = async (state, index, isClose) => {
1442
+ if (index === -1) {
1121
1443
  return {
1122
- code: MethodNotFound,
1123
- message: error.message,
1124
- data: error.stack
1444
+ ...state,
1445
+ listFocused: true,
1446
+ listFocusedIndex: -1
1125
1447
  };
1126
1448
  }
1449
+ const {
1450
+ items
1451
+ } = state;
1452
+ const searchResult = items[index];
1453
+ switch (searchResult.type) {
1454
+ case File$1:
1455
+ return selectIndexFile(state, searchResult, index);
1456
+ case Match:
1457
+ return selectIndexPreview(state, searchResult, index);
1458
+ default:
1459
+ throw new Error(`unexpected search result type ${searchResult.type}`);
1460
+ }
1461
+ };
1462
+
1463
+ const handleClickAt = async (state, eventX, eventY) => {
1464
+ const {
1465
+ x,
1466
+ y,
1467
+ itemHeight,
1468
+ deltaY
1469
+ } = state;
1470
+ const index = getListIndex(eventX, eventY, x, y, deltaY, itemHeight);
1471
+ return selectIndex(state, index);
1472
+ };
1473
+
1474
+ const handleScrollBarCaptureLost = state => {
1127
1475
  return {
1128
- code: Custom,
1129
- message: prettyError.message,
1130
- data: {
1131
- stack: prettyError.stack,
1132
- codeFrame: prettyError.codeFrame,
1133
- type: getErrorType(prettyError),
1134
- code: prettyError.code,
1135
- name: prettyError.name
1136
- }
1476
+ ...state,
1477
+ scrollBarActive: false
1137
1478
  };
1138
1479
  };
1139
- const create$1 = (message, error) => {
1480
+
1481
+ /**
1482
+ *
1483
+ * @param {number} size
1484
+ * @param {number} contentSize
1485
+ * @param {number} minimumSliderSize
1486
+ * @returns
1487
+ */
1488
+ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
1489
+ if (size >= contentSize) {
1490
+ return 0;
1491
+ }
1492
+ return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
1493
+ };
1494
+ const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
1495
+ const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
1496
+ return scrollBarOffset;
1497
+ };
1498
+ const getScrollBarY = getScrollBarOffset;
1499
+ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
1500
+ const halfScrollBarHeight = scrollBarHeight / 2;
1501
+ if (relativeY <= halfScrollBarHeight) {
1502
+ // clicked at top
1503
+ return {
1504
+ percent: 0,
1505
+ handleOffset: relativeY
1506
+ };
1507
+ }
1508
+ if (relativeY <= height - halfScrollBarHeight) {
1509
+ // clicked in middle
1510
+ return {
1511
+ percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
1512
+ handleOffset: halfScrollBarHeight
1513
+ };
1514
+ }
1515
+ // clicked at bottom
1140
1516
  return {
1141
- jsonrpc: Two,
1142
- id: message.id,
1143
- error
1517
+ percent: 1,
1518
+ handleOffset: scrollBarHeight - height + relativeY
1144
1519
  };
1145
1520
  };
1146
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
1147
- const prettyError = preparePrettyError(error);
1148
- logError(error, prettyError);
1149
- const errorProperty = getErrorProperty(error, prettyError);
1150
- return create$1(message, errorProperty);
1521
+
1522
+ const clamp = (num, min, max) => {
1523
+ number(num);
1524
+ number(min);
1525
+ number(max);
1526
+ return Math.min(Math.max(num, min), max);
1151
1527
  };
1152
- const create = (message, result) => {
1528
+
1529
+ const setDeltaY = (state, value) => {
1530
+ object(state);
1531
+ number(value);
1532
+ const {
1533
+ itemHeight,
1534
+ finalDeltaY,
1535
+ deltaY,
1536
+ height,
1537
+ headerHeight
1538
+ } = state;
1539
+ const listHeight = height - headerHeight;
1540
+ const newDeltaY = clamp(value, 0, finalDeltaY);
1541
+ if (deltaY === newDeltaY) {
1542
+ return state;
1543
+ }
1544
+ // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
1545
+ const minLineY = Math.floor(newDeltaY / itemHeight);
1546
+ const maxLineY = minLineY + getNumberOfVisibleItems(listHeight, itemHeight);
1153
1547
  return {
1154
- jsonrpc: Two,
1155
- id: message.id,
1156
- result: result ?? null
1548
+ ...state,
1549
+ deltaY: newDeltaY,
1550
+ minLineY,
1551
+ maxLineY
1157
1552
  };
1158
1553
  };
1159
- const getSuccessResponse = (message, result) => {
1160
- const resultProperty = result ?? null;
1161
- return create(message, resultProperty);
1554
+
1555
+ const handleScrollBarClick = (state, eventY) => {
1556
+ const {
1557
+ y,
1558
+ deltaY,
1559
+ headerHeight,
1560
+ finalDeltaY,
1561
+ scrollBarHeight,
1562
+ height
1563
+ } = state;
1564
+ const contentHeight = height - headerHeight;
1565
+ const relativeY = eventY - y - headerHeight;
1566
+ const currentScrollBarY = getScrollBarY(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
1567
+ const diff = relativeY - currentScrollBarY;
1568
+ if (diff >= 0 && diff < scrollBarHeight) {
1569
+ return {
1570
+ ...state,
1571
+ handleOffset: diff,
1572
+ scrollBarActive: true
1573
+ };
1574
+ }
1575
+ const {
1576
+ percent,
1577
+ handleOffset
1578
+ } = getNewDeltaPercent(contentHeight, scrollBarHeight, relativeY);
1579
+ const newDeltaY = percent * finalDeltaY;
1580
+ return {
1581
+ ...setDeltaY(state, newDeltaY),
1582
+ handleOffset,
1583
+ scrollBarActive: true
1584
+ };
1162
1585
  };
1163
- const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
1164
- try {
1165
- const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
1166
- return getSuccessResponse(message, result);
1167
- } catch (error) {
1168
- return getErrorResponse(message, error, preparePrettyError, logError);
1586
+
1587
+ const getNewPercent = (contentHeight, scrollBarHeight, relativeY) => {
1588
+ if (relativeY <= contentHeight - scrollBarHeight / 2) {
1589
+ // clicked in middle
1590
+ return relativeY / (contentHeight - scrollBarHeight);
1169
1591
  }
1592
+ // clicked at bottom
1593
+ return 1;
1170
1594
  };
1171
- const defaultPreparePrettyError = error => {
1172
- return error;
1595
+ const handleScrollBarMove = (state, eventY) => {
1596
+ const {
1597
+ y,
1598
+ headerHeight,
1599
+ handleOffset,
1600
+ finalDeltaY,
1601
+ height,
1602
+ scrollBarHeight
1603
+ } = state;
1604
+ const relativeY = eventY - y - headerHeight - handleOffset;
1605
+ const contentHeight = height - headerHeight;
1606
+ const newPercent = getNewPercent(contentHeight, scrollBarHeight, relativeY);
1607
+ const newDeltaY = newPercent * finalDeltaY;
1608
+ return setDeltaY(state, newDeltaY);
1173
1609
  };
1174
- const defaultLogError = () => {
1175
- // ignore
1610
+
1611
+ const handleWheel = (state, deltaMode, deltaY) => {
1612
+ number(deltaMode);
1613
+ number(deltaY);
1614
+ return setDeltaY(state, state.deltaY + deltaY);
1176
1615
  };
1177
- const defaultRequiresSocket = () => {
1178
- return false;
1616
+
1617
+ const handleError = async (error, notify = true, prefix = '') => {
1618
+ console.error(`[text-search-worker] ${error}`);
1179
1619
  };
1180
- const defaultResolve = resolve;
1181
- const handleJsonRpcMessage = async (...args) => {
1182
- let message;
1183
- let ipc;
1184
- let execute;
1185
- let preparePrettyError;
1186
- let logError;
1187
- let resolve;
1188
- let requiresSocket;
1189
- if (args.length === 1) {
1190
- const arg = args[0];
1191
- message = arg.message;
1192
- ipc = arg.ipc;
1193
- execute = arg.execute;
1194
- preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
1195
- logError = arg.logError || defaultLogError;
1196
- requiresSocket = arg.requiresSocket || defaultRequiresSocket;
1197
- resolve = arg.resolve || defaultResolve;
1198
- } else {
1199
- ipc = args[0];
1200
- message = args[1];
1201
- execute = args[2];
1202
- resolve = args[3];
1203
- preparePrettyError = args[4];
1204
- logError = args[5];
1205
- requiresSocket = args[6];
1206
- }
1207
- if ('id' in message) {
1208
- if ('method' in message) {
1209
- const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
1210
- try {
1211
- ipc.send(response);
1212
- } catch (error) {
1213
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
1214
- ipc.send(errorResponse);
1215
- }
1216
- return;
1620
+
1621
+ const getTextSearchResultCounts = results => {
1622
+ let resultCount = 0;
1623
+ let fileCount = 0;
1624
+ for (const result of results) {
1625
+ switch (result.type) {
1626
+ case File$1:
1627
+ fileCount++;
1628
+ break;
1629
+ case Match:
1630
+ resultCount++;
1631
+ break;
1217
1632
  }
1218
- resolve(message.id, message);
1219
- return;
1220
- }
1221
- if ('method' in message) {
1222
- await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
1223
- return;
1224
1633
  }
1225
- throw new JsonRpcError('unexpected message');
1226
- };
1227
- const invoke$2 = async (ipc, method, ...params) => {
1228
- const {
1229
- message,
1230
- promise
1231
- } = create$2(method, params);
1232
- ipc.send(message);
1233
- const responseMessage = await promise;
1234
- const result = unwrapJsonRpcResult(responseMessage);
1235
- return result;
1634
+ return {
1635
+ fileCount,
1636
+ resultCount
1637
+ };
1236
1638
  };
1237
1639
 
1238
- const invoke$1 = (method, ...params) => {
1239
- const ipc = get$1();
1240
- return invoke$2(ipc, method, ...params);
1640
+ const EmptyString = '';
1641
+
1642
+ const isEmptyString = string => {
1643
+ return string === EmptyString;
1241
1644
  };
1242
- const listen$2 = ipc => {
1243
- set$1(ipc);
1645
+
1646
+ const RE_PROTOCOL = /^([a-z\-]+):\/\//;
1647
+ const getProtocol = uri => {
1648
+ const protocolMatch = uri.match(RE_PROTOCOL);
1649
+ if (protocolMatch) {
1650
+ return protocolMatch[1];
1651
+ }
1652
+ return '';
1244
1653
  };
1245
1654
 
1246
1655
  const textSearch$5 = async (scheme, root, query) => {
@@ -1696,24 +2105,6 @@ const getDirectoryHandle = async uri => {
1696
2105
  return getDirectoryHandle(dirname$1);
1697
2106
  };
1698
2107
 
1699
- // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1700
-
1701
- const insertInto = (array, start, newItems) => {
1702
- const originalLength = array.length;
1703
- const newItemsLength = newItems.length;
1704
- array.length = originalLength + newItemsLength;
1705
- // Move the items after the start index, start from the end so that we don't overwrite any value.
1706
- for (let i = originalLength - 1; i >= start; i--) {
1707
- array[i + newItemsLength] = array[i];
1708
- }
1709
- for (let i = 0; i < newItemsLength; i++) {
1710
- array[i + start] = newItems[i];
1711
- }
1712
- };
1713
- const push = (array, newItems) => {
1714
- insertInto(array, array.length, newItems);
1715
- };
1716
-
1717
2108
  const NotReadableError = 'NotReadableError';
1718
2109
 
1719
2110
  const isNotReadableError = error => {
@@ -1882,8 +2273,8 @@ const textSearch = async (root, query, options, assetDir) => {
1882
2273
  };
1883
2274
 
1884
2275
  const getStatusMessage = (resultCount, fileResultCount) => {
1885
- number$1(resultCount);
1886
- number$1(fileResultCount);
2276
+ number(resultCount);
2277
+ number(fileResultCount);
1887
2278
  if (resultCount === 0) {
1888
2279
  return noResults();
1889
2280
  }
@@ -1997,7 +2388,7 @@ const getThreads = () => {
1997
2388
  return 1;
1998
2389
  };
1999
2390
  const loadContent = async (uid, savedState) => {
2000
- const state = get$2(uid);
2391
+ const state = get(uid);
2001
2392
  const savedValue = getSavedValue(savedState);
2002
2393
  const savedReplaceExpanded = getSavedReplaceExpanded(savedState);
2003
2394
  const savedCollapsedPaths = getSavedCollapsedPaths(savedState);
@@ -2019,6 +2410,10 @@ const loadContent = async (uid, savedState) => {
2019
2410
  };
2020
2411
  };
2021
2412
 
2413
+ const refresh = state => {
2414
+ return handleUpdate(state, {});
2415
+ };
2416
+
2022
2417
  const renderItems = {
2023
2418
  isEqual(oldState, newState) {
2024
2419
  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;
@@ -2050,7 +2445,7 @@ const renderFocus = {
2050
2445
  isEqual(oldState, newState) {
2051
2446
  return oldState.focus === newState.focus;
2052
2447
  },
2053
- apply(oldState, newState) {
2448
+ apply(newState) {
2054
2449
  const selector = getSelector(newState.focus);
2055
2450
  return ['setFocus', selector];
2056
2451
  }
@@ -2144,9 +2539,9 @@ const Keyboard = -1;
2144
2539
 
2145
2540
  const show = async (x, y, id, ...args) => {
2146
2541
  // TODO ask renderer worker to show context menu
2147
- number$1(x);
2148
- number$1(y);
2149
- number$1(id);
2542
+ number(x);
2543
+ number(y);
2544
+ number(id);
2150
2545
  // TODO
2151
2546
  };
2152
2547
 
@@ -2178,12 +2573,21 @@ const commandMap = {
2178
2573
  'SearchView.focusReplaceValue': focusReplaceValue$1,
2179
2574
  'SearchView.focusSearchValue': focusSearchValue$1,
2180
2575
  'SearchView.focusSearchValueNext': focusSearchValueNext$1,
2181
- 'TextSearch.create': create$4,
2576
+ 'TextSearch.clearSearchResults': clearSearchResults$1,
2577
+ 'TextSearch.copy': copy,
2578
+ 'TextSearch.create': create,
2182
2579
  'TextSearch.doRender': doRender,
2580
+ 'TextSearch.focusFirst': focusFirst,
2581
+ 'TextSearch.focusIndex': focusIndex,
2582
+ 'TextSearch.focusLast': focusLast,
2183
2583
  'TextSearch.focusMatchCase': focusMatchCase,
2184
2584
  'TextSearch.focusMatchCasePrevious': focusMatchCasePrevious,
2185
2585
  'TextSearch.focusMatchWholeWord': focusMatchWholeWord,
2586
+ 'TextSearch.focusNext': focusNext,
2587
+ 'TextSearch.focusNextPage': focusNextPage,
2186
2588
  'TextSearch.focusPreserveCase': focusPreserveCase,
2589
+ 'TextSearch.focusPrevious': focusPrevious,
2590
+ 'TextSearch.focusPreviousPage': focusPreviousPage,
2187
2591
  'TextSearch.focusRegex': focusRegex,
2188
2592
  'TextSearch.focusRegexNext': focusRegexNext,
2189
2593
  'TextSearch.focusReplaceAll': focusReplaceAll,
@@ -2195,9 +2599,15 @@ const commandMap = {
2195
2599
  'TextSearch.getActionsVirtualDom': getActionsVirtualDom,
2196
2600
  'TextSearch.getSearchDisplayResults': getDisplayResults,
2197
2601
  'TextSearch.getVirtualDom': getSearchVirtualDom,
2602
+ 'TextSearch.handleClickAt': handleClickAt,
2198
2603
  'TextSearch.handleContextMenu': handleContextMenu,
2199
2604
  'TextSearch.handleIconThemeChange': handleIconThemeChange,
2605
+ 'TextSearch.handleScrollBarCaptureLost': handleScrollBarCaptureLost,
2606
+ 'TextSearch.handleScrollBarClick': handleScrollBarClick,
2607
+ 'TextSearch.handleScrollBarMove': handleScrollBarMove,
2608
+ 'TextSearch.handleWheel': handleWheel,
2200
2609
  'TextSearch.loadContent': loadContent,
2610
+ 'TextSearch.refresh': refresh,
2201
2611
  'TextSearch.submit': submit,
2202
2612
  'TextSearch.textSearch': textSearch
2203
2613
  };