@lvce-editor/text-search-view 1.12.2 → 1.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/textSearchViewMain.js +99 -45
- package/package.json +1 -1
|
@@ -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
|
|
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
|
|
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
|
|
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
|
}
|
|
@@ -6791,9 +6824,11 @@ const getActionButtonVirtualDom = action => {
|
|
|
6791
6824
|
label
|
|
6792
6825
|
} = action;
|
|
6793
6826
|
const className = getClassName(enabled);
|
|
6827
|
+
const disabled = !enabled;
|
|
6794
6828
|
return [{
|
|
6795
6829
|
childCount: 1,
|
|
6796
6830
|
className,
|
|
6831
|
+
disabled,
|
|
6797
6832
|
name: id,
|
|
6798
6833
|
title: label,
|
|
6799
6834
|
type: Button$2
|
|
@@ -6827,20 +6862,23 @@ const Refresh = 'Refresh';
|
|
|
6827
6862
|
|
|
6828
6863
|
const getActions = state => {
|
|
6829
6864
|
const {
|
|
6865
|
+
items,
|
|
6830
6866
|
replacement,
|
|
6831
6867
|
value
|
|
6832
6868
|
} = state;
|
|
6833
|
-
const
|
|
6869
|
+
const hasSearchPattern = value !== '';
|
|
6870
|
+
const hasSearchResults = items.length > 0;
|
|
6871
|
+
const canClear = hasSearchResults || hasSearchPattern || replacement !== '';
|
|
6834
6872
|
return [{
|
|
6835
6873
|
command: 'refresh',
|
|
6836
|
-
enabled:
|
|
6874
|
+
enabled: hasSearchPattern,
|
|
6837
6875
|
icon: Refresh,
|
|
6838
6876
|
id: Refresh$1,
|
|
6839
6877
|
label: refresh$1(),
|
|
6840
6878
|
type: Button
|
|
6841
6879
|
}, {
|
|
6842
6880
|
command: 'clearSearchResults',
|
|
6843
|
-
enabled:
|
|
6881
|
+
enabled: canClear,
|
|
6844
6882
|
icon: ClearAll,
|
|
6845
6883
|
id: ClearAll$1,
|
|
6846
6884
|
label: clearSearchResults(),
|
|
@@ -6854,14 +6892,14 @@ const getActions = state => {
|
|
|
6854
6892
|
type: Button
|
|
6855
6893
|
}, {
|
|
6856
6894
|
command: '',
|
|
6857
|
-
enabled:
|
|
6895
|
+
enabled: hasSearchResults,
|
|
6858
6896
|
icon: ListFlat,
|
|
6859
6897
|
id: ViewAsTree,
|
|
6860
6898
|
label: viewAsTree$1(),
|
|
6861
6899
|
type: Button
|
|
6862
6900
|
}, {
|
|
6863
6901
|
command: '',
|
|
6864
|
-
enabled:
|
|
6902
|
+
enabled: hasSearchResults,
|
|
6865
6903
|
icon: CollapseAll,
|
|
6866
6904
|
id: CollapseAll$1,
|
|
6867
6905
|
label: collapseAll(),
|
|
@@ -6963,6 +7001,19 @@ const rerender = state => {
|
|
|
6963
7001
|
};
|
|
6964
7002
|
};
|
|
6965
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
|
+
|
|
6966
7017
|
const saveState = state => {
|
|
6967
7018
|
const {
|
|
6968
7019
|
collapsedPaths,
|
|
@@ -7083,13 +7134,15 @@ const Keyboard = -1;
|
|
|
7083
7134
|
|
|
7084
7135
|
const handleContextMenuKeyboard = async state => {
|
|
7085
7136
|
const {
|
|
7137
|
+
focusedIndex,
|
|
7138
|
+
listFocusedIndex,
|
|
7086
7139
|
uid,
|
|
7087
7140
|
x,
|
|
7088
7141
|
y
|
|
7089
|
-
} = state;
|
|
7142
|
+
} = state;
|
|
7143
|
+
const index = focusedIndex === -1 ? listFocusedIndex : focusedIndex;
|
|
7090
7144
|
await show2(uid, Search$1, x, y, {
|
|
7091
|
-
index
|
|
7092
|
-
// TODO pass proper index
|
|
7145
|
+
index,
|
|
7093
7146
|
menuId: Search$1
|
|
7094
7147
|
});
|
|
7095
7148
|
return state;
|
|
@@ -7234,6 +7287,7 @@ const commandMap = {
|
|
|
7234
7287
|
'TextSearch.replaceAllInFile': wrapCommand(replaceAllInFile),
|
|
7235
7288
|
'TextSearch.rerender': rerender,
|
|
7236
7289
|
'TextSearch.restoreState': restoreState,
|
|
7290
|
+
'TextSearch.revealInExplorer': wrapCommand(revealInExplorer),
|
|
7237
7291
|
'TextSearch.saveState': wrapGetter(saveState),
|
|
7238
7292
|
'TextSearch.selectIndex': wrapCommand(selectIndex),
|
|
7239
7293
|
'TextSearch.setLimit': wrapCommand(setLimit),
|