@lvce-editor/text-search-worker 2.2.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,142 +18,31 @@ const execute = (command, ...args) => {
18
18
  return fn(...args);
19
19
  };
20
20
 
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 => {
21
+ const clearSearchResults$1 = state => {
37
22
  return {
38
23
  ...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);
56
- }
57
- return focusMatchCase$1(state);
58
- };
59
-
60
- const CheckBox = 'checkbox';
61
- const None = 'none';
62
- const Status = 'status';
63
- const Tree = 'tree';
64
- const TreeItem$1 = 'treeitem';
65
- const ToolBar = 'toolbar';
66
-
67
- const Chevron = 'Chevron';
68
- const CloseMaskIcon = 'MaskIcon MaskIconClose';
69
- const Empty = '';
70
- const FileIcon = 'FileIcon';
71
- const IconButton = 'IconButton';
72
- const Actions = 'Actions';
73
- const FocusOutline = 'FocusOutline';
74
- const Highlight = 'Highlight';
75
- const HighlightDeleted = 'HighlightDeleted';
76
- const HighlightInserted = 'HighlightInserted';
77
- const Label = 'Label';
78
- const List = 'List';
79
- const MaskIcon = 'MaskIcon';
80
- const MaskIconChevronDown = 'MaskIconChevronDown';
81
- const MaskIconChevronRight = 'MaskIconChevronRight';
82
- const MultilineInputBox = 'MultilineInputBox';
83
- const Search = 'Search';
84
- const SearchField = 'SearchField';
85
- const SearchFieldButtons = 'SearchFieldButtons';
86
- const SearchFieldContainer = 'SearchFieldContainer';
87
- const SearchHeader = 'SearchHeader';
88
- const SearchHeaderTop = 'SearchHeaderTop';
89
- const SearchRemove = 'SearchRemove';
90
- const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
91
- const SourceControlBadge = 'SourceControlBadge';
92
- const TreeItem = 'TreeItem';
93
- const TreeItemActive = 'TreeItemActive';
94
- const Viewlet = 'Viewlet';
95
- const ViewletSearchMessage = 'ViewletSearchMessage';
96
-
97
- const Button$1 = 1;
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 getIconVirtualDom = (icon, type = Div) => {
110
- return {
111
- type,
112
- className: `MaskIcon MaskIcon${icon}`,
113
- role: None,
114
- childCount: 0
24
+ value: '',
25
+ items: [],
26
+ minLineY: 0,
27
+ maxLineY: 0,
28
+ message: ''
115
29
  };
116
30
  };
117
31
 
118
- const getActionButtonVirtualDom = action => {
119
- const {
120
- id,
121
- icon,
122
- command
123
- } = action;
124
- return [{
125
- type: Button,
126
- className: IconButton,
127
- title: id,
128
- 'data-command': command,
129
- childCount: 1
130
- }, getIconVirtualDom(icon)];
32
+ const state$3 = {
33
+ /**
34
+ * @type {any}
35
+ */
36
+ ipc: undefined
131
37
  };
132
-
133
- const getActionVirtualDom = action => {
134
- switch (action.type) {
135
- case Button$1:
136
- return getActionButtonVirtualDom(action);
137
- default:
138
- return [];
139
- }
38
+ const get$2 = () => {
39
+ return state$3.ipc;
140
40
  };
141
-
142
- const getActionsVirtualDom = actions => {
143
- return [{
144
- type: Div,
145
- className: Actions,
146
- role: ToolBar,
147
- childCount: actions.length
148
- }, ...actions.flatMap(getActionVirtualDom)];
41
+ const set$2 = ipc => {
42
+ state$3.ipc = ipc;
149
43
  };
150
44
 
151
- const ClearAll = 'ClearAll';
152
- const CollapseAll = 'CollapseAll';
153
- const ListFlat = 'ListFlat';
154
- const NewFile = 'NewFile';
155
- const Refresh = 'Refresh';
156
-
45
+ const Two = '2.0';
157
46
  let AssertionError$1 = class AssertionError extends Error {
158
47
  constructor(message) {
159
48
  super(message);
@@ -182,115 +71,734 @@ const getType$1 = value => {
182
71
  return 'unknown';
183
72
  }
184
73
  };
185
- const string = value => {
74
+ const number$1 = value => {
186
75
  const type = getType$1(value);
187
- if (type !== 'string') {
188
- throw new AssertionError$1('expected value to be of type string');
189
- }
190
- };
191
-
192
- const emptyObject = {};
193
- const RE_PLACEHOLDER = /\{(PH\d+)\}/g;
194
- const i18nString = (key, placeholders = emptyObject) => {
195
- if (placeholders === emptyObject) {
196
- return key;
76
+ if (type !== 'number') {
77
+ throw new AssertionError$1('expected value to be of type number');
197
78
  }
198
- const replacer = (match, rest) => {
199
- // @ts-ignore
200
- return placeholders[rest];
201
- };
202
- return key.replaceAll(RE_PLACEHOLDER, replacer);
203
- };
204
-
205
- /**
206
- * @enum {string}
207
- */
208
- const UiStrings = {
209
- NoResults: 'No results found',
210
- Oneresult: '1 result in 1 file',
211
- ManyResultsInOneFile: '{PH1} results in 1 file',
212
- ManyResultsInManyFiles: '{PH1} results in {PH2} files',
213
- ReplaceAll: 'Replace All',
214
- Replace: 'Replace',
215
- ConfirmReplaceAll: 'Replace All?',
216
- ConfirmReplaceOneOccurrenceInOneFile: "Replace 1 occurrence across 1 file with '{PH1}'",
217
- ConfirmReplaceOneOccurrenceInOneFileNoValue: 'Replace 1 occurrence across 1 file',
218
- ConfirmReplaceManyOccurrencesInOneFile: "Replace {PH1} occurrences across 1 file with '{PH2}'",
219
- ConfirmReplaceManyOccurrencesInOneFileNoValue: 'Replace {PH1} occurrences across 1 file',
220
- ConfirmReplaceManyOccurrencesInManyFiles: "Replace {PH1} occurrences across {PH2} files with '{PH3}'",
221
- ConfirmReplaceManyOccurrencesInManyFilesNoValue: 'Replace {PH1} occurrences across {PH2} files',
222
- ReplacedOneOccurrenceInOneFile: "Replaced 1 occurrence across 1 file with '{PH1}'",
223
- ReplacedManyOccurrencesInOneFile: "Replaced {PH1} occurrences across 1 file with '{PH2}'",
224
- ReplacedManyOccurrencesInManyFiles: "Replaced {PH1} occurrences across {PH2} files with '{PH3}'",
225
- CopyPath: 'Copy Path',
226
- Dismiss: 'Dismiss',
227
- Refresh: 'Refresh',
228
- ClearSearchResults: 'Clear Search Results',
229
- OpenNewSearchEditor: 'Open New Search Editor',
230
- ViewAsTree: 'View as Tree',
231
- CollapseAll: 'Collapse All'
232
79
  };
233
- const refresh = () => {
234
- return i18nString(UiStrings.Refresh);
80
+ const state$1 = {
81
+ callbacks: Object.create(null)
235
82
  };
236
- const clearSearchResults = () => {
237
- return i18nString(UiStrings.ClearSearchResults);
83
+ const set$1 = (id, fn) => {
84
+ state$1.callbacks[id] = fn;
238
85
  };
239
- const openNewSearchEditor = () => {
240
- return i18nString(UiStrings.OpenNewSearchEditor);
86
+ const get$1 = id => {
87
+ return state$1.callbacks[id];
241
88
  };
242
- const viewAsTree = () => {
243
- return i18nString(UiStrings.ViewAsTree);
89
+ const remove = id => {
90
+ delete state$1.callbacks[id];
244
91
  };
245
- const collapseAll = () => {
246
- return i18nString(UiStrings.CollapseAll);
92
+ const state$2 = {
93
+ id: 0
247
94
  };
248
-
249
- const getActions = () => {
250
- return [{
251
- type: Button$1,
252
- id: refresh(),
253
- icon: Refresh,
254
- command: 'refresh'
255
- }, {
256
- type: Button$1,
257
- id: clearSearchResults(),
258
- icon: ClearAll,
259
- command: 'clearSearchResults'
260
- }, {
261
- type: Button$1,
262
- id: openNewSearchEditor(),
263
- icon: NewFile,
264
- command: ''
265
- }, {
266
- type: Button$1,
267
- id: viewAsTree(),
268
- icon: ListFlat,
269
- command: ''
270
- }, {
271
- type: Button$1,
272
- id: collapseAll(),
273
- icon: CollapseAll,
274
- command: ''
275
- }];
95
+ const create$3 = () => {
96
+ return ++state$2.id;
276
97
  };
277
-
278
- const getFileIcon = () => {
279
- return '';
98
+ const warn = (...args) => {
99
+ console.warn(...args);
280
100
  };
281
-
282
- const File$1 = 1;
283
- const Match = 2;
284
-
285
- // TODO this should be in FileSystem module
286
- const pathBaseName = path => {
287
- return path.slice(path.lastIndexOf('/') + 1);
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
111
+ };
288
112
  };
289
- const getAbsolutePath = relativePath => {
290
- if (relativePath.startsWith('./')) {
291
- return `/${relativePath.slice(2)}`; // TODO support windows paths
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;
292
120
  }
293
- return `/${relativePath}`; // TODO support windows paths
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
+ */
699
+ const UiStrings = {
700
+ NoResults: 'No results found',
701
+ Oneresult: '1 result in 1 file',
702
+ ManyResultsInOneFile: '{PH1} results in 1 file',
703
+ ManyResultsInManyFiles: '{PH1} results in {PH2} files',
704
+ ReplaceAll: 'Replace All',
705
+ Replace: 'Replace',
706
+ ConfirmReplaceAll: 'Replace All?',
707
+ ConfirmReplaceOneOccurrenceInOneFile: "Replace 1 occurrence across 1 file with '{PH1}'",
708
+ ConfirmReplaceOneOccurrenceInOneFileNoValue: 'Replace 1 occurrence across 1 file',
709
+ ConfirmReplaceManyOccurrencesInOneFile: "Replace {PH1} occurrences across 1 file with '{PH2}'",
710
+ ConfirmReplaceManyOccurrencesInOneFileNoValue: 'Replace {PH1} occurrences across 1 file',
711
+ ConfirmReplaceManyOccurrencesInManyFiles: "Replace {PH1} occurrences across {PH2} files with '{PH3}'",
712
+ ConfirmReplaceManyOccurrencesInManyFilesNoValue: 'Replace {PH1} occurrences across {PH2} files',
713
+ ReplacedOneOccurrenceInOneFile: "Replaced 1 occurrence across 1 file with '{PH1}'",
714
+ ReplacedManyOccurrencesInOneFile: "Replaced {PH1} occurrences across 1 file with '{PH2}'",
715
+ ReplacedManyOccurrencesInManyFiles: "Replaced {PH1} occurrences across {PH2} files with '{PH3}'",
716
+ CopyPath: 'Copy Path',
717
+ Dismiss: 'Dismiss',
718
+ Refresh: 'Refresh',
719
+ ClearSearchResults: 'Clear Search Results',
720
+ OpenNewSearchEditor: 'Open New Search Editor',
721
+ ViewAsTree: 'View as Tree',
722
+ CollapseAll: 'Collapse All'
723
+ };
724
+ const noResults = () => {
725
+ return i18nString(UiStrings.NoResults);
726
+ };
727
+ const oneResult = () => {
728
+ return i18nString(UiStrings.Oneresult);
729
+ };
730
+ const manyResultsInOneFile = resultCount => {
731
+ return i18nString(UiStrings.ManyResultsInOneFile, {
732
+ PH1: resultCount
733
+ });
734
+ };
735
+ const manyResultsInManyFiles = (resultCount, fileResultCount) => {
736
+ return i18nString(UiStrings.ManyResultsInManyFiles, {
737
+ PH1: resultCount,
738
+ PH2: fileResultCount
739
+ });
740
+ };
741
+ const refresh$1 = () => {
742
+ return i18nString(UiStrings.Refresh);
743
+ };
744
+ const clearSearchResults = () => {
745
+ return i18nString(UiStrings.ClearSearchResults);
746
+ };
747
+ const openNewSearchEditor = () => {
748
+ return i18nString(UiStrings.OpenNewSearchEditor);
749
+ };
750
+ const viewAsTree = () => {
751
+ return i18nString(UiStrings.ViewAsTree);
752
+ };
753
+ const collapseAll = () => {
754
+ return i18nString(UiStrings.CollapseAll);
755
+ };
756
+
757
+ const getActions = () => {
758
+ return [{
759
+ type: Button$1,
760
+ id: refresh$1(),
761
+ icon: Refresh,
762
+ command: 'refresh'
763
+ }, {
764
+ type: Button$1,
765
+ id: clearSearchResults(),
766
+ icon: ClearAll,
767
+ command: 'clearSearchResults'
768
+ }, {
769
+ type: Button$1,
770
+ id: openNewSearchEditor(),
771
+ icon: NewFile,
772
+ command: ''
773
+ }, {
774
+ type: Button$1,
775
+ id: viewAsTree(),
776
+ icon: ListFlat,
777
+ command: ''
778
+ }, {
779
+ type: Button$1,
780
+ id: collapseAll(),
781
+ icon: CollapseAll,
782
+ command: ''
783
+ }];
784
+ };
785
+
786
+ const getFileIcon = () => {
787
+ return '';
788
+ };
789
+
790
+ const File$1 = 1;
791
+ const Match = 2;
792
+
793
+ // TODO this should be in FileSystem module
794
+ const pathBaseName = path => {
795
+ return path.slice(path.lastIndexOf('/') + 1);
796
+ };
797
+ const getAbsolutePath = relativePath => {
798
+ if (relativePath.startsWith('./')) {
799
+ return `/${relativePath.slice(2)}`; // TODO support windows paths
800
+ }
801
+ return `/${relativePath}`; // TODO support windows paths
294
802
  };
295
803
 
296
804
  const getDisplayResult = (result, itemHeight, i, setSize, searchTermLength, replacement, focusedIndex) => {
@@ -671,7 +1179,7 @@ const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWhol
671
1179
  const dom = [];
672
1180
  dom.push({
673
1181
  type: Div,
674
- className: mergeClassNames(Viewlet, Search),
1182
+ className: mergeClassNames(Viewlet, Search$1),
675
1183
  childCount: 2
676
1184
  });
677
1185
  dom.push(...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded));
@@ -680,464 +1188,461 @@ const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWhol
680
1188
  className: ViewletSearchMessage,
681
1189
  role: Status,
682
1190
  tabIndex: 0,
683
- childCount: 1
684
- }, text(message));
685
- dom.push({
686
- type: Div,
687
- className: mergeClassNames(Viewlet, List, focusOutline ? FocusOutline : Empty),
688
- role: Tree,
689
- tabIndex: 0,
690
- childCount: visibleItems.length,
691
- onClick: HandleClick,
692
- onBlur: HandleListBlur
693
- });
694
- dom.push(...getSearchResultsVirtualDom(visibleItems));
695
- return dom;
696
- };
697
-
698
- const state$3 = {
699
- /**
700
- * @type {any}
701
- */
702
- ipc: undefined
703
- };
704
- const get$1 = () => {
705
- return state$3.ipc;
706
- };
707
- const set$1 = ipc => {
708
- state$3.ipc = ipc;
709
- };
710
-
711
- const Two = '2.0';
712
- class AssertionError extends Error {
713
- constructor(message) {
714
- super(message);
715
- this.name = 'AssertionError';
716
- }
717
- }
718
- const getType = value => {
719
- switch (typeof value) {
720
- case 'number':
721
- return 'number';
722
- case 'function':
723
- return 'function';
724
- case 'string':
725
- return 'string';
726
- case 'object':
727
- if (value === null) {
728
- return 'null';
729
- }
730
- if (Array.isArray(value)) {
731
- return 'array';
732
- }
733
- return 'object';
734
- case 'boolean':
735
- return 'boolean';
736
- default:
737
- return 'unknown';
738
- }
739
- };
740
- const number = value => {
741
- const type = getType(value);
742
- if (type !== 'number') {
743
- throw new AssertionError('expected value to be of type number');
744
- }
745
- };
746
- const state$1 = {
747
- callbacks: Object.create(null)
748
- };
749
- const set = (id, fn) => {
750
- state$1.callbacks[id] = fn;
751
- };
752
- const get = id => {
753
- return state$1.callbacks[id];
754
- };
755
- const remove = id => {
756
- delete state$1.callbacks[id];
757
- };
758
- const state$2 = {
759
- id: 0
760
- };
761
- const create$3 = () => {
762
- return ++state$2.id;
763
- };
764
- const warn = (...args) => {
765
- console.warn(...args);
766
- };
767
- const registerPromise = () => {
768
- const id = create$3();
769
- const {
770
- resolve,
771
- promise
772
- } = Promise.withResolvers();
773
- set(id, resolve);
774
- return {
775
- id,
776
- promise
777
- };
778
- };
779
- const resolve = (id, args) => {
780
- number(id);
781
- const fn = get(id);
782
- if (!fn) {
783
- console.log(args);
784
- warn(`callback ${id} may already be disposed`);
785
- return;
786
- }
787
- fn(args);
788
- remove(id);
789
- };
790
- const create$2 = (method, params) => {
791
- const {
792
- id,
793
- promise
794
- } = registerPromise();
795
- const message = {
796
- jsonrpc: Two,
797
- method,
798
- params,
799
- id
800
- };
801
- return {
802
- message,
803
- promise
804
- };
805
- };
806
- class JsonRpcError extends Error {
807
- constructor(message) {
808
- super(message);
809
- this.name = 'JsonRpcError';
810
- }
811
- }
812
- const NewLine$3 = '\n';
813
- const DomException = 'DOMException';
814
- const ReferenceError$1 = 'ReferenceError';
815
- const SyntaxError$1 = 'SyntaxError';
816
- const TypeError$1 = 'TypeError';
817
- const getErrorConstructor = (message, type) => {
818
- if (type) {
819
- switch (type) {
820
- case DomException:
821
- return DOMException;
822
- case TypeError$1:
823
- return TypeError;
824
- case SyntaxError$1:
825
- return SyntaxError;
826
- case ReferenceError$1:
827
- return ReferenceError;
828
- default:
829
- return Error;
830
- }
831
- }
832
- if (message.startsWith('TypeError: ')) {
833
- return TypeError;
834
- }
835
- if (message.startsWith('SyntaxError: ')) {
836
- return SyntaxError;
837
- }
838
- if (message.startsWith('ReferenceError: ')) {
839
- return ReferenceError;
840
- }
841
- return Error;
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;
842
1204
  };
843
- const constructError = (message, type, name) => {
844
- const ErrorConstructor = getErrorConstructor(message, type);
845
- if (ErrorConstructor === DOMException && name) {
846
- return new ErrorConstructor(message, name);
847
- }
848
- if (ErrorConstructor === Error) {
849
- const error = new Error(message);
850
- if (name && name !== 'VError') {
851
- error.name = name;
852
- }
853
- return error;
854
- }
855
- return new ErrorConstructor(message);
1205
+
1206
+ const handleIconThemeChange = state => {
1207
+ const {
1208
+ items
1209
+ } = state;
1210
+ const newItems = [...items];
1211
+ return {
1212
+ ...state,
1213
+ items: newItems
1214
+ };
856
1215
  };
857
- const getNewLineIndex$2 = (string, startIndex = undefined) => {
858
- return string.indexOf(NewLine$3, startIndex);
1216
+
1217
+ const first = () => {
1218
+ return 0;
859
1219
  };
860
- const getParentStack = error => {
861
- let parentStack = error.stack || error.data || error.message || '';
862
- if (parentStack.startsWith(' at')) {
863
- parentStack = error.message + NewLine$3 + parentStack;
864
- }
865
- return parentStack;
1220
+ const last = items => {
1221
+ return items.length - 1;
866
1222
  };
867
- const joinLines$1 = lines => {
868
- return lines.join(NewLine$3);
1223
+ const next = (items, index) => {
1224
+ return (index + 1) % items.length;
869
1225
  };
870
- const MethodNotFound = -32601;
871
- const Custom = -32001;
872
- const splitLines$2 = lines => {
873
- return lines.split(NewLine$3);
1226
+ const previous = (items, index) => {
1227
+ return index === 0 ? items.length - 1 : index - 1;
874
1228
  };
875
- const restoreJsonRpcError = error => {
876
- if (error && error instanceof Error) {
877
- return error;
878
- }
879
- const currentStack = joinLines$1(splitLines$2(new Error().stack || '').slice(1));
880
- if (error && error.code && error.code === MethodNotFound) {
881
- const restoredError = new JsonRpcError(error.message);
882
- const parentStack = getParentStack(error);
883
- restoredError.stack = parentStack + NewLine$3 + currentStack;
884
- return restoredError;
885
- }
886
- if (error && error.message) {
887
- const restoredError = constructError(error.message, error.type, error.name);
888
- if (error.data) {
889
- if (error.data.stack && error.data.type && error.message) {
890
- restoredError.stack = error.data.type + ': ' + error.message + NewLine$3 + error.data.stack + NewLine$3 + currentStack;
891
- } else if (error.data.stack) {
892
- restoredError.stack = error.data.stack;
893
- }
894
- if (error.data.codeFrame) {
895
- // @ts-ignore
896
- restoredError.codeFrame = error.data.codeFrame;
897
- }
898
- if (error.data.code) {
899
- // @ts-ignore
900
- restoredError.code = error.data.code;
901
- }
902
- if (error.data.type) {
903
- // @ts-ignore
904
- restoredError.name = error.data.type;
905
- }
906
- } else {
907
- if (error.stack) {
908
- const lowerStack = restoredError.stack || '';
909
- // @ts-ignore
910
- const indexNewLine = getNewLineIndex$2(lowerStack);
911
- const parentStack = getParentStack(error);
912
- // @ts-ignore
913
- restoredError.stack = parentStack + lowerStack.slice(indexNewLine);
914
- }
915
- if (error.codeFrame) {
916
- // @ts-ignore
917
- restoredError.codeFrame = error.codeFrame;
918
- }
919
- }
920
- return restoredError;
921
- }
922
- if (typeof error === 'string') {
923
- return new Error(`JsonRpc Error: ${error}`);
924
- }
925
- return new Error(`JsonRpc Error: ${error}`);
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;
926
1235
  };
927
- const unwrapJsonRpcResult = responseMessage => {
928
- if ('error' in responseMessage) {
929
- const restoredError = restoreJsonRpcError(responseMessage.error);
930
- throw restoredError;
931
- }
932
- if ('result' in responseMessage) {
933
- return responseMessage.result;
934
- }
935
- throw new JsonRpcError('unexpected response message');
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;
1242
+ return {
1243
+ ...state,
1244
+ focusedIndex: index,
1245
+ minLineY: newMinLineY,
1246
+ maxLineY: newMaxLineY,
1247
+ focused: true,
1248
+ deltaY: newDeltaY
1249
+ };
936
1250
  };
937
- const E_COMMAND_NOT_FOUND = 'E_COMMAND_NOT_FOUND';
938
- const getErrorType = prettyError => {
939
- if (prettyError && prettyError.type) {
940
- return prettyError.type;
941
- }
942
- if (prettyError && prettyError.constructor && prettyError.constructor.name) {
943
- return prettyError.constructor.name;
944
- }
945
- return undefined;
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;
1256
+ return {
1257
+ ...state,
1258
+ focusedIndex: index,
1259
+ minLineY: newMinLineY,
1260
+ maxLineY: newMaxLineY,
1261
+ focused: true,
1262
+ deltaY: newDeltaY
1263
+ };
946
1264
  };
947
- const getErrorProperty = (error, prettyError) => {
948
- if (error && error.code === E_COMMAND_NOT_FOUND) {
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;
1277
+ }
1278
+ number(itemHeight);
1279
+ if (index === -1) {
949
1280
  return {
950
- code: MethodNotFound,
951
- message: error.message,
952
- data: error.stack
1281
+ ...state,
1282
+ focusedIndex: -1,
1283
+ focused: true
953
1284
  };
954
1285
  }
1286
+ const listHeight = height - headerHeight;
1287
+ if (index < minLineY + 1) {
1288
+ return focusIndexScrollUp(state, index, listHeight, itemHeight, itemsLength);
1289
+ }
1290
+ if (index >= maxLineY - 1) {
1291
+ return focusIndexScrollDown(state, index, listHeight, itemHeight, itemsLength);
1292
+ }
955
1293
  return {
956
- code: Custom,
957
- message: prettyError.message,
958
- data: {
959
- stack: prettyError.stack,
960
- codeFrame: prettyError.codeFrame,
961
- type: getErrorType(prettyError),
962
- code: prettyError.code,
963
- name: prettyError.name
964
- }
965
- };
966
- };
967
- const create$1 = (message, error) => {
968
- return {
969
- jsonrpc: Two,
970
- id: message.id,
971
- error
1294
+ ...state,
1295
+ focusedIndex: index,
1296
+ focused: true
972
1297
  };
973
1298
  };
974
- const getErrorResponse = (message, error, preparePrettyError, logError) => {
975
- const prettyError = preparePrettyError(error);
976
- logError(error, prettyError);
977
- const errorProperty = getErrorProperty(error, prettyError);
978
- return create$1(message, errorProperty);
1299
+
1300
+ const focusFirst = state => {
1301
+ const firstIndex = first();
1302
+ return focusIndex(state, firstIndex);
979
1303
  };
980
- const create = (message, result) => {
981
- return {
982
- jsonrpc: Two,
983
- id: message.id,
984
- result: result ?? null
985
- };
1304
+
1305
+ const focusLast = state => {
1306
+ const {
1307
+ items
1308
+ } = state;
1309
+ const lastIndex = last(items);
1310
+ return focusIndex(state, lastIndex);
986
1311
  };
987
- const getSuccessResponse = (message, result) => {
988
- const resultProperty = result ?? null;
989
- return create(message, resultProperty);
1312
+
1313
+ const focusNext = state => {
1314
+ const {
1315
+ focusedIndex,
1316
+ items
1317
+ } = state;
1318
+ const nextIndex = next(items, focusedIndex);
1319
+ return focusIndex(state, nextIndex);
990
1320
  };
991
- const getResponse = async (message, ipc, execute, preparePrettyError, logError, requiresSocket) => {
992
- try {
993
- const result = requiresSocket(message.method) ? await execute(message.method, ipc, ...message.params) : await execute(message.method, ...message.params);
994
- return getSuccessResponse(message, result);
995
- } catch (error) {
996
- return getErrorResponse(message, error, preparePrettyError, logError);
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];
997
1334
  }
998
1335
  };
999
- const defaultPreparePrettyError = error => {
1000
- return error;
1336
+ const push = (array, newItems) => {
1337
+ insertInto(array, array.length, newItems);
1001
1338
  };
1002
- const defaultLogError = () => {
1003
- // ignore
1339
+ const isLastIndex = (array, index) => {
1340
+ return index === array.length - 1;
1004
1341
  };
1005
- const defaultRequiresSocket = () => {
1006
- return false;
1342
+ const lastIndex = array => {
1343
+ return array.length - 1;
1007
1344
  };
1008
- const defaultResolve = resolve;
1009
- const handleJsonRpcMessage = async (...args) => {
1010
- let message;
1011
- let ipc;
1012
- let execute;
1013
- let preparePrettyError;
1014
- let logError;
1015
- let resolve;
1016
- let requiresSocket;
1017
- if (args.length === 1) {
1018
- const arg = args[0];
1019
- message = arg.message;
1020
- ipc = arg.ipc;
1021
- execute = arg.execute;
1022
- preparePrettyError = arg.preparePrettyError || defaultPreparePrettyError;
1023
- logError = arg.logError || defaultLogError;
1024
- requiresSocket = arg.requiresSocket || defaultRequiresSocket;
1025
- resolve = arg.resolve || defaultResolve;
1026
- } else {
1027
- ipc = args[0];
1028
- message = args[1];
1029
- execute = args[2];
1030
- resolve = args[3];
1031
- preparePrettyError = args[4];
1032
- logError = args[5];
1033
- requiresSocket = args[6];
1034
- }
1035
- if ('id' in message) {
1036
- if ('method' in message) {
1037
- const response = await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
1038
- try {
1039
- ipc.send(response);
1040
- } catch (error) {
1041
- const errorResponse = getErrorResponse(message, error, preparePrettyError, logError);
1042
- ipc.send(errorResponse);
1043
- }
1044
- return;
1045
- }
1046
- resolve(message.id, message);
1047
- return;
1048
- }
1049
- if ('method' in message) {
1050
- await getResponse(message, ipc, execute, preparePrettyError, logError, requiresSocket);
1051
- return;
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;
1052
1355
  }
1053
- throw new JsonRpcError('unexpected message');
1356
+ const indexNextPage = Math.min(maxLineY + (maxLineY - minLineY) - 2, lastIndex(items));
1357
+ return focusIndex(state, indexNextPage);
1054
1358
  };
1055
- const invoke$2 = async (ipc, method, ...params) => {
1359
+
1360
+ const focusPreviousPage = state => {
1056
1361
  const {
1057
- message,
1058
- promise
1059
- } = create$2(method, params);
1060
- ipc.send(message);
1061
- const responseMessage = await promise;
1062
- const result = unwrapJsonRpcResult(responseMessage);
1063
- return result;
1362
+ focusedIndex,
1363
+ minLineY,
1364
+ maxLineY
1365
+ } = state;
1366
+ if (focusedIndex === 0 || focusedIndex === -1) {
1367
+ return state;
1368
+ }
1369
+ const indexPreviousPage = Math.max(minLineY - (maxLineY - minLineY) + 1, 0);
1370
+ return focusIndex(state, indexPreviousPage);
1371
+ };
1372
+
1373
+ const focusPrevious = state => {
1374
+ const {
1375
+ focusedIndex,
1376
+ items
1377
+ } = state;
1378
+ if (focusedIndex === 0 || focusedIndex === -1) {
1379
+ return state;
1380
+ }
1381
+ const previousIndex = previous(items, focusedIndex);
1382
+ return focusIndex(state, previousIndex);
1064
1383
  };
1065
1384
 
1066
- const invoke$1 = (method, ...params) => {
1067
- const ipc = get$1();
1068
- return invoke$2(ipc, method, ...params);
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;
1069
1389
  };
1070
- const listen$2 = ipc => {
1071
- set$1(ipc);
1390
+
1391
+ const openUri = async (path, focus = true, props = {}) => {
1392
+ await invoke$1(/* Main.openUri */'Main.openUri', /* uri */path, /* focus */focus, props);
1072
1393
  };
1073
1394
 
1074
- const focusSearchValue = state => {
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
+ }
1401
+ }
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);
1075
1410
  return {
1076
1411
  ...state,
1077
- focus: FocusSearchInput
1412
+ collapsedPaths: [...collapsedPaths, path],
1413
+ listFocusedIndex: index,
1414
+ listFocused: true
1078
1415
  };
1079
1416
  };
1080
- const focusSearchValueNext = state => {
1417
+ const selectIndexPreview = async (state, searchResult, index) => {
1081
1418
  const {
1082
- replaceExpanded
1419
+ items
1083
1420
  } = state;
1084
- if (replaceExpanded) {
1085
- return focusReplaceValue(state);
1421
+ const fileIndex = getFileIndex(items, index);
1422
+ if (fileIndex === -1) {
1423
+ throw new Error('Search result is missing file');
1086
1424
  }
1087
- return focusMatchCase(state);
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
+ };
1088
1440
  };
1089
- const focusMatchCasePrevious = state => {
1441
+ const selectIndex = async (state, index, isClose) => {
1442
+ if (index === -1) {
1443
+ return {
1444
+ ...state,
1445
+ listFocused: true,
1446
+ listFocusedIndex: -1
1447
+ };
1448
+ }
1090
1449
  const {
1091
- replaceExpanded
1450
+ items
1092
1451
  } = state;
1093
- if (replaceExpanded) {
1094
- return focusReplaceValue(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}`);
1095
1460
  }
1096
- return focusSearchValue(state);
1097
- };
1098
- const focusReplaceValueNext = state => {
1099
- return focusMatchCase(state);
1100
1461
  };
1101
- const focusRegexNext = state => {
1102
- return focusPreserveCase(state);
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);
1103
1472
  };
1104
- const focusReplaceValue = state => {
1473
+
1474
+ const handleScrollBarCaptureLost = state => {
1105
1475
  return {
1106
1476
  ...state,
1107
- focus: FocusSearchReplaceInput
1477
+ scrollBarActive: false
1108
1478
  };
1109
1479
  };
1110
- const focusMatchCase = state => {
1111
- return {
1112
- ...state,
1113
- focus: FocusSearchMatchCase
1114
- };
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);
1115
1493
  };
1116
- const focusPreserveCase = state => {
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
1117
1516
  return {
1118
- ...state,
1119
- focus: FocusSearchPreserveCase
1517
+ percent: 1,
1518
+ handleOffset: scrollBarHeight - height + relativeY
1120
1519
  };
1121
1520
  };
1122
- const focusMatchWholeWord = state => {
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);
1527
+ };
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);
1123
1547
  return {
1124
1548
  ...state,
1125
- focus: FocusSearchWholeWord
1549
+ deltaY: newDeltaY,
1550
+ minLineY,
1551
+ maxLineY
1126
1552
  };
1127
1553
  };
1128
- const focusRegex = state => {
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;
1129
1580
  return {
1130
- ...state,
1131
- focus: FocusSearchRegex
1581
+ ...setDeltaY(state, newDeltaY),
1582
+ handleOffset,
1583
+ scrollBarActive: true
1132
1584
  };
1133
1585
  };
1134
- const focusReplaceAll = state => {
1586
+
1587
+ const getNewPercent = (contentHeight, scrollBarHeight, relativeY) => {
1588
+ if (relativeY <= contentHeight - scrollBarHeight / 2) {
1589
+ // clicked in middle
1590
+ return relativeY / (contentHeight - scrollBarHeight);
1591
+ }
1592
+ // clicked at bottom
1593
+ return 1;
1594
+ };
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);
1609
+ };
1610
+
1611
+ const handleWheel = (state, deltaMode, deltaY) => {
1612
+ number(deltaMode);
1613
+ number(deltaY);
1614
+ return setDeltaY(state, state.deltaY + deltaY);
1615
+ };
1616
+
1617
+ const handleError = async (error, notify = true, prefix = '') => {
1618
+ console.error(`[text-search-worker] ${error}`);
1619
+ };
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;
1632
+ }
1633
+ }
1135
1634
  return {
1136
- ...state,
1137
- focus: FocusSearchReplaceAll
1635
+ fileCount,
1636
+ resultCount
1138
1637
  };
1139
1638
  };
1140
1639
 
1640
+ const EmptyString = '';
1641
+
1642
+ const isEmptyString = string => {
1643
+ return string === EmptyString;
1644
+ };
1645
+
1141
1646
  const RE_PROTOCOL = /^([a-z\-]+):\/\//;
1142
1647
  const getProtocol = uri => {
1143
1648
  const protocolMatch = uri.match(RE_PROTOCOL);
@@ -1600,24 +2105,6 @@ const getDirectoryHandle = async uri => {
1600
2105
  return getDirectoryHandle(dirname$1);
1601
2106
  };
1602
2107
 
1603
- // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1604
-
1605
- const insertInto = (array, start, newItems) => {
1606
- const originalLength = array.length;
1607
- const newItemsLength = newItems.length;
1608
- array.length = originalLength + newItemsLength;
1609
- // Move the items after the start index, start from the end so that we don't overwrite any value.
1610
- for (let i = originalLength - 1; i >= start; i--) {
1611
- array[i + newItemsLength] = array[i];
1612
- }
1613
- for (let i = 0; i < newItemsLength; i++) {
1614
- array[i + start] = newItems[i];
1615
- }
1616
- };
1617
- const push = (array, newItems) => {
1618
- insertInto(array, array.length, newItems);
1619
- };
1620
-
1621
2108
  const NotReadableError = 'NotReadableError';
1622
2109
 
1623
2110
  const isNotReadableError = error => {
@@ -1785,15 +2272,322 @@ const textSearch = async (root, query, options, assetDir) => {
1785
2272
  return results;
1786
2273
  };
1787
2274
 
2275
+ const getStatusMessage = (resultCount, fileResultCount) => {
2276
+ number(resultCount);
2277
+ number(fileResultCount);
2278
+ if (resultCount === 0) {
2279
+ return noResults();
2280
+ }
2281
+ if (resultCount === 1) {
2282
+ return oneResult();
2283
+ }
2284
+ if (fileResultCount === 1) {
2285
+ return manyResultsInOneFile(resultCount);
2286
+ }
2287
+ return manyResultsInManyFiles(resultCount, fileResultCount);
2288
+ };
2289
+
2290
+ const handleUpdate = async (state, update) => {
2291
+ const partialNewState = {
2292
+ ...state,
2293
+ ...update
2294
+ };
2295
+ try {
2296
+ const {
2297
+ height,
2298
+ itemHeight,
2299
+ minimumSliderSize,
2300
+ headerHeight,
2301
+ matchCase,
2302
+ value,
2303
+ threads,
2304
+ useRegularExpression
2305
+ } = partialNewState;
2306
+ if (isEmptyString(value)) {
2307
+ return {
2308
+ ...partialNewState,
2309
+ minLineY: 0,
2310
+ maxLineY: 0,
2311
+ deltaY: 0,
2312
+ items: [],
2313
+ matchIndex: 0,
2314
+ matchCount: 0,
2315
+ message: '',
2316
+ loaded: true
2317
+ };
2318
+ }
2319
+ const root = state.workspacePath;
2320
+ const results = await textSearch(root, value, {
2321
+ threads,
2322
+ isCaseSensitive: matchCase,
2323
+ useRegularExpression
2324
+ }, state.assetDir);
2325
+ if (!Array.isArray(results)) {
2326
+ throw new TypeError('results must be of type array');
2327
+ }
2328
+ const {
2329
+ fileCount,
2330
+ resultCount
2331
+ } = getTextSearchResultCounts(results);
2332
+ const message = getStatusMessage(resultCount, fileCount);
2333
+ const total = results.length;
2334
+ const contentHeight = total * itemHeight;
2335
+ const listHeight = height - headerHeight;
2336
+ const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
2337
+ const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
2338
+ const maxLineY = Math.min(numberOfVisible, total);
2339
+ const finalDeltaY = Math.max(contentHeight - listHeight, 0);
2340
+ return {
2341
+ ...partialNewState,
2342
+ minLineY: 0,
2343
+ deltaY: 0,
2344
+ value,
2345
+ items: results,
2346
+ message,
2347
+ maxLineY: maxLineY,
2348
+ scrollBarHeight,
2349
+ finalDeltaY,
2350
+ threads,
2351
+ fileCount,
2352
+ matchCount: resultCount,
2353
+ loaded: true
2354
+ };
2355
+ } catch (error) {
2356
+ handleError(error);
2357
+ return {
2358
+ ...partialNewState,
2359
+ message: `${error}`,
2360
+ items: [],
2361
+ matchCount: 0,
2362
+ fileCount: 0,
2363
+ minLineY: 0,
2364
+ maxLineY: 0
2365
+ };
2366
+ }
2367
+ };
2368
+
2369
+ const getSavedValue = savedState => {
2370
+ if (savedState && savedState.value) {
2371
+ return savedState.value;
2372
+ }
2373
+ return '';
2374
+ };
2375
+ const getSavedReplaceExpanded = savedState => {
2376
+ if (savedState && 'replaceExpanded' in savedState) {
2377
+ return savedState.replaceExpanded;
2378
+ }
2379
+ return false;
2380
+ };
2381
+ const getSavedCollapsedPaths = savedState => {
2382
+ if (savedState && 'collapsedPaths' in savedState && Array.isArray(savedState.collapsedPaths) && savedState.collapsedPaths.every(path => typeof path === 'string')) {
2383
+ return savedState.collapsedPaths;
2384
+ }
2385
+ return [];
2386
+ };
2387
+ const getThreads = () => {
2388
+ return 1;
2389
+ };
2390
+ const loadContent = async (uid, savedState) => {
2391
+ const state = get(uid);
2392
+ const savedValue = getSavedValue(savedState);
2393
+ const savedReplaceExpanded = getSavedReplaceExpanded(savedState);
2394
+ const savedCollapsedPaths = getSavedCollapsedPaths(savedState);
2395
+ const threads = getThreads();
2396
+ if (savedValue) {
2397
+ return handleUpdate(state, {
2398
+ value: savedValue,
2399
+ threads,
2400
+ replaceExpanded: savedReplaceExpanded,
2401
+ inputSource: Script,
2402
+ collapsedPaths: savedCollapsedPaths
2403
+ });
2404
+ }
2405
+ return {
2406
+ ...state,
2407
+ threads,
2408
+ replaceExpanded: savedReplaceExpanded,
2409
+ loaded: true
2410
+ };
2411
+ };
2412
+
2413
+ const refresh = state => {
2414
+ return handleUpdate(state, {});
2415
+ };
2416
+
2417
+ const renderItems = {
2418
+ isEqual(oldState, newState) {
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;
2420
+ },
2421
+ apply(oldState, newState) {
2422
+ const displayResults = getDisplayResults(newState.items, newState.itemHeight, newState.fileCount, newState.value, newState.minLineY, newState.maxLineY, newState.replacement, newState.collapsedPaths, newState.focusedIndex);
2423
+ const focusOutline = newState.listFocused && newState.listFocusedIndex === -1;
2424
+ const dom = getSearchVirtualDom(displayResults, newState.replaceExpanded, newState.matchCase, newState.matchWholeWord, newState.useRegularExpression, newState.message, newState.detailsExpanded, focusOutline);
2425
+ return ['Viewlet.setDom2', dom];
2426
+ }
2427
+ };
2428
+ const getSelector = focusKey => {
2429
+ switch (focusKey) {
2430
+ case FocusSearchInput:
2431
+ return '[name="search-value"]';
2432
+ case FocusSearchReplaceInput:
2433
+ return '[name="search-replace-value"]';
2434
+ case FocusSearchMatchCase:
2435
+ return '[title="Match Case"]';
2436
+ case FocusSearchPreserveCase:
2437
+ return '[title="Preserve Case"]';
2438
+ case FocusSearchRegex:
2439
+ return '[title="Use Regular Expression"]';
2440
+ default:
2441
+ return '';
2442
+ }
2443
+ };
2444
+ const renderFocus = {
2445
+ isEqual(oldState, newState) {
2446
+ return oldState.focus === newState.focus;
2447
+ },
2448
+ apply(newState) {
2449
+ const selector = getSelector(newState.focus);
2450
+ return ['setFocus', selector];
2451
+ }
2452
+ };
2453
+ const render = [renderItems, renderFocus];
2454
+ const doRender = (oldState, newState) => {
2455
+ const commands = [];
2456
+ for (const fn of render) {
2457
+ if (!fn.isEqual(oldState, newState)) {
2458
+ commands.push(fn.apply(oldState, newState));
2459
+ }
2460
+ }
2461
+ return commands;
2462
+ };
2463
+
2464
+ const focusSearchValue = state => {
2465
+ return {
2466
+ ...state,
2467
+ focus: FocusSearchInput
2468
+ };
2469
+ };
2470
+ const focusSearchValueNext = state => {
2471
+ const {
2472
+ replaceExpanded
2473
+ } = state;
2474
+ if (replaceExpanded) {
2475
+ return focusReplaceValue(state);
2476
+ }
2477
+ return focusMatchCase(state);
2478
+ };
2479
+ const focusMatchCasePrevious = state => {
2480
+ const {
2481
+ replaceExpanded
2482
+ } = state;
2483
+ if (replaceExpanded) {
2484
+ return focusReplaceValue(state);
2485
+ }
2486
+ return focusSearchValue(state);
2487
+ };
2488
+ const focusReplaceValueNext = state => {
2489
+ return focusMatchCase(state);
2490
+ };
2491
+ const focusRegexNext = state => {
2492
+ return focusPreserveCase(state);
2493
+ };
2494
+ const focusReplaceValue = state => {
2495
+ return {
2496
+ ...state,
2497
+ focus: FocusSearchReplaceInput
2498
+ };
2499
+ };
2500
+ const focusMatchCase = state => {
2501
+ return {
2502
+ ...state,
2503
+ focus: FocusSearchMatchCase
2504
+ };
2505
+ };
2506
+ const focusPreserveCase = state => {
2507
+ return {
2508
+ ...state,
2509
+ focus: FocusSearchPreserveCase
2510
+ };
2511
+ };
2512
+ const focusMatchWholeWord = state => {
2513
+ return {
2514
+ ...state,
2515
+ focus: FocusSearchWholeWord
2516
+ };
2517
+ };
2518
+ const focusRegex = state => {
2519
+ return {
2520
+ ...state,
2521
+ focus: FocusSearchRegex
2522
+ };
2523
+ };
2524
+ const focusReplaceAll = state => {
2525
+ return {
2526
+ ...state,
2527
+ focus: FocusSearchReplaceAll
2528
+ };
2529
+ };
2530
+
2531
+ const submit = state => {
2532
+ return handleUpdate(state, {
2533
+ value: state.value,
2534
+ inputSource: User
2535
+ });
2536
+ };
2537
+
2538
+ const Keyboard = -1;
2539
+
2540
+ const show = async (x, y, id, ...args) => {
2541
+ // TODO ask renderer worker to show context menu
2542
+ number(x);
2543
+ number(y);
2544
+ number(id);
2545
+ // TODO
2546
+ };
2547
+
2548
+ const Search = 18;
2549
+
2550
+ const handleContextMenuKeyboard = async state => {
2551
+ const x = state.x; // TODO
2552
+ const y = state.y; // TODO
2553
+ await show(x, y, Search);
2554
+ return state;
2555
+ };
2556
+
2557
+ const handleContextMenuMouseAt = async (state, x, y) => {
2558
+ await show(x, y, Search);
2559
+ return state;
2560
+ };
2561
+
2562
+ const handleContextMenu = (state, button, x, y) => {
2563
+ switch (button) {
2564
+ case Keyboard:
2565
+ return handleContextMenuKeyboard(state);
2566
+ default:
2567
+ return handleContextMenuMouseAt(state, x, y);
2568
+ }
2569
+ };
2570
+
1788
2571
  const commandMap = {
1789
2572
  'SearchView.focusMatchCase': focusMatchCase$1,
1790
2573
  'SearchView.focusReplaceValue': focusReplaceValue$1,
1791
2574
  'SearchView.focusSearchValue': focusSearchValue$1,
1792
2575
  'SearchView.focusSearchValueNext': focusSearchValueNext$1,
2576
+ 'TextSearch.clearSearchResults': clearSearchResults$1,
2577
+ 'TextSearch.copy': copy,
2578
+ 'TextSearch.create': create,
2579
+ 'TextSearch.doRender': doRender,
2580
+ 'TextSearch.focusFirst': focusFirst,
2581
+ 'TextSearch.focusIndex': focusIndex,
2582
+ 'TextSearch.focusLast': focusLast,
1793
2583
  'TextSearch.focusMatchCase': focusMatchCase,
1794
2584
  'TextSearch.focusMatchCasePrevious': focusMatchCasePrevious,
1795
2585
  'TextSearch.focusMatchWholeWord': focusMatchWholeWord,
2586
+ 'TextSearch.focusNext': focusNext,
2587
+ 'TextSearch.focusNextPage': focusNextPage,
1796
2588
  'TextSearch.focusPreserveCase': focusPreserveCase,
2589
+ 'TextSearch.focusPrevious': focusPrevious,
2590
+ 'TextSearch.focusPreviousPage': focusPreviousPage,
1797
2591
  'TextSearch.focusRegex': focusRegex,
1798
2592
  'TextSearch.focusRegexNext': focusRegexNext,
1799
2593
  'TextSearch.focusReplaceAll': focusReplaceAll,
@@ -1805,6 +2599,16 @@ const commandMap = {
1805
2599
  'TextSearch.getActionsVirtualDom': getActionsVirtualDom,
1806
2600
  'TextSearch.getSearchDisplayResults': getDisplayResults,
1807
2601
  'TextSearch.getVirtualDom': getSearchVirtualDom,
2602
+ 'TextSearch.handleClickAt': handleClickAt,
2603
+ 'TextSearch.handleContextMenu': handleContextMenu,
2604
+ 'TextSearch.handleIconThemeChange': handleIconThemeChange,
2605
+ 'TextSearch.handleScrollBarCaptureLost': handleScrollBarCaptureLost,
2606
+ 'TextSearch.handleScrollBarClick': handleScrollBarClick,
2607
+ 'TextSearch.handleScrollBarMove': handleScrollBarMove,
2608
+ 'TextSearch.handleWheel': handleWheel,
2609
+ 'TextSearch.loadContent': loadContent,
2610
+ 'TextSearch.refresh': refresh,
2611
+ 'TextSearch.submit': submit,
1808
2612
  'TextSearch.textSearch': textSearch
1809
2613
  };
1810
2614