@lvce-editor/text-search-worker 3.2.0 → 3.3.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 +122 -95
- package/package.json +1 -1
|
@@ -958,11 +958,15 @@ const isLastIndex = (array, index) => {
|
|
|
958
958
|
const lastIndex = array => {
|
|
959
959
|
return array.length - 1;
|
|
960
960
|
};
|
|
961
|
-
const toSpliced = (array, index, deleteCount, ...inserted) => {
|
|
962
|
-
return [...array.slice(0, index), ...inserted, ...array.slice(index + deleteCount)];
|
|
963
|
-
};
|
|
964
961
|
const remove = (array, index, deleteCount) => {
|
|
965
|
-
return toSpliced(
|
|
962
|
+
return array.toSpliced(index, deleteCount);
|
|
963
|
+
};
|
|
964
|
+
const fromAsync = async asyncIterable => {
|
|
965
|
+
const children = [];
|
|
966
|
+
for await (const value of asyncIterable) {
|
|
967
|
+
children.push(value);
|
|
968
|
+
}
|
|
969
|
+
return children;
|
|
966
970
|
};
|
|
967
971
|
|
|
968
972
|
class AssertionError extends Error {
|
|
@@ -1035,33 +1039,34 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
1035
1039
|
* @enum {string}
|
|
1036
1040
|
*/
|
|
1037
1041
|
const UiStrings = {
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
ManyResultsInOneFile: '{PH1} results in 1 file',
|
|
1041
|
-
ManyResultsInManyFiles: '{PH1} results in {PH2} files',
|
|
1042
|
-
ReplaceAll: 'Replace All',
|
|
1043
|
-
Replace: 'Replace',
|
|
1042
|
+
ClearSearchResults: 'Clear Search Results',
|
|
1043
|
+
CollapseAll: 'Collapse All',
|
|
1044
1044
|
ConfirmReplaceAll: 'Replace All?',
|
|
1045
|
-
ConfirmReplaceOneOccurrenceInOneFile: "Replace 1 occurrence across 1 file with '{PH1}'",
|
|
1046
|
-
ConfirmReplaceOneOccurrenceInOneFileNoValue: 'Replace 1 occurrence across 1 file',
|
|
1047
|
-
ConfirmReplaceManyOccurrencesInOneFile: "Replace {PH1} occurrences across 1 file with '{PH2}'",
|
|
1048
|
-
ConfirmReplaceManyOccurrencesInOneFileNoValue: 'Replace {PH1} occurrences across 1 file',
|
|
1049
1045
|
ConfirmReplaceManyOccurrencesInManyFiles: "Replace {PH1} occurrences across {PH2} files with '{PH3}'",
|
|
1050
1046
|
ConfirmReplaceManyOccurrencesInManyFilesNoValue: 'Replace {PH1} occurrences across {PH2} files',
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1047
|
+
ConfirmReplaceManyOccurrencesInOneFile: "Replace {PH1} occurrences across 1 file with '{PH2}'",
|
|
1048
|
+
ConfirmReplaceManyOccurrencesInOneFileNoValue: 'Replace {PH1} occurrences across 1 file',
|
|
1049
|
+
ConfirmReplaceOneOccurrenceInOneFile: "Replace 1 occurrence across 1 file with '{PH1}'",
|
|
1050
|
+
ConfirmReplaceOneOccurrenceInOneFileNoValue: 'Replace 1 occurrence across 1 file',
|
|
1054
1051
|
CopyPath: 'Copy Path',
|
|
1055
1052
|
Dismiss: 'Dismiss',
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
OpenNewSearchEditor: 'Open New Search Editor',
|
|
1059
|
-
ViewAsTree: 'View as Tree',
|
|
1060
|
-
CollapseAll: 'Collapse All',
|
|
1061
|
-
ToggleReplace: 'Toggle Replace',
|
|
1053
|
+
ManyResultsInManyFiles: '{PH1} results in {PH2} files',
|
|
1054
|
+
ManyResultsInOneFile: '{PH1} results in 1 file',
|
|
1062
1055
|
MatchCase: 'Match Case',
|
|
1063
1056
|
MatchWholeWord: 'Match Whole Word',
|
|
1064
|
-
|
|
1057
|
+
NoResults: 'No results found',
|
|
1058
|
+
Oneresult: '1 result in 1 file',
|
|
1059
|
+
OpenNewSearchEditor: 'Open New Search Editor',
|
|
1060
|
+
PreserveCase: 'Preserve Case',
|
|
1061
|
+
Refresh: 'Refresh',
|
|
1062
|
+
Replace: 'Replace',
|
|
1063
|
+
ReplaceAll: 'Replace All',
|
|
1064
|
+
ReplacedManyOccurrencesInManyFiles: "Replaced {PH1} occurrences across {PH2} files with '{PH3}'",
|
|
1065
|
+
ReplacedManyOccurrencesInOneFile: "Replaced {PH1} occurrences across 1 file with '{PH2}'",
|
|
1066
|
+
ReplacedOneOccurrenceInOneFile: "Replaced 1 occurrence across 1 file with '{PH1}'",
|
|
1067
|
+
ToggleReplace: 'Toggle Replace',
|
|
1068
|
+
UseRegularExpression: 'Use Regular Expression',
|
|
1069
|
+
ViewAsTree: 'View as Tree'
|
|
1065
1070
|
};
|
|
1066
1071
|
const noResults = () => {
|
|
1067
1072
|
return i18nString(UiStrings.NoResults);
|
|
@@ -1075,6 +1080,9 @@ const toggleReplace$1 = () => {
|
|
|
1075
1080
|
const matchCase = () => {
|
|
1076
1081
|
return i18nString(UiStrings.MatchCase);
|
|
1077
1082
|
};
|
|
1083
|
+
const preserveCase = () => {
|
|
1084
|
+
return i18nString(UiStrings.PreserveCase);
|
|
1085
|
+
};
|
|
1078
1086
|
const matchWholeWord = () => {
|
|
1079
1087
|
return i18nString(UiStrings.MatchWholeWord);
|
|
1080
1088
|
};
|
|
@@ -1349,8 +1357,13 @@ const IconButton = 'IconButton';
|
|
|
1349
1357
|
const Label = 'Label';
|
|
1350
1358
|
const List = 'List';
|
|
1351
1359
|
const MaskIcon = 'MaskIcon';
|
|
1360
|
+
const MaskIconCaseSensitive = 'MaskIconCaseSensitive';
|
|
1352
1361
|
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
1353
1362
|
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
1363
|
+
const MaskIconPreserveCase = 'MaskIconPreserveCase';
|
|
1364
|
+
const MaskIconRegex = 'MaskIconRegex';
|
|
1365
|
+
const MaskIconReplaceAll = 'MaskIconReplaceAll';
|
|
1366
|
+
const MaskIconWholeWord = 'MaskIconWholeWord';
|
|
1354
1367
|
const MultilineInputBox = 'MultilineInputBox';
|
|
1355
1368
|
const Search$1 = 'Search';
|
|
1356
1369
|
const SearchField = 'SearchField';
|
|
@@ -1594,8 +1607,29 @@ const getSearchFieldButtonVirtualDom = button => {
|
|
|
1594
1607
|
}];
|
|
1595
1608
|
};
|
|
1596
1609
|
|
|
1610
|
+
const getOutSideButtonsDom = outsideButtons => {
|
|
1611
|
+
if (outsideButtons.length === 0) {
|
|
1612
|
+
return {
|
|
1613
|
+
preNodes: [],
|
|
1614
|
+
postNodes: []
|
|
1615
|
+
};
|
|
1616
|
+
}
|
|
1617
|
+
return {
|
|
1618
|
+
preNodes: [{
|
|
1619
|
+
type: Div,
|
|
1620
|
+
className: SearchFieldContainer,
|
|
1621
|
+
role: None,
|
|
1622
|
+
childCount: 1 + outsideButtons.length
|
|
1623
|
+
}],
|
|
1624
|
+
postNodes: outsideButtons.flatMap(getSearchFieldButtonVirtualDom)
|
|
1625
|
+
};
|
|
1626
|
+
};
|
|
1597
1627
|
const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '') => {
|
|
1598
|
-
const
|
|
1628
|
+
const {
|
|
1629
|
+
preNodes,
|
|
1630
|
+
postNodes
|
|
1631
|
+
} = getOutSideButtonsDom(outsideButtons);
|
|
1632
|
+
const dom = [...preNodes, {
|
|
1599
1633
|
type: Div,
|
|
1600
1634
|
className: SearchField,
|
|
1601
1635
|
role: None,
|
|
@@ -1615,16 +1649,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
|
|
|
1615
1649
|
type: Div,
|
|
1616
1650
|
className: SearchFieldButtons,
|
|
1617
1651
|
childCount: insideButtons.length
|
|
1618
|
-
}, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom)];
|
|
1619
|
-
if (outsideButtons.length > 0) {
|
|
1620
|
-
dom.unshift({
|
|
1621
|
-
type: Div,
|
|
1622
|
-
className: SearchFieldContainer,
|
|
1623
|
-
role: None,
|
|
1624
|
-
childCount: 1 + outsideButtons.length
|
|
1625
|
-
});
|
|
1626
|
-
dom.push(...outsideButtons.flatMap(getSearchFieldButtonVirtualDom));
|
|
1627
|
-
}
|
|
1652
|
+
}, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom), ...postNodes];
|
|
1628
1653
|
return dom;
|
|
1629
1654
|
};
|
|
1630
1655
|
|
|
@@ -1667,27 +1692,27 @@ const getSearchHeaderVirtualDom = (replaceExpanded, matchCase$1, matchWholeWord$
|
|
|
1667
1692
|
role: None,
|
|
1668
1693
|
childCount: replaceExpanded ? 2 : 1
|
|
1669
1694
|
}, ...getSearchFieldVirtualDom('search-value', 'Search', 'handleInput', [{
|
|
1670
|
-
icon:
|
|
1695
|
+
icon: MaskIconCaseSensitive,
|
|
1671
1696
|
checked: matchCase$1,
|
|
1672
1697
|
title: matchCase()
|
|
1673
1698
|
}, {
|
|
1674
|
-
icon:
|
|
1699
|
+
icon: MaskIconWholeWord,
|
|
1675
1700
|
checked: matchWholeWord$1,
|
|
1676
1701
|
title: matchWholeWord()
|
|
1677
1702
|
}, {
|
|
1678
|
-
icon:
|
|
1703
|
+
icon: MaskIconRegex,
|
|
1679
1704
|
checked: useRegularExpression$1,
|
|
1680
1705
|
title: useRegularExpression()
|
|
1681
1706
|
}], [])];
|
|
1682
1707
|
if (replaceExpanded) {
|
|
1683
1708
|
dom.push(...getSearchFieldVirtualDom('search-replace-value', 'Replace', 'handleReplaceInput', [{
|
|
1684
|
-
icon:
|
|
1709
|
+
icon: MaskIconPreserveCase,
|
|
1685
1710
|
checked: false,
|
|
1686
|
-
title:
|
|
1711
|
+
title: preserveCase()
|
|
1687
1712
|
}], [{
|
|
1688
|
-
icon:
|
|
1713
|
+
icon: MaskIconReplaceAll,
|
|
1689
1714
|
checked: false,
|
|
1690
|
-
title:
|
|
1715
|
+
title: replaceAll$1()
|
|
1691
1716
|
}]));
|
|
1692
1717
|
}
|
|
1693
1718
|
if (detailsExpanded) {
|
|
@@ -1719,12 +1744,18 @@ const getBadgeVirtualDom = (className, count) => {
|
|
|
1719
1744
|
}, text(`${count}`)];
|
|
1720
1745
|
};
|
|
1721
1746
|
|
|
1722
|
-
const
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1747
|
+
const chevronDownVirtualDom = {
|
|
1748
|
+
type: Div,
|
|
1749
|
+
className: mergeClassNames(Chevron, MaskIconChevronDown),
|
|
1750
|
+
childCount: 0
|
|
1751
|
+
};
|
|
1752
|
+
({
|
|
1753
|
+
type: Div,
|
|
1754
|
+
className: mergeClassNames(Chevron, MaskIconChevronRight),
|
|
1755
|
+
childCount: 0
|
|
1756
|
+
});
|
|
1757
|
+
const getChevronDownVirtualDom = () => {
|
|
1758
|
+
return chevronDownVirtualDom;
|
|
1728
1759
|
};
|
|
1729
1760
|
|
|
1730
1761
|
const getFileIconVirtualDom = icon => {
|
|
@@ -1847,21 +1878,17 @@ const getSearchResultsVirtualDom = visibleItems => {
|
|
|
1847
1878
|
};
|
|
1848
1879
|
|
|
1849
1880
|
const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWholeWord, useRegularExpression, message, detailsExpanded, focusOutline) => {
|
|
1850
|
-
const dom = [
|
|
1851
|
-
dom.push({
|
|
1881
|
+
const dom = [{
|
|
1852
1882
|
type: Div,
|
|
1853
1883
|
className: mergeClassNames(Viewlet, Search$1),
|
|
1854
1884
|
childCount: 2
|
|
1855
|
-
})
|
|
1856
|
-
dom.push(...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded));
|
|
1857
|
-
dom.push({
|
|
1885
|
+
}, ...getSearchHeaderVirtualDom(replaceExpanded, matchCase, matchWholeWord, useRegularExpression, detailsExpanded), {
|
|
1858
1886
|
type: Div,
|
|
1859
1887
|
className: ViewletSearchMessage,
|
|
1860
1888
|
role: Status,
|
|
1861
1889
|
tabIndex: 0,
|
|
1862
1890
|
childCount: 1
|
|
1863
|
-
}, text(message)
|
|
1864
|
-
dom.push({
|
|
1891
|
+
}, text(message), {
|
|
1865
1892
|
type: Div,
|
|
1866
1893
|
className: mergeClassNames(Viewlet, List, focusOutline ? FocusOutline : Empty),
|
|
1867
1894
|
role: Tree,
|
|
@@ -1869,8 +1896,7 @@ const getSearchVirtualDom = (visibleItems, replaceExpanded, matchCase, matchWhol
|
|
|
1869
1896
|
childCount: visibleItems.length,
|
|
1870
1897
|
onClick: HandleClick,
|
|
1871
1898
|
onBlur: HandleListBlur
|
|
1872
|
-
});
|
|
1873
|
-
dom.push(...getSearchResultsVirtualDom(visibleItems));
|
|
1899
|
+
}, ...getSearchResultsVirtualDom(visibleItems)];
|
|
1874
1900
|
return dom;
|
|
1875
1901
|
};
|
|
1876
1902
|
|
|
@@ -2072,7 +2098,7 @@ const splitLines = lines => {
|
|
|
2072
2098
|
return lines.split('\n');
|
|
2073
2099
|
};
|
|
2074
2100
|
|
|
2075
|
-
const
|
|
2101
|
+
const textSearchInText = (file, content, query) => {
|
|
2076
2102
|
const results = [];
|
|
2077
2103
|
const lines = splitLines(content);
|
|
2078
2104
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -2099,6 +2125,7 @@ const textSearchInFile$1 = (file, content, query) => {
|
|
|
2099
2125
|
}
|
|
2100
2126
|
return results;
|
|
2101
2127
|
};
|
|
2128
|
+
|
|
2102
2129
|
const textSearch$4 = async (scheme, root, query, options, assetDir) => {
|
|
2103
2130
|
string(scheme);
|
|
2104
2131
|
string(root);
|
|
@@ -2111,15 +2138,38 @@ const textSearch$4 = async (scheme, root, query, options, assetDir) => {
|
|
|
2111
2138
|
const fetchUri = `${assetDir}${uri}`;
|
|
2112
2139
|
const content = await getText(fetchUri);
|
|
2113
2140
|
const relativeUri = uri.slice(relativeRoot.length + 1);
|
|
2114
|
-
const results =
|
|
2141
|
+
const results = textSearchInText(relativeUri, content, query);
|
|
2115
2142
|
allResults.push(...results);
|
|
2116
2143
|
}
|
|
2117
2144
|
return allResults;
|
|
2118
2145
|
};
|
|
2119
2146
|
|
|
2147
|
+
class FileNotFoundError extends Error {
|
|
2148
|
+
constructor(message) {
|
|
2149
|
+
super(message);
|
|
2150
|
+
this.name = 'FileNotFoundError';
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2120
2154
|
const Directory = 'directory';
|
|
2121
2155
|
const File = 'file';
|
|
2122
2156
|
|
|
2157
|
+
const getChildHandles$1 = async handle => {
|
|
2158
|
+
object(handle);
|
|
2159
|
+
// @ts-ignore
|
|
2160
|
+
const childHandles = handle.values();
|
|
2161
|
+
const handles = await fromAsync(childHandles);
|
|
2162
|
+
return handles;
|
|
2163
|
+
};
|
|
2164
|
+
|
|
2165
|
+
const getChildHandles = async handle => {
|
|
2166
|
+
try {
|
|
2167
|
+
return await getChildHandles$1(handle);
|
|
2168
|
+
} catch (error) {
|
|
2169
|
+
throw new VError(error, 'failed to get child handles');
|
|
2170
|
+
}
|
|
2171
|
+
};
|
|
2172
|
+
|
|
2123
2173
|
const dirname = (pathSeparator, path) => {
|
|
2124
2174
|
const index = path.lastIndexOf(pathSeparator);
|
|
2125
2175
|
if (index === -1) {
|
|
@@ -2441,34 +2491,6 @@ const getFile = handle => {
|
|
|
2441
2491
|
return handle.getFile();
|
|
2442
2492
|
};
|
|
2443
2493
|
|
|
2444
|
-
const textSearchInText = (file, content, query) => {
|
|
2445
|
-
const results = [];
|
|
2446
|
-
const lines = splitLines(content);
|
|
2447
|
-
for (let i = 0; i < lines.length; i++) {
|
|
2448
|
-
const line = lines[i];
|
|
2449
|
-
const index = line.indexOf(query);
|
|
2450
|
-
if (index !== -1) {
|
|
2451
|
-
results.push({
|
|
2452
|
-
type: Match,
|
|
2453
|
-
text: line,
|
|
2454
|
-
start: index,
|
|
2455
|
-
end: index + query.length,
|
|
2456
|
-
lineNumber: i
|
|
2457
|
-
});
|
|
2458
|
-
}
|
|
2459
|
-
}
|
|
2460
|
-
if (results.length > 0) {
|
|
2461
|
-
results.unshift({
|
|
2462
|
-
type: File$1,
|
|
2463
|
-
text: file,
|
|
2464
|
-
start: 0,
|
|
2465
|
-
end: 0,
|
|
2466
|
-
lineNumber: 0
|
|
2467
|
-
});
|
|
2468
|
-
}
|
|
2469
|
-
return results;
|
|
2470
|
-
};
|
|
2471
|
-
|
|
2472
2494
|
const textSearchInFile = async (all, handle, absolutePath, query) => {
|
|
2473
2495
|
try {
|
|
2474
2496
|
const file = await getFile(handle);
|
|
@@ -2485,9 +2507,7 @@ const textSearchInFile = async (all, handle, absolutePath, query) => {
|
|
|
2485
2507
|
};
|
|
2486
2508
|
|
|
2487
2509
|
const textSearchRecursively = async (all, parent, handle, query) => {
|
|
2488
|
-
const childHandles =
|
|
2489
|
-
// TODO
|
|
2490
|
-
// await FileSystemHtml.getChildHandles(handle)
|
|
2510
|
+
const childHandles = await getChildHandles(handle);
|
|
2491
2511
|
const promises = [];
|
|
2492
2512
|
for (const childHandle of childHandles) {
|
|
2493
2513
|
const absolutePath = parent + '/' + childHandle.name;
|
|
@@ -2496,6 +2516,7 @@ const textSearchRecursively = async (all, parent, handle, query) => {
|
|
|
2496
2516
|
promises.push(textSearchRecursively(all, absolutePath, childHandle, query));
|
|
2497
2517
|
break;
|
|
2498
2518
|
case File:
|
|
2519
|
+
// @ts-ignore
|
|
2499
2520
|
promises.push(textSearchInFile(all, childHandle, absolutePath, query));
|
|
2500
2521
|
break;
|
|
2501
2522
|
}
|
|
@@ -2509,7 +2530,7 @@ const textSearch$3 = async (scheme, root, query) => {
|
|
|
2509
2530
|
const relativeRoot = root.slice('html://'.length);
|
|
2510
2531
|
const handle = await getDirectoryHandle(relativeRoot);
|
|
2511
2532
|
if (!handle) {
|
|
2512
|
-
throw new
|
|
2533
|
+
throw new FileNotFoundError(`Folder not found: ${relativeRoot}`);
|
|
2513
2534
|
}
|
|
2514
2535
|
const all = [];
|
|
2515
2536
|
await textSearchRecursively(all, '', handle, query);
|
|
@@ -3136,7 +3157,7 @@ const getBulkReplacementEdits = (workspacePath, matches) => {
|
|
|
3136
3157
|
ranges.push(currentRanges.length);
|
|
3137
3158
|
push(ranges, currentRanges);
|
|
3138
3159
|
const absolutePath = `${workspacePath}/${text.slice(2)}`;
|
|
3139
|
-
files.push(absolutePath);
|
|
3160
|
+
files.push(absolutePath);
|
|
3140
3161
|
currentRanges = [];
|
|
3141
3162
|
break;
|
|
3142
3163
|
case Match:
|
|
@@ -3152,12 +3173,18 @@ const getBulkReplacementEdits = (workspacePath, matches) => {
|
|
|
3152
3173
|
};
|
|
3153
3174
|
};
|
|
3154
3175
|
|
|
3155
|
-
const replaceAll = async
|
|
3176
|
+
const replaceAll = async state => {
|
|
3177
|
+
const {
|
|
3178
|
+
workspacePath,
|
|
3179
|
+
items,
|
|
3180
|
+
replacement
|
|
3181
|
+
} = state;
|
|
3156
3182
|
const {
|
|
3157
3183
|
files,
|
|
3158
3184
|
ranges
|
|
3159
3185
|
} = getBulkReplacementEdits(workspacePath, items);
|
|
3160
3186
|
await invoke$1('BulkReplacement.applyBulkReplacement', files, ranges, replacement);
|
|
3187
|
+
return state;
|
|
3161
3188
|
};
|
|
3162
3189
|
|
|
3163
3190
|
const getReplaceAllConfirmText = (matchCount, fileCount, replacement) => {
|
|
@@ -3284,8 +3311,8 @@ const focusReplaceAll = state => {
|
|
|
3284
3311
|
return focusElement(state, FocusSearchReplaceAll);
|
|
3285
3312
|
};
|
|
3286
3313
|
const handleFocusIn = (state, key) => {
|
|
3287
|
-
const focusKey = getSearchFocusKey(key
|
|
3288
|
-
if (
|
|
3314
|
+
const focusKey = getSearchFocusKey(key);
|
|
3315
|
+
if (state.focus === focusKey) {
|
|
3289
3316
|
return state;
|
|
3290
3317
|
}
|
|
3291
3318
|
void setFocus(focusKey);
|