@lvce-editor/text-search-worker 2.7.0 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/textSearchWorkerMain.js +135 -9
- package/package.json +1 -1
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
const commands = Object.create(null);
|
|
2
|
-
const registerCommand = (key, fn) => {
|
|
3
|
-
commands[key] = fn;
|
|
4
|
-
};
|
|
5
2
|
const register = commandMap => {
|
|
6
|
-
|
|
7
|
-
registerCommand(key, value);
|
|
8
|
-
}
|
|
3
|
+
Object.assign(commands, commandMap);
|
|
9
4
|
};
|
|
10
5
|
const getCommand = key => {
|
|
11
6
|
return commands[key];
|
|
@@ -468,7 +463,7 @@ const FocusSearchWholeWord = 34;
|
|
|
468
463
|
const FocusSearchReplaceAll = 35;
|
|
469
464
|
const FocusSearchPreserveCase = 36;
|
|
470
465
|
|
|
471
|
-
const create = (uid, x, y, width, height, workspacePath) => {
|
|
466
|
+
const create = (uid, x, y, width, height, workspacePath, assetDir) => {
|
|
472
467
|
const state = {
|
|
473
468
|
uid,
|
|
474
469
|
searchResults: [],
|
|
@@ -505,7 +500,7 @@ const create = (uid, x, y, width, height, workspacePath) => {
|
|
|
505
500
|
message: '',
|
|
506
501
|
collapsedPaths: [],
|
|
507
502
|
icons: [],
|
|
508
|
-
assetDir
|
|
503
|
+
assetDir,
|
|
509
504
|
deltaY: 0,
|
|
510
505
|
finalDeltaY: 0,
|
|
511
506
|
focused: false,
|
|
@@ -585,6 +580,12 @@ const number = value => {
|
|
|
585
580
|
throw new AssertionError('expected value to be of type number');
|
|
586
581
|
}
|
|
587
582
|
};
|
|
583
|
+
const array = value => {
|
|
584
|
+
const type = getType(value);
|
|
585
|
+
if (type !== 'array') {
|
|
586
|
+
throw new AssertionError('expected value to be of type array');
|
|
587
|
+
}
|
|
588
|
+
};
|
|
588
589
|
const string = value => {
|
|
589
590
|
const type = getType(value);
|
|
590
591
|
if (type !== 'string') {
|
|
@@ -650,6 +651,49 @@ const manyResultsInManyFiles = (resultCount, fileResultCount) => {
|
|
|
650
651
|
PH2: fileResultCount
|
|
651
652
|
});
|
|
652
653
|
};
|
|
654
|
+
const confirmReplaceOneOccurrenceInOneFile = replacement => {
|
|
655
|
+
return i18nString(UiStrings.ConfirmReplaceOneOccurrenceInOneFile, {
|
|
656
|
+
PH1: replacement
|
|
657
|
+
});
|
|
658
|
+
};
|
|
659
|
+
const confirmReplaceOneOccurrenceInOneFileNoValue = () => {
|
|
660
|
+
return i18nString(UiStrings.ConfirmReplaceOneOccurrenceInOneFileNoValue);
|
|
661
|
+
};
|
|
662
|
+
const confirmReplaceManyOccurrencesInOneFile = (matchCount, replacement) => {
|
|
663
|
+
return i18nString(UiStrings.ConfirmReplaceManyOccurrencesInOneFile, {
|
|
664
|
+
PH1: matchCount,
|
|
665
|
+
PH2: replacement
|
|
666
|
+
});
|
|
667
|
+
};
|
|
668
|
+
const confirmReplaceManyOccurrencesInOneFileNoValue = matchCount => {
|
|
669
|
+
return i18nString(UiStrings.ConfirmReplaceManyOccurrencesInOneFileNoValue, {
|
|
670
|
+
PH1: matchCount
|
|
671
|
+
});
|
|
672
|
+
};
|
|
673
|
+
const confirmReplaceManyOccurrencesInManyFiles = (matchCount, fileCount, replacement) => {
|
|
674
|
+
number(matchCount);
|
|
675
|
+
number(fileCount);
|
|
676
|
+
string(replacement);
|
|
677
|
+
return i18nString(UiStrings.ConfirmReplaceManyOccurrencesInManyFiles, {
|
|
678
|
+
PH1: matchCount,
|
|
679
|
+
PH2: fileCount,
|
|
680
|
+
PH3: replacement
|
|
681
|
+
});
|
|
682
|
+
};
|
|
683
|
+
const confirmReplaceManyOccurrencesInManyFilesNoValue = (matchCount, fileCount) => {
|
|
684
|
+
number(matchCount);
|
|
685
|
+
number(fileCount);
|
|
686
|
+
return i18nString(UiStrings.ConfirmReplaceManyOccurrencesInManyFilesNoValue, {
|
|
687
|
+
PH1: matchCount,
|
|
688
|
+
PH2: fileCount
|
|
689
|
+
});
|
|
690
|
+
};
|
|
691
|
+
const replaceAll$1 = () => {
|
|
692
|
+
return i18nString(UiStrings.ReplaceAll);
|
|
693
|
+
};
|
|
694
|
+
const replace = () => {
|
|
695
|
+
return i18nString(UiStrings.Replace);
|
|
696
|
+
};
|
|
653
697
|
const refresh$1 = () => {
|
|
654
698
|
return i18nString(UiStrings.Refresh);
|
|
655
699
|
};
|
|
@@ -2630,6 +2674,86 @@ const doRender = uid => {
|
|
|
2630
2674
|
return commands;
|
|
2631
2675
|
};
|
|
2632
2676
|
|
|
2677
|
+
const getReplaceAllConfirmText = (matchCount, fileCount, replacement) => {
|
|
2678
|
+
if (matchCount === 1) {
|
|
2679
|
+
if (replacement) {
|
|
2680
|
+
return confirmReplaceOneOccurrenceInOneFile(replacement);
|
|
2681
|
+
}
|
|
2682
|
+
return confirmReplaceOneOccurrenceInOneFileNoValue();
|
|
2683
|
+
}
|
|
2684
|
+
if (fileCount === 1) {
|
|
2685
|
+
if (replacement) {
|
|
2686
|
+
return confirmReplaceManyOccurrencesInOneFile(matchCount, replacement);
|
|
2687
|
+
}
|
|
2688
|
+
return confirmReplaceManyOccurrencesInOneFileNoValue(matchCount);
|
|
2689
|
+
}
|
|
2690
|
+
if (replacement) {
|
|
2691
|
+
return confirmReplaceManyOccurrencesInManyFiles(matchCount, fileCount, replacement);
|
|
2692
|
+
}
|
|
2693
|
+
return confirmReplaceManyOccurrencesInManyFilesNoValue(matchCount, fileCount);
|
|
2694
|
+
};
|
|
2695
|
+
|
|
2696
|
+
const replaceAllAndPrompt = async (workspacePath, items, replacement, matchCount, fileCount) => {
|
|
2697
|
+
string(workspacePath);
|
|
2698
|
+
array(items);
|
|
2699
|
+
string(replacement);
|
|
2700
|
+
number(matchCount);
|
|
2701
|
+
number(fileCount);
|
|
2702
|
+
const confirmTitle = replaceAll$1();
|
|
2703
|
+
const confirmAccept = replace();
|
|
2704
|
+
const confirmText = getReplaceAllConfirmText(matchCount, fileCount, replacement);
|
|
2705
|
+
const shouldReplace = await execute('ConfirmPrompt.prompt', confirmText, {
|
|
2706
|
+
title: confirmTitle,
|
|
2707
|
+
confirmMessage: confirmAccept
|
|
2708
|
+
});
|
|
2709
|
+
if (!shouldReplace) {
|
|
2710
|
+
return false;
|
|
2711
|
+
}
|
|
2712
|
+
// TODO
|
|
2713
|
+
// await TextSearchReplaceAll.replaceAll(workspacePath, items, replacement)
|
|
2714
|
+
return true;
|
|
2715
|
+
};
|
|
2716
|
+
|
|
2717
|
+
const getBulkReplacementEdits = (workspacePath, matches) => {
|
|
2718
|
+
string(workspacePath);
|
|
2719
|
+
array(matches);
|
|
2720
|
+
const files = [];
|
|
2721
|
+
const ranges = [];
|
|
2722
|
+
let currentRanges = [];
|
|
2723
|
+
for (const match of matches) {
|
|
2724
|
+
const {
|
|
2725
|
+
type,
|
|
2726
|
+
text
|
|
2727
|
+
} = match;
|
|
2728
|
+
switch (type) {
|
|
2729
|
+
case File$1:
|
|
2730
|
+
ranges.push(currentRanges.length);
|
|
2731
|
+
push(ranges, currentRanges);
|
|
2732
|
+
const absolutePath = `${workspacePath}/${text.slice(2)}`;
|
|
2733
|
+
files.push(absolutePath); // TODO
|
|
2734
|
+
currentRanges = [];
|
|
2735
|
+
break;
|
|
2736
|
+
case Match:
|
|
2737
|
+
currentRanges.push(match.lineNumber - 1, match.matchStart, match.lineNumber - 1, match.matchStart + match.matchLength);
|
|
2738
|
+
break;
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
ranges.push(currentRanges.length);
|
|
2742
|
+
push(ranges, currentRanges);
|
|
2743
|
+
return {
|
|
2744
|
+
files,
|
|
2745
|
+
ranges: ranges.slice(1)
|
|
2746
|
+
};
|
|
2747
|
+
};
|
|
2748
|
+
|
|
2749
|
+
const replaceAll = async (workspacePath, items, replacement) => {
|
|
2750
|
+
const {
|
|
2751
|
+
files,
|
|
2752
|
+
ranges
|
|
2753
|
+
} = getBulkReplacementEdits(workspacePath, items);
|
|
2754
|
+
await invoke$1('BulkReplacement.applyBulkReplacement', files, ranges, replacement);
|
|
2755
|
+
};
|
|
2756
|
+
|
|
2633
2757
|
const saveState = uid => {
|
|
2634
2758
|
const {
|
|
2635
2759
|
newState
|
|
@@ -2802,7 +2926,6 @@ const wrapCommand = fn => {
|
|
|
2802
2926
|
const commandMap = {
|
|
2803
2927
|
'TextSearch.clearSearchResults': wrapCommand(clearSearchResults$1),
|
|
2804
2928
|
'TextSearch.copy': wrapCommand(copy),
|
|
2805
|
-
'TextSearch.handleInput': wrapCommand(handleInput),
|
|
2806
2929
|
'TextSearch.dismissItem': wrapCommand(dismissItem),
|
|
2807
2930
|
'TextSearch.focusFirst': wrapCommand(focusFirst),
|
|
2808
2931
|
'TextSearch.focusIndex': wrapCommand(focusIndex),
|
|
@@ -2830,12 +2953,15 @@ const commandMap = {
|
|
|
2830
2953
|
'TextSearch.handleContextMenu': wrapCommand(handleContextMenu),
|
|
2831
2954
|
'TextSearch.handleFocusIn': wrapCommand(handleFocusIn),
|
|
2832
2955
|
'TextSearch.handleIconThemeChange': wrapCommand(handleIconThemeChange),
|
|
2956
|
+
'TextSearch.handleInput': wrapCommand(handleInput),
|
|
2833
2957
|
'TextSearch.handleScrollBarCaptureLost': wrapCommand(handleScrollBarCaptureLost),
|
|
2834
2958
|
'TextSearch.handleScrollBarClick': wrapCommand(handleScrollBarClick),
|
|
2835
2959
|
'TextSearch.handleScrollBarMove': wrapCommand(handleScrollBarMove),
|
|
2836
2960
|
'TextSearch.handleWheel': wrapCommand(handleWheel),
|
|
2837
2961
|
'TextSearch.loadContent': wrapCommand(loadContent),
|
|
2838
2962
|
'TextSearch.refresh': wrapCommand(refresh),
|
|
2963
|
+
'TextSearch.replaceAllAndPrompt': wrapCommand(replaceAllAndPrompt),
|
|
2964
|
+
'TextSearch.replaceAll': wrapCommand(replaceAll),
|
|
2839
2965
|
'TextSearch.submit': wrapCommand(submit),
|
|
2840
2966
|
'TextSearch.toggleReplace': wrapCommand(toggleReplace),
|
|
2841
2967
|
// not wrapped
|