@lvce-editor/text-search-view 1.13.0 → 1.14.1

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.
@@ -6,5 +6,14 @@
6
6
  "id": "search.exclude",
7
7
  "type": 4,
8
8
  "value": {}
9
+ },
10
+ {
11
+ "category": "features",
12
+ "description": "Controls the number of worker threads used for search",
13
+ "heading": "Search Threads",
14
+ "id": "search.threads",
15
+ "minimum": 1,
16
+ "type": 5,
17
+ "value": 1
9
18
  }
10
19
  ]
@@ -2813,6 +2813,7 @@ const PreserveCase$1 = 'Preserve Case';
2813
2813
  const Refresh$2 = 'Refresh';
2814
2814
  const Replace = 'Replace';
2815
2815
  const ReplaceAll$1 = 'Replace All';
2816
+ const RevealInExplorerView = 'Reveal in Explorer View';
2816
2817
  const ReplacingManyOccurrencesInManyFiles = 'Replacing {PH1} occurrences across {PH2} files…';
2817
2818
  const ReplacingManyOccurrencesInOneFile = 'Replacing {PH1} occurrences across 1 file…';
2818
2819
  const ReplacingOneOccurrenceInOneFile = 'Replacing 1 occurrence across 1 file…';
@@ -2967,6 +2968,9 @@ const copyPath = () => {
2967
2968
  const copyAll = () => {
2968
2969
  return i18nString(CopyAll);
2969
2970
  };
2971
+ const revealInExplorerView = () => {
2972
+ return i18nString(RevealInExplorerView);
2973
+ };
2970
2974
  const refresh$1 = () => {
2971
2975
  return i18nString(Refresh$2);
2972
2976
  };
@@ -3410,7 +3414,52 @@ const getMenuEntriesInput = options => {
3410
3414
  }];
3411
3415
  };
3412
3416
 
3417
+ const getFileIndex$1 = (items, index) => {
3418
+ for (let i = index; i >= 0; i--) {
3419
+ const item = items[i];
3420
+ if (item.type === File) {
3421
+ return i;
3422
+ }
3423
+ }
3424
+ return -1;
3425
+ };
3426
+
3427
+ // TODO this should be in FileSystem module
3428
+ const pathBaseName = path => {
3429
+ return path.slice(path.lastIndexOf('/') + 1);
3430
+ };
3431
+ const getRelativePath = relativePath => {
3432
+ if (relativePath.startsWith('./')) {
3433
+ return `/${relativePath.slice(2)}`; // TODO support windows paths
3434
+ }
3435
+ return `/${relativePath}`; // TODO support windows paths
3436
+ };
3437
+ const getRelativeFolderPath = relativePath => {
3438
+ const normalized = relativePath.startsWith('./') ? relativePath.slice(2) : relativePath;
3439
+ const slashIndex = normalized.lastIndexOf('/');
3440
+ if (slashIndex === -1) {
3441
+ return '';
3442
+ }
3443
+ return normalized.slice(0, slashIndex);
3444
+ };
3445
+
3446
+ const getFileUri = (state, index) => {
3447
+ const {
3448
+ items,
3449
+ workspacePath
3450
+ } = state;
3451
+ if (index < 0 || index >= items.length) {
3452
+ return '';
3453
+ }
3454
+ const fileIndex = getFileIndex$1(items, index);
3455
+ if (fileIndex === -1) {
3456
+ return '';
3457
+ }
3458
+ return `${workspacePath}${getRelativePath(items[fileIndex].text)}`;
3459
+ };
3460
+
3413
3461
  const getMenuEntriesFile = (state, props) => {
3462
+ const uri = getFileUri(state, props.index);
3414
3463
  return [{
3415
3464
  command: 'Search.replaceAll',
3416
3465
  flags: None$1,
@@ -3421,7 +3470,7 @@ const getMenuEntriesFile = (state, props) => {
3421
3470
  flags: None$1,
3422
3471
  id: 'dismiss',
3423
3472
  label: dismiss()
3424
- }, {
3473
+ }, menuEntrySeparator, {
3425
3474
  command: 'Search.copy',
3426
3475
  flags: None$1,
3427
3476
  id: 'copy',
@@ -3436,16 +3485,23 @@ const getMenuEntriesFile = (state, props) => {
3436
3485
  flags: None$1,
3437
3486
  id: 'copyAll',
3438
3487
  label: copyAll()
3488
+ }, menuEntrySeparator, {
3489
+ args: [uri],
3490
+ command: 'Search.revealInExplorer',
3491
+ flags: None$1,
3492
+ id: 'revealInExplorerView',
3493
+ label: revealInExplorerView()
3439
3494
  }];
3440
3495
  };
3441
3496
 
3442
3497
  const getMenuEntriesMatch = (state, props) => {
3498
+ const uri = getFileUri(state, props.index);
3443
3499
  return [{
3444
3500
  command: 'Search.removeCurrent',
3445
3501
  flags: None$1,
3446
3502
  id: 'dismiss',
3447
3503
  label: dismiss()
3448
- }, {
3504
+ }, menuEntrySeparator, {
3449
3505
  command: 'Search.copy',
3450
3506
  flags: None$1,
3451
3507
  id: 'copy',
@@ -3455,6 +3511,12 @@ const getMenuEntriesMatch = (state, props) => {
3455
3511
  flags: None$1,
3456
3512
  id: 'copyAll',
3457
3513
  label: copyAll()
3514
+ }, menuEntrySeparator, {
3515
+ args: [uri],
3516
+ command: 'Search.revealInExplorer',
3517
+ flags: None$1,
3518
+ id: 'revealInExplorerView',
3519
+ label: revealInExplorerView()
3458
3520
  }];
3459
3521
  };
3460
3522
 
@@ -3470,10 +3532,10 @@ const getMenuEntriesList = (state, props) => {
3470
3532
  return [];
3471
3533
  }
3472
3534
  if (item.type === Match$1) {
3473
- return getMenuEntriesMatch();
3535
+ return getMenuEntriesMatch(state, props);
3474
3536
  }
3475
3537
  if (item.type === File$1) {
3476
- return getMenuEntriesFile();
3538
+ return getMenuEntriesFile(state, props);
3477
3539
  }
3478
3540
  return [];
3479
3541
  };
@@ -4160,7 +4222,7 @@ const getActualIndex = state => {
4160
4222
  } = state;
4161
4223
  return focusedIndex === -1 ? listFocusedIndex : focusedIndex;
4162
4224
  };
4163
- const getFileIndex$1 = (state, actualIndex) => {
4225
+ const getFileIndex = (state, actualIndex) => {
4164
4226
  const {
4165
4227
  items
4166
4228
  } = state;
@@ -4290,7 +4352,7 @@ const replaceAllConfirmed = async (state, fileIndex) => {
4290
4352
  };
4291
4353
  const replaceAll = async state => {
4292
4354
  const actualIndex = getActualIndex(state);
4293
- const fileIndex = getFileIndex$1(state, actualIndex);
4355
+ const fileIndex = getFileIndex(state, actualIndex);
4294
4356
  const shouldReplace = await confirmReplaceAll(state, fileIndex);
4295
4357
  if (!shouldReplace) {
4296
4358
  return state;
@@ -4304,7 +4366,7 @@ const replaceAllWithProgress = async context => {
4304
4366
  matchCount: totalMatchCount
4305
4367
  } = state;
4306
4368
  const actualIndex = getActualIndex(state);
4307
- const fileIndex = getFileIndex$1(state, actualIndex);
4369
+ const fileIndex = getFileIndex(state, actualIndex);
4308
4370
  const fileCount = fileIndex === -1 ? totalFileCount : 1;
4309
4371
  const matchCount = fileIndex === -1 ? totalMatchCount : Math.max(getFileItems(state, fileIndex).length - 1, 0);
4310
4372
  const shouldReplace = await confirmReplaceAll(state, fileIndex);
@@ -5347,41 +5409,12 @@ const selectIndexFile = async (state, searchResult, index) => {
5347
5409
  return applyCollapsedPaths(state, newCollapsedPaths, index);
5348
5410
  };
5349
5411
 
5350
- const getFileIndex = (items, index) => {
5351
- for (let i = index; i >= 0; i--) {
5352
- const item = items[i];
5353
- if (item.type === File) {
5354
- return i;
5355
- }
5356
- }
5357
- return -1;
5358
- };
5359
-
5360
- // TODO this should be in FileSystem module
5361
- const pathBaseName = path => {
5362
- return path.slice(path.lastIndexOf('/') + 1);
5363
- };
5364
- const getRelativePath = relativePath => {
5365
- if (relativePath.startsWith('./')) {
5366
- return `/${relativePath.slice(2)}`; // TODO support windows paths
5367
- }
5368
- return `/${relativePath}`; // TODO support windows paths
5369
- };
5370
- const getRelativeFolderPath = relativePath => {
5371
- const normalized = relativePath.startsWith('./') ? relativePath.slice(2) : relativePath;
5372
- const slashIndex = normalized.lastIndexOf('/');
5373
- if (slashIndex === -1) {
5374
- return '';
5375
- }
5376
- return normalized.slice(0, slashIndex);
5377
- };
5378
-
5379
5412
  const selectIndexPreview = async (state, searchResult, index) => {
5380
5413
  const {
5381
5414
  listItems,
5382
5415
  workspacePath
5383
5416
  } = state;
5384
- const fileIndex = getFileIndex(listItems, index);
5417
+ const fileIndex = getFileIndex$1(listItems, index);
5385
5418
  if (fileIndex === -1) {
5386
5419
  throw new Error('Search result is missing file');
5387
5420
  }
@@ -6968,6 +7001,19 @@ const rerender = state => {
6968
7001
  };
6969
7002
  };
6970
7003
 
7004
+ const revealInExplorerActual = async uri => {
7005
+ await invoke$2('SideBar.show', 'Explorer');
7006
+ const states = await invoke$2('Viewlet.getAllStates');
7007
+ const viewlets = Object.values(states);
7008
+ const sideBar = viewlets.find(viewlet => viewlet.currentViewletId === 'Explorer');
7009
+ const explorerUid = Math.max(...viewlets.filter(viewlet => viewlet.parentUid === sideBar.uid).map(viewlet => viewlet.uid));
7010
+ await invoke$2('Viewlet.executeViewletCommand', explorerUid, 'reveal', uri);
7011
+ };
7012
+ const revealInExplorer = async (state, uri) => {
7013
+ await revealInExplorerActual(uri);
7014
+ return state;
7015
+ };
7016
+
6971
7017
  const saveState = state => {
6972
7018
  const {
6973
7019
  collapsedPaths,
@@ -7088,13 +7134,15 @@ const Keyboard = -1;
7088
7134
 
7089
7135
  const handleContextMenuKeyboard = async state => {
7090
7136
  const {
7137
+ focusedIndex,
7138
+ listFocusedIndex,
7091
7139
  uid,
7092
7140
  x,
7093
7141
  y
7094
- } = state; // TODO
7142
+ } = state;
7143
+ const index = focusedIndex === -1 ? listFocusedIndex : focusedIndex;
7095
7144
  await show2(uid, Search$1, x, y, {
7096
- index: 0,
7097
- // TODO pass proper index
7145
+ index,
7098
7146
  menuId: Search$1
7099
7147
  });
7100
7148
  return state;
@@ -7239,6 +7287,7 @@ const commandMap = {
7239
7287
  'TextSearch.replaceAllInFile': wrapCommand(replaceAllInFile),
7240
7288
  'TextSearch.rerender': rerender,
7241
7289
  'TextSearch.restoreState': restoreState,
7290
+ 'TextSearch.revealInExplorer': wrapCommand(revealInExplorer),
7242
7291
  'TextSearch.saveState': wrapGetter(saveState),
7243
7292
  'TextSearch.selectIndex': wrapCommand(selectIndex),
7244
7293
  'TextSearch.setLimit': wrapCommand(setLimit),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-view",
3
- "version": "1.13.0",
3
+ "version": "1.14.1",
4
4
  "description": "Text Search View",
5
5
  "keywords": [
6
6
  "text-search"