@lvce-editor/text-search-worker 4.1.0 → 4.2.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 +1997 -2045
- package/package.json +1 -1
|
@@ -1076,7 +1076,7 @@ const FocusSearchWholeWord = 34;
|
|
|
1076
1076
|
const FocusToggleDetails = 1010;
|
|
1077
1077
|
const FocusToggleReplace = 1020;
|
|
1078
1078
|
|
|
1079
|
-
const clearSearchResults
|
|
1079
|
+
const clearSearchResults = state => {
|
|
1080
1080
|
return {
|
|
1081
1081
|
...state,
|
|
1082
1082
|
value: '',
|
|
@@ -1325,8 +1325,6 @@ const i18nString = (key, placeholders = emptyObject) => {
|
|
|
1325
1325
|
return key.replaceAll(RE_PLACEHOLDER, replacer);
|
|
1326
1326
|
};
|
|
1327
1327
|
|
|
1328
|
-
const ClearSearchResults = 'Clear Search Results';
|
|
1329
|
-
const CollapseAll$1 = 'Collapse All';
|
|
1330
1328
|
const ConfirmReplaceManyOccurrencesInManyFiles = "Replace {PH1} occurrences across {PH2} files with '{PH3}'";
|
|
1331
1329
|
const ConfirmReplaceManyOccurrencesInManyFilesNoValue = 'Replace {PH1} occurrences across {PH2} files';
|
|
1332
1330
|
const ConfirmReplaceManyOccurrencesInOneFile = "Replace {PH1} occurrences across 1 file with '{PH2}'";
|
|
@@ -1339,16 +1337,13 @@ const MatchCase$1 = 'Match Case';
|
|
|
1339
1337
|
const MatchWholeWord$1 = 'Match Whole Word';
|
|
1340
1338
|
const NoResults = 'No results found';
|
|
1341
1339
|
const Oneresult = '1 result in 1 file';
|
|
1342
|
-
const OpenNewSearchEditor = 'Open New Search Editor';
|
|
1343
1340
|
const PreserveCase$1 = 'Preserve Case';
|
|
1344
|
-
const Refresh$1 = 'Refresh';
|
|
1345
1341
|
const Replace = 'Replace';
|
|
1346
1342
|
const ReplaceAll$1 = 'Replace All';
|
|
1347
1343
|
const ReplacedManyOccurrencesInManyFiles = "Replaced {PH1} occurrences across {PH2} files with '{PH3}'";
|
|
1348
1344
|
const ReplacedOneOccurrenceInOneFile = "Replaced 1 occurrence across 1 file with '{PH1}'";
|
|
1349
1345
|
const ToggleReplace$1 = 'Toggle Replace';
|
|
1350
1346
|
const UseRegularExpression$1 = 'Use Regular Expression';
|
|
1351
|
-
const ViewAsTree = 'View as Tree';
|
|
1352
1347
|
const FilesToInclude$1 = 'Files to Include';
|
|
1353
1348
|
const FilesToExclude$1 = 'Files to Exclude';
|
|
1354
1349
|
const ToggleSearchDetails$1 = 'Toggle Search Details';
|
|
@@ -1446,21 +1441,6 @@ const replaceAll$1 = () => {
|
|
|
1446
1441
|
const replace = () => {
|
|
1447
1442
|
return i18nString(Replace);
|
|
1448
1443
|
};
|
|
1449
|
-
const refresh$1 = () => {
|
|
1450
|
-
return i18nString(Refresh$1);
|
|
1451
|
-
};
|
|
1452
|
-
const clearSearchResults = () => {
|
|
1453
|
-
return i18nString(ClearSearchResults);
|
|
1454
|
-
};
|
|
1455
|
-
const openNewSearchEditor = () => {
|
|
1456
|
-
return i18nString(OpenNewSearchEditor);
|
|
1457
|
-
};
|
|
1458
|
-
const viewAsTree = () => {
|
|
1459
|
-
return i18nString(ViewAsTree);
|
|
1460
|
-
};
|
|
1461
|
-
const collapseAll = () => {
|
|
1462
|
-
return i18nString(CollapseAll$1);
|
|
1463
|
-
};
|
|
1464
1444
|
const filesToInclude = () => {
|
|
1465
1445
|
return i18nString(FilesToInclude$1);
|
|
1466
1446
|
};
|
|
@@ -1750,2327 +1730,2251 @@ const focusSearchValueNext = state => {
|
|
|
1750
1730
|
return focusMatchCase$1(state);
|
|
1751
1731
|
};
|
|
1752
1732
|
|
|
1753
|
-
const
|
|
1754
|
-
const Button$2 = 'button';
|
|
1755
|
-
const CheckBox = 'checkbox';
|
|
1756
|
-
const None$1 = 'none';
|
|
1757
|
-
const ScrollBar$1 = 'scrollbar';
|
|
1758
|
-
const Status = 'status';
|
|
1759
|
-
const ToolBar = 'toolbar';
|
|
1760
|
-
const Tree$1 = 'tree';
|
|
1761
|
-
const TreeItem$1 = 'treeitem';
|
|
1733
|
+
const commandIds = ['clearSearchResults', 'collapseDetails', 'copy', 'dismissItem', 'expandDetails', 'focusFirst', 'focusIndex', 'focusLast', 'focusMatchCase', 'focusMatchCasePrevious', 'focusMatchWholeWord', 'focusNext', 'focusNextInput', 'focusNextPage', 'focusPreserveCasePrevious', 'focusPrevious', 'focusPreviousInput', 'focusPreviousPage', 'focusRegex', 'focusRegexNext', 'focusReplaceAll', 'focusReplaceValue', 'focusReplaceValueNext', 'focusReplaceValuePrevious', 'focusSearchValue', 'focusSearchValueNext', 'handleClick', 'handleClickAt', 'handleContextMenu', 'handleContextMenuKeyboard', 'handleContextMenuMouseAt', 'handleExcludeInput', 'handleFocusIn', 'handleHeaderClick', 'handleHeaderFocusIn', 'handleIconThemeChange', 'handleIconThemeChange', 'handleIncludeInput', 'handleInput', 'handleInput2', 'handleListBlur', 'handleListFocus', 'handleReplaceInput', 'handleScrollBarCaptureLost', 'handleScrollBarClick', 'handleScrollBarMove', 'handleScrollBarThumbPointerMove', 'handleTouchEnd', 'handleTouchMove', 'handleTouchStart', 'handleUpdate', 'handleWheel', 'refresh', 'replaceAll', 'scrollDown', 'selectIndex', 'submit', 'toggleMatchCase', 'toggleMatchWholeWord', 'togglePreserveCase', 'toggleReplace', 'toggleSearchDetails', 'toggleUseRegularExpression'];
|
|
1762
1734
|
|
|
1763
|
-
const
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
const CloseMaskIcon = 'MaskIcon MaskIconClose';
|
|
1767
|
-
const Empty = '';
|
|
1768
|
-
const FileIcon = 'FileIcon';
|
|
1769
|
-
const FocusOutline = 'FocusOutline';
|
|
1770
|
-
const Grow = 'Grow';
|
|
1771
|
-
const Highlight = 'Highlight';
|
|
1772
|
-
const HighlightDeleted = 'HighlightDeleted';
|
|
1773
|
-
const HighlightInserted = 'HighlightInserted';
|
|
1774
|
-
const IconButton = 'IconButton';
|
|
1775
|
-
const Label = 'Label';
|
|
1776
|
-
const List = 'List';
|
|
1777
|
-
const MaskIcon = 'MaskIcon';
|
|
1778
|
-
const MaskIconBook = 'MaskIconBook';
|
|
1779
|
-
const MaskIconCaseSensitive = 'MaskIconCaseSensitive';
|
|
1780
|
-
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
1781
|
-
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
1782
|
-
const MaskIconEllipsis = 'MaskIconEllipsis';
|
|
1783
|
-
const MaskIconExclude = 'MaskIconExclude';
|
|
1784
|
-
const MaskIconPreserveCase = 'MaskIconPreserveCase';
|
|
1785
|
-
const MaskIconRegex = 'MaskIconRegex';
|
|
1786
|
-
const MaskIconReplaceAll = 'MaskIconReplaceAll';
|
|
1787
|
-
const MaskIconWholeWord = 'MaskIconWholeWord';
|
|
1788
|
-
const MultilineInputBox = 'MultilineInputBox';
|
|
1789
|
-
const ScrollBar = 'ScrollBar';
|
|
1790
|
-
const ScrollBarThumb = 'ScrollBarThumb';
|
|
1791
|
-
const ScrollBarVertical = 'ScrollBarVertical';
|
|
1792
|
-
const Search$1 = 'Search';
|
|
1793
|
-
const SearchField = 'SearchField';
|
|
1794
|
-
const SearchFieldButton = 'SearchFieldButton';
|
|
1795
|
-
const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
|
|
1796
|
-
const SearchFieldButtonDisabled = 'SearchFieldButtonDisabled';
|
|
1797
|
-
const SearchFieldButtons = 'SearchFieldButtons';
|
|
1798
|
-
const SearchFieldContainer = 'SearchFieldContainer';
|
|
1799
|
-
const SearchFieldError = 'SearchFieldError';
|
|
1800
|
-
const SearchHeader = 'SearchHeader';
|
|
1801
|
-
const SearchHeaderDetails = 'SearchHeaderDetails';
|
|
1802
|
-
const SearchHeaderDetailsExpanded = 'SearchHeaderDetailsExpanded';
|
|
1803
|
-
const SearchHeaderDetailsExpandedTop = 'SearchHeaderDetailsExpandedTop';
|
|
1804
|
-
const SearchHeaderDetailsHeading = 'SearchHeaderDetailsHeading';
|
|
1805
|
-
const SearchHeaderTop = 'SearchHeaderTop';
|
|
1806
|
-
const SearchHeaderTopRight = 'SearchHeaderTopRight';
|
|
1807
|
-
const SearchInputError = 'SearchInputError';
|
|
1808
|
-
const SearchRemove = 'SearchRemove';
|
|
1809
|
-
const SearchToggleButton = 'SearchToggleButton';
|
|
1810
|
-
const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
|
|
1811
|
-
const SourceControlBadge = 'SourceControlBadge';
|
|
1812
|
-
const ToggleDetails = 'ToggleDetails';
|
|
1813
|
-
const Tree = 'Tree';
|
|
1814
|
-
const TreeItem = 'TreeItem';
|
|
1815
|
-
const TreeItemActive = 'TreeItemActive';
|
|
1816
|
-
const TreeItems$1 = 'TreeItems';
|
|
1817
|
-
const Viewlet = 'Viewlet';
|
|
1818
|
-
const ViewletSearchMessage = 'ViewletSearchMessage';
|
|
1819
|
-
const ViewletSearchMessageIndented = 'ViewletSearchMessageIndented';
|
|
1735
|
+
const getCommandIds = () => {
|
|
1736
|
+
return commandIds;
|
|
1737
|
+
};
|
|
1820
1738
|
|
|
1821
|
-
const
|
|
1739
|
+
const Tab = 2;
|
|
1740
|
+
const Enter = 3;
|
|
1741
|
+
const End = 255;
|
|
1742
|
+
const Home = 12;
|
|
1743
|
+
const UpArrow = 14;
|
|
1744
|
+
const DownArrow = 16;
|
|
1745
|
+
const Delete = 18;
|
|
1746
|
+
const KeyC = 31;
|
|
1822
1747
|
|
|
1823
|
-
const
|
|
1824
|
-
|
|
1748
|
+
const CtrlCmd = 1 << 11 >>> 0;
|
|
1749
|
+
const Shift = 1 << 10 >>> 0;
|
|
1750
|
+
const Alt = 1 << 9 >>> 0;
|
|
1751
|
+
|
|
1752
|
+
const getKeyBindings = () => {
|
|
1753
|
+
return [{
|
|
1754
|
+
key: CtrlCmd | Alt | Enter,
|
|
1755
|
+
command: 'Search.replaceAll',
|
|
1756
|
+
when: FocusSearch
|
|
1757
|
+
}, {
|
|
1758
|
+
key: Tab,
|
|
1759
|
+
command: 'Search.focusNextInput',
|
|
1760
|
+
when: FocusSearch
|
|
1761
|
+
}, {
|
|
1762
|
+
key: Shift | Tab,
|
|
1763
|
+
command: 'Search.focusPreviousInput',
|
|
1764
|
+
when: FocusSearch
|
|
1765
|
+
}, {
|
|
1766
|
+
key: DownArrow,
|
|
1767
|
+
command: 'Search.focusNext',
|
|
1768
|
+
when: FocusSearchResults
|
|
1769
|
+
}, {
|
|
1770
|
+
key: UpArrow,
|
|
1771
|
+
command: 'Search.focusPrevious',
|
|
1772
|
+
when: FocusSearchResults
|
|
1773
|
+
}, {
|
|
1774
|
+
key: Delete,
|
|
1775
|
+
command: 'Search.dismissItem',
|
|
1776
|
+
when: FocusSearchResults
|
|
1777
|
+
}, {
|
|
1778
|
+
key: Home,
|
|
1779
|
+
command: 'Search.focusFirst',
|
|
1780
|
+
when: FocusSearchResults
|
|
1781
|
+
}, {
|
|
1782
|
+
key: End,
|
|
1783
|
+
command: 'Search.focusLast',
|
|
1784
|
+
when: FocusSearchResults
|
|
1785
|
+
}, {
|
|
1786
|
+
key: CtrlCmd | KeyC,
|
|
1787
|
+
command: 'Search.copy',
|
|
1788
|
+
when: FocusSearchResults
|
|
1789
|
+
}, {
|
|
1790
|
+
key: Enter,
|
|
1791
|
+
command: 'Search.submit',
|
|
1792
|
+
when: FocusSearchInput
|
|
1793
|
+
}, {
|
|
1794
|
+
key: Enter,
|
|
1795
|
+
command: 'Search.submit',
|
|
1796
|
+
when: FocusSearchReplaceInput
|
|
1797
|
+
}];
|
|
1825
1798
|
};
|
|
1826
|
-
|
|
1827
|
-
const
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
const
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
for (let k = 0; k < pendingPatches.length - skip; k += 2) {
|
|
1837
|
-
const type = pendingPatches[k];
|
|
1838
|
-
const index = pendingPatches[k + 1];
|
|
1839
|
-
if (type === NavigateParent) {
|
|
1840
|
-
patches.push({
|
|
1841
|
-
type
|
|
1842
|
-
});
|
|
1843
|
-
} else {
|
|
1844
|
-
patches.push({
|
|
1845
|
-
type,
|
|
1846
|
-
index
|
|
1847
|
-
});
|
|
1848
|
-
}
|
|
1799
|
+
|
|
1800
|
+
const handleError = error => {
|
|
1801
|
+
console.error(`[text-search-worker] ${error}`);
|
|
1802
|
+
};
|
|
1803
|
+
|
|
1804
|
+
const getFileIcon = async result => {
|
|
1805
|
+
if (result.type === File) {
|
|
1806
|
+
return invoke$2('IconTheme.getFileIcon', {
|
|
1807
|
+
name: result.text
|
|
1808
|
+
});
|
|
1849
1809
|
}
|
|
1850
|
-
|
|
1810
|
+
return '';
|
|
1851
1811
|
};
|
|
1852
|
-
const
|
|
1853
|
-
|
|
1812
|
+
const getFileIcons = async matches => {
|
|
1813
|
+
// TODO cache file icons
|
|
1814
|
+
const promises = matches.map(getFileIcon);
|
|
1815
|
+
const icons = await Promise.all(promises);
|
|
1816
|
+
return icons;
|
|
1854
1817
|
};
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1818
|
+
|
|
1819
|
+
// TODO optimize this function to return the minimum number
|
|
1820
|
+
// of visible items needed, e.g. when not scrolled 5 items with
|
|
1821
|
+
// 20px fill 100px but when scrolled 6 items are needed
|
|
1822
|
+
const getNumberOfVisibleItems$1 = (listHeight, itemHeight) => {
|
|
1823
|
+
return Math.ceil(listHeight / itemHeight) + 1;
|
|
1858
1824
|
};
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
pending--;
|
|
1866
|
-
i++;
|
|
1825
|
+
|
|
1826
|
+
const RE_PROTOCOL = /^([a-z-\d]+):\/\//;
|
|
1827
|
+
const getProtocol$1 = uri => {
|
|
1828
|
+
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
1829
|
+
if (protocolMatch) {
|
|
1830
|
+
return protocolMatch[1];
|
|
1867
1831
|
}
|
|
1868
|
-
return
|
|
1832
|
+
return '';
|
|
1869
1833
|
};
|
|
1870
|
-
const diff = (oldNodes, newNodes) => {
|
|
1871
|
-
const patches = [];
|
|
1872
|
-
const pendingPatches = [];
|
|
1873
|
-
let i = 0;
|
|
1874
|
-
let j = 0;
|
|
1875
|
-
let siblingOffset = 0;
|
|
1876
|
-
let maxSiblingOffset = 1;
|
|
1877
|
-
const indexStack = [0, 1];
|
|
1878
|
-
while (i < oldNodes.length && j < newNodes.length) {
|
|
1879
|
-
const oldNode = oldNodes[i];
|
|
1880
|
-
const newNode = newNodes[j];
|
|
1881
1834
|
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
siblingOffset = indexStack.pop() + 1;
|
|
1894
|
-
}
|
|
1895
|
-
if (oldNode.type !== newNode.type) {
|
|
1896
|
-
let skip = 0;
|
|
1897
|
-
if (pendingPatches.length > 0 && pendingPatches.at(-2) === NavigateChild) {
|
|
1898
|
-
skip = 2;
|
|
1899
|
-
}
|
|
1900
|
-
applyPendingPatches(patches, pendingPatches, skip);
|
|
1901
|
-
const oldTotal = getTotalChildCount(oldNodes, i);
|
|
1902
|
-
const newTotal = getTotalChildCount(newNodes, j);
|
|
1903
|
-
patches.push({
|
|
1904
|
-
type: RemoveChild,
|
|
1905
|
-
index: siblingOffset
|
|
1906
|
-
});
|
|
1907
|
-
patches.push({
|
|
1908
|
-
type: Add,
|
|
1909
|
-
nodes: newNodes.slice(j, j + newTotal)
|
|
1910
|
-
});
|
|
1911
|
-
siblingOffset++;
|
|
1912
|
-
i += oldTotal;
|
|
1913
|
-
j += newTotal;
|
|
1914
|
-
continue;
|
|
1835
|
+
const getTextSearchResultCounts = results => {
|
|
1836
|
+
let resultCount = 0;
|
|
1837
|
+
let fileCount = 0;
|
|
1838
|
+
for (const result of results) {
|
|
1839
|
+
switch (result.type) {
|
|
1840
|
+
case File:
|
|
1841
|
+
fileCount++;
|
|
1842
|
+
break;
|
|
1843
|
+
case Match:
|
|
1844
|
+
resultCount++;
|
|
1845
|
+
break;
|
|
1915
1846
|
}
|
|
1916
|
-
if (oldNode.type === Text$1 && newNode.type === Text$1) {
|
|
1917
|
-
if (oldNode.text !== newNode.text) {
|
|
1918
|
-
if (siblingOffset !== 0) {
|
|
1919
|
-
pendingPatches.push(NavigateSibling, siblingOffset);
|
|
1920
|
-
}
|
|
1921
|
-
applyPendingPatches(patches, pendingPatches, 0);
|
|
1922
|
-
patches.push({
|
|
1923
|
-
type: SetText,
|
|
1924
|
-
value: newNode.text
|
|
1925
|
-
});
|
|
1926
|
-
}
|
|
1927
|
-
i++;
|
|
1928
|
-
j++;
|
|
1929
|
-
siblingOffset++;
|
|
1930
|
-
continue;
|
|
1931
|
-
}
|
|
1932
|
-
const oldKeys = getKeys(oldNode);
|
|
1933
|
-
const newKeys = getKeys(newNode);
|
|
1934
|
-
let hasAttributeChanges = false;
|
|
1935
|
-
for (const key of newKeys) {
|
|
1936
|
-
if (oldNode[key] !== newNode[key]) {
|
|
1937
|
-
hasAttributeChanges = true;
|
|
1938
|
-
break;
|
|
1939
|
-
}
|
|
1940
|
-
}
|
|
1941
|
-
for (const key of oldKeys) {
|
|
1942
|
-
if (!(key in newNode)) {
|
|
1943
|
-
hasAttributeChanges = true;
|
|
1944
|
-
break;
|
|
1945
|
-
}
|
|
1946
|
-
}
|
|
1947
|
-
if (hasAttributeChanges) {
|
|
1948
|
-
if (siblingOffset > 0) {
|
|
1949
|
-
pendingPatches.push(NavigateSibling, siblingOffset);
|
|
1950
|
-
}
|
|
1951
|
-
applyPendingPatches(patches, pendingPatches, 0);
|
|
1952
|
-
for (const key of newKeys) {
|
|
1953
|
-
if (oldNode[key] !== newNode[key]) {
|
|
1954
|
-
patches.push({
|
|
1955
|
-
type: SetAttribute,
|
|
1956
|
-
key,
|
|
1957
|
-
value: newNode[key]
|
|
1958
|
-
});
|
|
1959
|
-
}
|
|
1960
|
-
}
|
|
1961
|
-
for (const key of oldKeys) {
|
|
1962
|
-
if (!(key in newNode)) {
|
|
1963
|
-
patches.push({
|
|
1964
|
-
type: RemoveAttribute,
|
|
1965
|
-
key
|
|
1966
|
-
});
|
|
1967
|
-
}
|
|
1968
|
-
}
|
|
1969
|
-
}
|
|
1970
|
-
if (oldNode.childCount && newNode.childCount) {
|
|
1971
|
-
maxSiblingOffset = oldNode.childCount;
|
|
1972
|
-
indexStack.push(0, maxSiblingOffset);
|
|
1973
|
-
pendingPatches.push(NavigateChild, 0);
|
|
1974
|
-
i++;
|
|
1975
|
-
j++;
|
|
1976
|
-
continue;
|
|
1977
|
-
}
|
|
1978
|
-
if (oldNode.childCount) {
|
|
1979
|
-
applyPendingPatches(patches, pendingPatches, 0);
|
|
1980
|
-
for (let k = 0; k < oldNode.childCount; k++) {
|
|
1981
|
-
patches.push({
|
|
1982
|
-
type: RemoveChild,
|
|
1983
|
-
index: 0
|
|
1984
|
-
});
|
|
1985
|
-
}
|
|
1986
|
-
i += getTotalChildCount(oldNodes, i);
|
|
1987
|
-
j++;
|
|
1988
|
-
siblingOffset++;
|
|
1989
|
-
continue;
|
|
1990
|
-
}
|
|
1991
|
-
if (newNode.childCount) {
|
|
1992
|
-
applyPendingPatches(patches, pendingPatches, 0);
|
|
1993
|
-
const total = getTotalChildCount(newNodes, j);
|
|
1994
|
-
patches.push({
|
|
1995
|
-
type: Add,
|
|
1996
|
-
nodes: newNodes.slice(j + 1, j + total)
|
|
1997
|
-
});
|
|
1998
|
-
i++;
|
|
1999
|
-
j += total;
|
|
2000
|
-
continue;
|
|
2001
|
-
}
|
|
2002
|
-
i++;
|
|
2003
|
-
j++;
|
|
2004
|
-
siblingOffset++;
|
|
2005
|
-
}
|
|
2006
|
-
while (i < oldNodes.length) {
|
|
2007
|
-
if (indexStack.length !== 2) {
|
|
2008
|
-
patches.push({
|
|
2009
|
-
type: NavigateParent
|
|
2010
|
-
});
|
|
2011
|
-
}
|
|
2012
|
-
patches.push({
|
|
2013
|
-
type: RemoveChild,
|
|
2014
|
-
index: siblingOffset
|
|
2015
|
-
});
|
|
2016
|
-
i += getTotalChildCount(oldNodes, i);
|
|
2017
|
-
indexStack.pop();
|
|
2018
|
-
indexStack.pop();
|
|
2019
|
-
}
|
|
2020
|
-
while (j < newNodes.length) {
|
|
2021
|
-
if (siblingOffset > 0) {
|
|
2022
|
-
patches.push({
|
|
2023
|
-
type: NavigateSibling,
|
|
2024
|
-
index: siblingOffset
|
|
2025
|
-
});
|
|
2026
|
-
siblingOffset = 0;
|
|
2027
|
-
}
|
|
2028
|
-
const count = getTotalChildCount(newNodes, j);
|
|
2029
|
-
patches.push({
|
|
2030
|
-
type: Add,
|
|
2031
|
-
nodes: newNodes.slice(j, j + count)
|
|
2032
|
-
});
|
|
2033
|
-
j += count;
|
|
2034
1847
|
}
|
|
2035
|
-
return patches;
|
|
2036
|
-
};
|
|
2037
|
-
|
|
2038
|
-
const Button = 1;
|
|
2039
|
-
const Del = 21;
|
|
2040
|
-
const Div = 4;
|
|
2041
|
-
const H4 = 24;
|
|
2042
|
-
const Img = 17;
|
|
2043
|
-
const Ins = 20;
|
|
2044
|
-
const Span = 8;
|
|
2045
|
-
const Text = 12;
|
|
2046
|
-
const TextArea = 62;
|
|
2047
|
-
|
|
2048
|
-
const getIconVirtualDom = (icon, type = Div) => {
|
|
2049
1848
|
return {
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
role: None$1,
|
|
2053
|
-
childCount: 0
|
|
1849
|
+
fileCount,
|
|
1850
|
+
resultCount
|
|
2054
1851
|
};
|
|
2055
1852
|
};
|
|
2056
1853
|
|
|
2057
|
-
const
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
command
|
|
2062
|
-
} = action;
|
|
2063
|
-
return [{
|
|
2064
|
-
type: Button,
|
|
2065
|
-
className: IconButton,
|
|
2066
|
-
title: id,
|
|
2067
|
-
'data-command': command,
|
|
2068
|
-
childCount: 1
|
|
2069
|
-
}, getIconVirtualDom(icon)];
|
|
1854
|
+
const EmptyString = '';
|
|
1855
|
+
|
|
1856
|
+
const isEmptyString = string => {
|
|
1857
|
+
return string === EmptyString;
|
|
2070
1858
|
};
|
|
2071
1859
|
|
|
2072
|
-
const
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
return getActionButtonVirtualDom(action);
|
|
2076
|
-
default:
|
|
2077
|
-
return [];
|
|
1860
|
+
const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
|
|
1861
|
+
if (size >= contentSize) {
|
|
1862
|
+
return 0;
|
|
2078
1863
|
}
|
|
1864
|
+
return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
|
|
2079
1865
|
};
|
|
2080
|
-
|
|
2081
|
-
const
|
|
2082
|
-
return
|
|
2083
|
-
type: Div,
|
|
2084
|
-
className: Actions,
|
|
2085
|
-
role: ToolBar,
|
|
2086
|
-
childCount: actions.length
|
|
2087
|
-
}, ...actions.flatMap(getActionVirtualDom)];
|
|
1866
|
+
const getScrollBarOffset$1 = (delta, finalDelta, size, scrollBarSize) => {
|
|
1867
|
+
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
1868
|
+
return scrollBarOffset;
|
|
2088
1869
|
};
|
|
1870
|
+
const getScrollBarY$1 = getScrollBarOffset$1;
|
|
2089
1871
|
|
|
2090
|
-
const
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
1872
|
+
const textSearch$6 = async (scheme, root, query) => {
|
|
1873
|
+
string(scheme);
|
|
1874
|
+
string(query);
|
|
1875
|
+
const result = await invoke$2('ExtensionHostTextSearch.executeTextSearchProvider', scheme, query);
|
|
1876
|
+
return result;
|
|
2094
1877
|
};
|
|
2095
1878
|
|
|
2096
|
-
const
|
|
2097
|
-
|
|
2098
|
-
const End = 255;
|
|
2099
|
-
const Home = 12;
|
|
2100
|
-
const UpArrow = 14;
|
|
2101
|
-
const DownArrow = 16;
|
|
2102
|
-
const Delete = 18;
|
|
2103
|
-
const KeyC = 31;
|
|
2104
|
-
|
|
2105
|
-
const CtrlCmd = 1 << 11 >>> 0;
|
|
2106
|
-
const Shift = 1 << 10 >>> 0;
|
|
2107
|
-
const Alt = 1 << 9 >>> 0;
|
|
2108
|
-
|
|
2109
|
-
const getKeyBindings = () => {
|
|
2110
|
-
return [{
|
|
2111
|
-
key: CtrlCmd | Alt | Enter,
|
|
2112
|
-
command: 'Search.replaceAll',
|
|
2113
|
-
when: FocusSearch
|
|
2114
|
-
}, {
|
|
2115
|
-
key: Tab,
|
|
2116
|
-
command: 'Search.focusNextInput',
|
|
2117
|
-
when: FocusSearch
|
|
2118
|
-
}, {
|
|
2119
|
-
key: Shift | Tab,
|
|
2120
|
-
command: 'Search.focusPreviousInput',
|
|
2121
|
-
when: FocusSearch
|
|
2122
|
-
}, {
|
|
2123
|
-
key: DownArrow,
|
|
2124
|
-
command: 'Search.focusNext',
|
|
2125
|
-
when: FocusSearchResults
|
|
2126
|
-
}, {
|
|
2127
|
-
key: UpArrow,
|
|
2128
|
-
command: 'Search.focusPrevious',
|
|
2129
|
-
when: FocusSearchResults
|
|
2130
|
-
}, {
|
|
2131
|
-
key: Delete,
|
|
2132
|
-
command: 'Search.dismissItem',
|
|
2133
|
-
when: FocusSearchResults
|
|
2134
|
-
}, {
|
|
2135
|
-
key: Home,
|
|
2136
|
-
command: 'Search.focusFirst',
|
|
2137
|
-
when: FocusSearchResults
|
|
2138
|
-
}, {
|
|
2139
|
-
key: End,
|
|
2140
|
-
command: 'Search.focusLast',
|
|
2141
|
-
when: FocusSearchResults
|
|
2142
|
-
}, {
|
|
2143
|
-
key: CtrlCmd | KeyC,
|
|
2144
|
-
command: 'Search.copy',
|
|
2145
|
-
when: FocusSearchResults
|
|
2146
|
-
}, {
|
|
2147
|
-
key: Enter,
|
|
2148
|
-
command: 'Search.submit',
|
|
2149
|
-
when: FocusSearchInput
|
|
2150
|
-
}, {
|
|
2151
|
-
key: Enter,
|
|
2152
|
-
command: 'Search.submit',
|
|
2153
|
-
when: FocusSearchReplaceInput
|
|
2154
|
-
}];
|
|
1879
|
+
const textSearch$5 = async (scheme, root, query, options, assetDir) => {
|
|
1880
|
+
return invoke$2('ExtensionHostTextSearch.textSearchFetch', scheme, root, query, options, assetDir);
|
|
2155
1881
|
};
|
|
2156
1882
|
|
|
2157
|
-
const
|
|
2158
|
-
|
|
2159
|
-
const ListFlat = 'ListFlat';
|
|
2160
|
-
const NewFile = 'NewFile';
|
|
2161
|
-
const Refresh = 'Refresh';
|
|
2162
|
-
|
|
2163
|
-
const getActions = () => {
|
|
2164
|
-
return [{
|
|
2165
|
-
type: Button$1,
|
|
2166
|
-
id: refresh$1(),
|
|
2167
|
-
icon: Refresh,
|
|
2168
|
-
command: 'refresh'
|
|
2169
|
-
}, {
|
|
2170
|
-
type: Button$1,
|
|
2171
|
-
id: clearSearchResults(),
|
|
2172
|
-
icon: ClearAll,
|
|
2173
|
-
command: 'clearSearchResults'
|
|
2174
|
-
}, {
|
|
2175
|
-
type: Button$1,
|
|
2176
|
-
id: openNewSearchEditor(),
|
|
2177
|
-
icon: NewFile,
|
|
2178
|
-
command: ''
|
|
2179
|
-
}, {
|
|
2180
|
-
type: Button$1,
|
|
2181
|
-
id: viewAsTree(),
|
|
2182
|
-
icon: ListFlat,
|
|
2183
|
-
command: ''
|
|
2184
|
-
}, {
|
|
2185
|
-
type: Button$1,
|
|
2186
|
-
id: collapseAll(),
|
|
2187
|
-
icon: CollapseAll,
|
|
2188
|
-
command: ''
|
|
2189
|
-
}];
|
|
1883
|
+
const textSearch$4 = async (scheme, root, query) => {
|
|
1884
|
+
return invoke$2('ExtensionHostTextSearch.textSearchHtml', scheme, root, query);
|
|
2190
1885
|
};
|
|
2191
1886
|
|
|
2192
|
-
const
|
|
2193
|
-
|
|
2194
|
-
|
|
1887
|
+
const textSearch$3 = async (scheme, root, query, options, assetDir) => {
|
|
1888
|
+
return invoke$2('ExtensionHostTextSearch.textSearchMemory', scheme, root, query, options, assetDir);
|
|
1889
|
+
};
|
|
2195
1890
|
|
|
2196
|
-
const
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
if (expanded === Expanded || expanded === Collapsed) {
|
|
2209
|
-
childCount += 2;
|
|
1891
|
+
const getRipGrepArgs = ({
|
|
1892
|
+
threads,
|
|
1893
|
+
isCaseSensitive,
|
|
1894
|
+
searchString,
|
|
1895
|
+
useRegularExpression
|
|
1896
|
+
}) => {
|
|
1897
|
+
const ripGrepArgs = ['--hidden', '--no-require-git', '--smart-case', '--stats', '--json'];
|
|
1898
|
+
ripGrepArgs.push('--threads', `${threads}`);
|
|
1899
|
+
if (isCaseSensitive) {
|
|
1900
|
+
ripGrepArgs.push('--case-sensitive');
|
|
1901
|
+
} else {
|
|
1902
|
+
ripGrepArgs.push('--ignore-case');
|
|
2210
1903
|
}
|
|
2211
|
-
if (
|
|
2212
|
-
|
|
1904
|
+
if (useRegularExpression) {
|
|
1905
|
+
ripGrepArgs.push('--regexp', searchString);
|
|
1906
|
+
} else {
|
|
1907
|
+
ripGrepArgs.push('--fixed-strings');
|
|
1908
|
+
ripGrepArgs.push('--');
|
|
1909
|
+
ripGrepArgs.push(searchString);
|
|
2213
1910
|
}
|
|
2214
|
-
|
|
2215
|
-
return
|
|
1911
|
+
ripGrepArgs.push('.');
|
|
1912
|
+
return ripGrepArgs;
|
|
2216
1913
|
};
|
|
2217
1914
|
|
|
2218
|
-
|
|
2219
|
-
const
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
const
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
return
|
|
1915
|
+
const Electron = 2;
|
|
1916
|
+
const Remote = 3;
|
|
1917
|
+
|
|
1918
|
+
const Https = 'https:';
|
|
1919
|
+
const Ws = 'ws:';
|
|
1920
|
+
const Wss = 'wss:';
|
|
1921
|
+
|
|
1922
|
+
const getWebSocketProtocol = locationProtocol => {
|
|
1923
|
+
return locationProtocol === Https ? Wss : Ws;
|
|
2227
1924
|
};
|
|
2228
1925
|
|
|
2229
|
-
const
|
|
2230
|
-
const
|
|
2231
|
-
|
|
2232
|
-
const baseName = pathBaseName(path);
|
|
2233
|
-
const index = originalResults.indexOf(results[i]);
|
|
2234
|
-
const matchCount = getMatchCount(results, index);
|
|
2235
|
-
const expanded = collapsedPaths.includes(path) ? Collapsed : Expanded;
|
|
2236
|
-
const childCount = getChildCount(expanded, matchCount);
|
|
2237
|
-
const badgeText = `${matchCount}`;
|
|
2238
|
-
return {
|
|
2239
|
-
badgeText,
|
|
2240
|
-
childCount,
|
|
2241
|
-
depth: 0,
|
|
2242
|
-
expanded,
|
|
2243
|
-
focused,
|
|
2244
|
-
icon: fileIcons[relativeIndex],
|
|
2245
|
-
matchLength: 0,
|
|
2246
|
-
matchStart: 0,
|
|
2247
|
-
posInSet,
|
|
2248
|
-
replacement: '',
|
|
2249
|
-
setSize,
|
|
2250
|
-
text: baseName,
|
|
2251
|
-
title: absolutePath
|
|
2252
|
-
};
|
|
1926
|
+
const getWebSocketUrl = (type, host, locationProtocol) => {
|
|
1927
|
+
const wsProtocol = getWebSocketProtocol(locationProtocol);
|
|
1928
|
+
return `${wsProtocol}//${host}/websocket/${type}`;
|
|
2253
1929
|
};
|
|
2254
1930
|
|
|
2255
|
-
const
|
|
2256
|
-
return
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
expanded: None,
|
|
2261
|
-
focused,
|
|
2262
|
-
icon: '',
|
|
2263
|
-
matchLength: searchTermLength,
|
|
2264
|
-
matchStart: start,
|
|
2265
|
-
posInSet,
|
|
2266
|
-
replacement,
|
|
2267
|
-
setSize,
|
|
2268
|
-
text: text,
|
|
2269
|
-
title: text
|
|
2270
|
-
};
|
|
1931
|
+
const getHost = () => {
|
|
1932
|
+
return location.host;
|
|
1933
|
+
};
|
|
1934
|
+
const getProtocol = () => {
|
|
1935
|
+
return location.protocol;
|
|
2271
1936
|
};
|
|
2272
1937
|
|
|
2273
|
-
const
|
|
2274
|
-
const
|
|
2275
|
-
const
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
switch (type) {
|
|
2284
|
-
case File:
|
|
2285
|
-
return getSearchDisplayResultFile(results, fileIcons, i, setSize, collapsedPaths, text, posInSet, relativeIndex, focused, originalResults);
|
|
2286
|
-
case Match:
|
|
2287
|
-
return getDisplayResultMatch(setSize, searchTermLength, replacement, text, posInSet, start, focused);
|
|
2288
|
-
default:
|
|
2289
|
-
throw new Error('unexpected search result type');
|
|
2290
|
-
}
|
|
1938
|
+
const launchSearchProcess = async () => {
|
|
1939
|
+
const host = getHost();
|
|
1940
|
+
const protocol = getProtocol();
|
|
1941
|
+
const wsUrl = getWebSocketUrl('search-process', host, protocol);
|
|
1942
|
+
const webSocket = new WebSocket(wsUrl);
|
|
1943
|
+
const rpc = await WebSocketRpcParent.create({
|
|
1944
|
+
webSocket,
|
|
1945
|
+
commandMap: {}
|
|
1946
|
+
});
|
|
1947
|
+
return rpc;
|
|
2291
1948
|
};
|
|
2292
1949
|
|
|
2293
|
-
const
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
1950
|
+
const state$1 = {
|
|
1951
|
+
rpc: undefined
|
|
1952
|
+
};
|
|
1953
|
+
const getOrCreate$1 = () => {
|
|
1954
|
+
if (!state$1.rpc) {
|
|
1955
|
+
// @ts-ignore
|
|
1956
|
+
state$1.rpc = launchSearchProcess();
|
|
2300
1957
|
}
|
|
2301
|
-
return
|
|
1958
|
+
return state$1.rpc;
|
|
2302
1959
|
};
|
|
2303
1960
|
|
|
2304
|
-
const
|
|
2305
|
-
const
|
|
2306
|
-
|
|
2307
|
-
const HandleHeaderFocusIn = 'handleHeaderFocusIn';
|
|
2308
|
-
const HandleIncludeInput = 'handleIncludeInput';
|
|
2309
|
-
const HandleInput = 'handleInput';
|
|
2310
|
-
const HandleListBlur = 'handleListBlur';
|
|
2311
|
-
const HandleReplaceInput = 'handleReplaceInput';
|
|
2312
|
-
const HandleScrollBarPointerDown = 'handleScrollBarPointerDown';
|
|
2313
|
-
const HandleToggleButtonClick = 'handleToggleButtonClick';
|
|
2314
|
-
const HandleWheel = 'handleWheel';
|
|
2315
|
-
const HandleListFocus = 'handleListFocus';
|
|
2316
|
-
const HandleContextMenu = 'handleContextMenu';
|
|
2317
|
-
|
|
2318
|
-
const FilesToExclude = 'FilesToExclude';
|
|
2319
|
-
const FilesToInclude = 'FilesToInclude';
|
|
2320
|
-
const MatchCase = 'MatchCase';
|
|
2321
|
-
const MatchWholeWord = 'MatchWholeWord';
|
|
2322
|
-
const PreserveCase = 'PreserveCase';
|
|
2323
|
-
const ReplaceAll = 'ReplaceAll';
|
|
2324
|
-
const ReplaceValue = 'ReplaceValue';
|
|
2325
|
-
const SearchOnlyOpenEditors = 'SearchOnlyOpenEditors';
|
|
2326
|
-
const SearchValue = 'SearchValue';
|
|
2327
|
-
const ToggleReplace = 'ToggleReplace';
|
|
2328
|
-
const ToggleSearchDetails = 'ToggleSearchDetails';
|
|
2329
|
-
const UseExcludeSettings = 'UseExcludeSettings';
|
|
2330
|
-
const UseRegularExpression = 'UseRegularExpression';
|
|
2331
|
-
|
|
2332
|
-
const getSearchDetailsToggleVirtualDom = () => {
|
|
2333
|
-
return [{
|
|
2334
|
-
type: Div,
|
|
2335
|
-
className: ToggleDetails,
|
|
2336
|
-
role: Button$2,
|
|
2337
|
-
tabIndex: 0,
|
|
2338
|
-
ariaLabel: toggleSearchDetails(),
|
|
2339
|
-
title: toggleSearchDetails(),
|
|
2340
|
-
name: ToggleSearchDetails,
|
|
2341
|
-
childCount: 1
|
|
2342
|
-
}, {
|
|
2343
|
-
type: Div,
|
|
2344
|
-
className: mergeClassNames(MaskIcon, MaskIconEllipsis),
|
|
2345
|
-
childCount: 0
|
|
2346
|
-
}];
|
|
1961
|
+
const invoke$1 = async (method, ...params) => {
|
|
1962
|
+
const rpc = await getOrCreate$1();
|
|
1963
|
+
return rpc.invoke(method, ...params);
|
|
2347
1964
|
};
|
|
2348
1965
|
|
|
2349
|
-
const
|
|
1966
|
+
const getPortTuple = () => {
|
|
1967
|
+
const {
|
|
1968
|
+
port1,
|
|
1969
|
+
port2
|
|
1970
|
+
} = new MessageChannel();
|
|
2350
1971
|
return {
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
childCount: 0
|
|
1972
|
+
port1,
|
|
1973
|
+
port2
|
|
2354
1974
|
};
|
|
2355
1975
|
};
|
|
2356
1976
|
|
|
2357
|
-
const
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
1977
|
+
const launchSearchProcessElectron = async () => {
|
|
1978
|
+
const {
|
|
1979
|
+
port1,
|
|
1980
|
+
port2
|
|
1981
|
+
} = getPortTuple();
|
|
1982
|
+
const rpcPromise = MessagePortRpcParent.create({
|
|
1983
|
+
messagePort: port2,
|
|
1984
|
+
commandMap: {},
|
|
1985
|
+
isMessagePortOpen: true
|
|
1986
|
+
});
|
|
1987
|
+
await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port1, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
|
|
1988
|
+
port2.start();
|
|
1989
|
+
const rpc = await rpcPromise;
|
|
1990
|
+
return rpc;
|
|
2371
1991
|
};
|
|
2372
1992
|
|
|
2373
|
-
const
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
1993
|
+
const state = {
|
|
1994
|
+
rpc: undefined
|
|
1995
|
+
};
|
|
1996
|
+
const getOrCreate = () => {
|
|
1997
|
+
if (!state.rpc) {
|
|
1998
|
+
// @ts-ignore
|
|
1999
|
+
state.rpc = launchSearchProcessElectron();
|
|
2000
|
+
}
|
|
2001
|
+
return state.rpc;
|
|
2379
2002
|
};
|
|
2380
2003
|
|
|
2381
|
-
const
|
|
2382
|
-
const
|
|
2383
|
-
|
|
2384
|
-
|
|
2004
|
+
const invoke = async (method, ...params) => {
|
|
2005
|
+
const rpc = await getOrCreate();
|
|
2006
|
+
return rpc.invoke(method, ...params);
|
|
2007
|
+
};
|
|
2385
2008
|
|
|
2386
|
-
const
|
|
2387
|
-
const
|
|
2388
|
-
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
const outside = [];
|
|
2395
|
-
return {
|
|
2396
|
-
inside,
|
|
2397
|
-
outside
|
|
2398
|
-
};
|
|
2399
|
-
};
|
|
2400
|
-
|
|
2401
|
-
const getInputActionsInclude = flags => {
|
|
2402
|
-
const inside = [{
|
|
2403
|
-
icon: MaskIconBook,
|
|
2404
|
-
title: searchOnlyOpenEditors(),
|
|
2405
|
-
command: 'searchOnlyOpenEditors',
|
|
2406
|
-
flag: flags & OpenEditors ? CheckBoxEnabled : CheckBoxDisabled,
|
|
2407
|
-
name: SearchOnlyOpenEditors
|
|
2408
|
-
}];
|
|
2409
|
-
const outside = [];
|
|
2410
|
-
return {
|
|
2411
|
-
inside,
|
|
2412
|
-
outside
|
|
2009
|
+
const textSearch$2 = async (scheme, root, query, options, assetDir, platform) => {
|
|
2010
|
+
const ripGrepArgs = getRipGrepArgs({
|
|
2011
|
+
...options,
|
|
2012
|
+
searchString: query
|
|
2013
|
+
});
|
|
2014
|
+
const actualOptions = {
|
|
2015
|
+
ripGrepArgs,
|
|
2016
|
+
searchDir: root
|
|
2413
2017
|
};
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
};
|
|
2419
|
-
|
|
2420
|
-
// TODO maybe move logic to viewmodel, which returns ariaChecked 1 | 2 | 3
|
|
2421
|
-
const getAriaChecked = flag => {
|
|
2422
|
-
switch (flag) {
|
|
2423
|
-
case CheckBoxEnabled:
|
|
2424
|
-
return true;
|
|
2425
|
-
case CheckBoxDisabled:
|
|
2426
|
-
return false;
|
|
2427
|
-
default:
|
|
2428
|
-
return undefined;
|
|
2018
|
+
if (platform === Remote) {
|
|
2019
|
+
const result = await invoke$1('TextSearch.search', actualOptions);
|
|
2020
|
+
// TODO api is weird
|
|
2021
|
+
return result.results;
|
|
2429
2022
|
}
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
const getRole = flag => {
|
|
2434
|
-
switch (flag) {
|
|
2435
|
-
case CheckBoxEnabled:
|
|
2436
|
-
case CheckBoxDisabled:
|
|
2437
|
-
return CheckBox;
|
|
2438
|
-
default:
|
|
2439
|
-
return undefined;
|
|
2023
|
+
if (platform === Electron) {
|
|
2024
|
+
const result = await invoke('TextSearch.search', actualOptions);
|
|
2025
|
+
return result.results;
|
|
2440
2026
|
}
|
|
2027
|
+
const results = await invoke$2('SearchProcess.invoke', 'TextSearch.search', actualOptions);
|
|
2028
|
+
// TODO api is weird
|
|
2029
|
+
return results.results;
|
|
2441
2030
|
};
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2031
|
+
|
|
2032
|
+
const textSearch$1 = (scheme, root, query) => {
|
|
2033
|
+
// TODO ask renderer worker for files
|
|
2034
|
+
const entries = Object.entries({});
|
|
2035
|
+
const results = [];
|
|
2036
|
+
for (const [key, value] of entries) {
|
|
2037
|
+
// @ts-ignore
|
|
2038
|
+
if (value.includes(query)) {
|
|
2039
|
+
results.push([key, [{
|
|
2040
|
+
absoluteOffset: 0,
|
|
2041
|
+
preview: value
|
|
2042
|
+
}]]);
|
|
2043
|
+
}
|
|
2448
2044
|
}
|
|
2449
|
-
|
|
2450
|
-
const getSearchFieldButtonVirtualDom = button => {
|
|
2451
|
-
const {
|
|
2452
|
-
icon,
|
|
2453
|
-
title,
|
|
2454
|
-
name,
|
|
2455
|
-
flag
|
|
2456
|
-
} = button;
|
|
2457
|
-
const ariaChecked = getAriaChecked(flag);
|
|
2458
|
-
const role = getRole(flag);
|
|
2459
|
-
const disabled = getDisabled(flag);
|
|
2460
|
-
return [{
|
|
2461
|
-
type: Button,
|
|
2462
|
-
className: getSearchFieldButtonClassName(flag),
|
|
2463
|
-
name,
|
|
2464
|
-
title,
|
|
2465
|
-
role,
|
|
2466
|
-
ariaChecked,
|
|
2467
|
-
disabled,
|
|
2468
|
-
tabIndex: 0,
|
|
2469
|
-
childCount: 1
|
|
2470
|
-
}, {
|
|
2471
|
-
type: Span,
|
|
2472
|
-
className: mergeClassNames(MaskIcon, icon),
|
|
2473
|
-
childCount: 0
|
|
2474
|
-
}];
|
|
2045
|
+
return results;
|
|
2475
2046
|
};
|
|
2476
2047
|
|
|
2477
|
-
const
|
|
2478
|
-
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2048
|
+
const getProvider = scheme => {
|
|
2049
|
+
switch (scheme) {
|
|
2050
|
+
case '':
|
|
2051
|
+
return textSearch$2;
|
|
2052
|
+
case 'web':
|
|
2053
|
+
return textSearch$1;
|
|
2054
|
+
case 'fetch':
|
|
2055
|
+
return textSearch$5;
|
|
2056
|
+
case 'html':
|
|
2057
|
+
return textSearch$4;
|
|
2058
|
+
case 'memfs':
|
|
2059
|
+
return textSearch$3;
|
|
2060
|
+
default:
|
|
2061
|
+
return textSearch$6;
|
|
2483
2062
|
}
|
|
2484
|
-
return {
|
|
2485
|
-
preNodes: [{
|
|
2486
|
-
type: Div,
|
|
2487
|
-
className: SearchFieldContainer,
|
|
2488
|
-
role: None$1,
|
|
2489
|
-
childCount: 1 + outsideButtons.length
|
|
2490
|
-
}],
|
|
2491
|
-
postNodes: outsideButtons.flatMap(getSearchFieldButtonVirtualDom)
|
|
2492
|
-
};
|
|
2493
2063
|
};
|
|
2494
2064
|
|
|
2495
|
-
const
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
const
|
|
2501
|
-
|
|
2502
|
-
type: Div,
|
|
2503
|
-
className: searchFieldClassName,
|
|
2504
|
-
role: None$1,
|
|
2505
|
-
childCount: 2
|
|
2506
|
-
}, {
|
|
2507
|
-
type: TextArea,
|
|
2508
|
-
className: MultilineInputBox,
|
|
2509
|
-
spellcheck: false,
|
|
2510
|
-
autocapitalize: 'off',
|
|
2511
|
-
autocorrect: 'off',
|
|
2512
|
-
placeholder,
|
|
2513
|
-
name,
|
|
2514
|
-
onInput,
|
|
2515
|
-
onFocus,
|
|
2516
|
-
childCount: 0
|
|
2517
|
-
}, {
|
|
2518
|
-
type: Div,
|
|
2519
|
-
className: SearchFieldButtons,
|
|
2520
|
-
childCount: insideButtons.length
|
|
2521
|
-
}, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom), ...postNodes];
|
|
2522
|
-
return dom;
|
|
2065
|
+
const textSearch = async (root, query, options, assetDir, platform) => {
|
|
2066
|
+
string(root);
|
|
2067
|
+
string(query);
|
|
2068
|
+
const scheme = getProtocol$1(root);
|
|
2069
|
+
const provider = getProvider(scheme);
|
|
2070
|
+
const results = await provider(scheme, root, query, options, assetDir, platform);
|
|
2071
|
+
return results;
|
|
2523
2072
|
};
|
|
2524
2073
|
|
|
2525
|
-
|
|
2526
|
-
const includeButtons = getInputActionsInclude(flags);
|
|
2527
|
-
const excludeButtons = getInputActionsExclude(flags);
|
|
2528
|
-
return [{
|
|
2529
|
-
type: Div,
|
|
2530
|
-
className: SearchHeaderDetailsExpanded,
|
|
2531
|
-
childCount: 5
|
|
2532
|
-
}, {
|
|
2533
|
-
type: Div,
|
|
2534
|
-
className: SearchHeaderDetailsExpandedTop,
|
|
2535
|
-
childCount: 2
|
|
2536
|
-
}, ...getSearchDetailsToggleVirtualDom(), {
|
|
2537
|
-
type: H4,
|
|
2538
|
-
className: SearchHeaderDetailsHeading,
|
|
2539
|
-
childCount: 1
|
|
2540
|
-
}, text(filesToInclude()), ...getSearchFieldVirtualDom(FilesToInclude, 'Include', HandleIncludeInput, includeButtons.inside, includeButtons.outside), {
|
|
2541
|
-
type: H4,
|
|
2542
|
-
className: SearchHeaderDetailsHeading,
|
|
2543
|
-
childCount: 1
|
|
2544
|
-
}, text(filesToExclude()), ...getSearchFieldVirtualDom(FilesToExclude, 'Exclude', HandleExcludeInput, excludeButtons.inside, excludeButtons.outside), ...getSearchMessageVirtualDom(message, false)];
|
|
2545
|
-
};
|
|
2074
|
+
// Based on https://github.com/microsoft/vscode/blob/ad375c92764b72a1f28f3e1626563e9e41e5c740/src/vs/workbench/contrib/search/browser/searchWidget.ts#L393 by Microsoft (License MIT)
|
|
2546
2075
|
|
|
2547
|
-
const
|
|
2548
|
-
if (
|
|
2549
|
-
return
|
|
2076
|
+
const validateSearchInput = (value, flags) => {
|
|
2077
|
+
if (!value) {
|
|
2078
|
+
return '';
|
|
2550
2079
|
}
|
|
2551
|
-
|
|
2080
|
+
if (!(flags & UseRegularExpression$2)) {
|
|
2081
|
+
return '';
|
|
2082
|
+
}
|
|
2083
|
+
try {
|
|
2084
|
+
new RegExp(value, 'u');
|
|
2085
|
+
} catch (error) {
|
|
2086
|
+
if (error && error instanceof Error) {
|
|
2087
|
+
return error.message;
|
|
2088
|
+
}
|
|
2089
|
+
return '';
|
|
2090
|
+
}
|
|
2091
|
+
return '';
|
|
2552
2092
|
};
|
|
2553
2093
|
|
|
2554
|
-
const
|
|
2555
|
-
const
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
title: matchCase(),
|
|
2559
|
-
name: MatchCase
|
|
2560
|
-
}, {
|
|
2561
|
-
icon: MaskIconWholeWord,
|
|
2562
|
-
flag: flags & MatchWholeWord$2 ? CheckBoxEnabled : CheckBoxDisabled,
|
|
2563
|
-
title: matchWholeWord(),
|
|
2564
|
-
name: MatchWholeWord
|
|
2565
|
-
}, {
|
|
2566
|
-
icon: MaskIconRegex,
|
|
2567
|
-
flag: flags & UseRegularExpression$2 ? CheckBoxEnabled : CheckBoxDisabled,
|
|
2568
|
-
title: useRegularExpression(),
|
|
2569
|
-
name: UseRegularExpression
|
|
2570
|
-
}];
|
|
2571
|
-
const outside = [];
|
|
2572
|
-
return {
|
|
2573
|
-
inside,
|
|
2574
|
-
outside
|
|
2575
|
-
};
|
|
2576
|
-
};
|
|
2577
|
-
|
|
2578
|
-
const getInputActionsReplace = (flags, matchCount) => {
|
|
2579
|
-
const inside = [{
|
|
2580
|
-
icon: MaskIconPreserveCase,
|
|
2581
|
-
flag: flags & PreserveCase$2 ? CheckBoxEnabled : CheckBoxDisabled,
|
|
2582
|
-
title: preserveCase(),
|
|
2583
|
-
name: PreserveCase
|
|
2584
|
-
}];
|
|
2585
|
-
const outside = [{
|
|
2586
|
-
icon: MaskIconReplaceAll,
|
|
2587
|
-
flag: matchCount === 0 ? ButtonDisabled : ButtonEnabled,
|
|
2588
|
-
title: replaceAll$1(),
|
|
2589
|
-
name: ReplaceAll
|
|
2590
|
-
}];
|
|
2591
|
-
return {
|
|
2592
|
-
inside,
|
|
2593
|
-
outside
|
|
2094
|
+
const handleUpdate = async (state, update) => {
|
|
2095
|
+
const partialNewState = {
|
|
2096
|
+
...state,
|
|
2097
|
+
...update
|
|
2594
2098
|
};
|
|
2099
|
+
try {
|
|
2100
|
+
const {
|
|
2101
|
+
height,
|
|
2102
|
+
itemHeight,
|
|
2103
|
+
minimumSliderSize,
|
|
2104
|
+
headerHeight,
|
|
2105
|
+
flags,
|
|
2106
|
+
value,
|
|
2107
|
+
threads,
|
|
2108
|
+
includeValue,
|
|
2109
|
+
excludeValue
|
|
2110
|
+
} = partialNewState;
|
|
2111
|
+
if (isEmptyString(value)) {
|
|
2112
|
+
return {
|
|
2113
|
+
...partialNewState,
|
|
2114
|
+
minLineY: 0,
|
|
2115
|
+
maxLineY: 0,
|
|
2116
|
+
deltaY: 0,
|
|
2117
|
+
items: [],
|
|
2118
|
+
listItems: [],
|
|
2119
|
+
matchCount: 0,
|
|
2120
|
+
message: '',
|
|
2121
|
+
loaded: true,
|
|
2122
|
+
searchInputErrorMessage: ''
|
|
2123
|
+
};
|
|
2124
|
+
}
|
|
2125
|
+
const searchInputErrorMessage = validateSearchInput(value, flags);
|
|
2126
|
+
if (searchInputErrorMessage) {
|
|
2127
|
+
return {
|
|
2128
|
+
...partialNewState,
|
|
2129
|
+
searchInputErrorMessage: searchInputErrorMessage
|
|
2130
|
+
};
|
|
2131
|
+
}
|
|
2132
|
+
const root = state.workspacePath;
|
|
2133
|
+
const scheme = getProtocol$1(root);
|
|
2134
|
+
const results = await textSearch(root, value, {
|
|
2135
|
+
threads,
|
|
2136
|
+
isCaseSensitive: Boolean(flags & MatchCase$2),
|
|
2137
|
+
useRegularExpression: Boolean(flags & UseRegularExpression$2),
|
|
2138
|
+
exclude: excludeValue,
|
|
2139
|
+
include: includeValue,
|
|
2140
|
+
assetDir: state.assetDir,
|
|
2141
|
+
root,
|
|
2142
|
+
query: value,
|
|
2143
|
+
scheme,
|
|
2144
|
+
flags,
|
|
2145
|
+
matchWholeWord: Boolean(flags & MatchWholeWord$2)
|
|
2146
|
+
}, state.assetDir, state.platform);
|
|
2147
|
+
if (!Array.isArray(results)) {
|
|
2148
|
+
throw new TypeError('results must be of type array');
|
|
2149
|
+
}
|
|
2150
|
+
const {
|
|
2151
|
+
fileCount,
|
|
2152
|
+
resultCount
|
|
2153
|
+
} = getTextSearchResultCounts(results);
|
|
2154
|
+
const message = getStatusMessage(resultCount, fileCount);
|
|
2155
|
+
const total = results.length;
|
|
2156
|
+
const contentHeight = total * itemHeight;
|
|
2157
|
+
const listHeight = height - headerHeight;
|
|
2158
|
+
const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
|
|
2159
|
+
const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
|
|
2160
|
+
const maxLineY = Math.min(numberOfVisible, total);
|
|
2161
|
+
const finalDeltaY = Math.max(contentHeight - listHeight, 0);
|
|
2162
|
+
const visible = results.slice(0, maxLineY);
|
|
2163
|
+
const icons = await getFileIcons(visible);
|
|
2164
|
+
return {
|
|
2165
|
+
...partialNewState,
|
|
2166
|
+
minLineY: 0,
|
|
2167
|
+
deltaY: 0,
|
|
2168
|
+
value,
|
|
2169
|
+
items: results,
|
|
2170
|
+
listItems: results,
|
|
2171
|
+
message,
|
|
2172
|
+
maxLineY: maxLineY,
|
|
2173
|
+
scrollBarHeight,
|
|
2174
|
+
finalDeltaY,
|
|
2175
|
+
threads,
|
|
2176
|
+
fileCount,
|
|
2177
|
+
matchCount: resultCount,
|
|
2178
|
+
loaded: true,
|
|
2179
|
+
icons,
|
|
2180
|
+
searchInputErrorMessage: ''
|
|
2181
|
+
};
|
|
2182
|
+
} catch (error) {
|
|
2183
|
+
handleError(error);
|
|
2184
|
+
return {
|
|
2185
|
+
...partialNewState,
|
|
2186
|
+
message: `${error}`,
|
|
2187
|
+
items: [],
|
|
2188
|
+
listItems: [],
|
|
2189
|
+
matchCount: 0,
|
|
2190
|
+
fileCount: 0,
|
|
2191
|
+
minLineY: 0,
|
|
2192
|
+
maxLineY: 0
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2595
2195
|
};
|
|
2596
2196
|
|
|
2597
|
-
const
|
|
2598
|
-
return
|
|
2599
|
-
|
|
2600
|
-
|
|
2601
|
-
|
|
2602
|
-
ariaLabel: toggleReplace$1(),
|
|
2603
|
-
ariaExpanded: Boolean(flags & ReplaceExpanded),
|
|
2604
|
-
childCount: 1,
|
|
2605
|
-
'data-command': 'toggleReplace',
|
|
2606
|
-
name: ToggleReplace
|
|
2607
|
-
}, {
|
|
2608
|
-
type: Div,
|
|
2609
|
-
className: mergeClassNames(MaskIcon, flags & ReplaceExpanded ? MaskIconChevronDown : MaskIconChevronRight),
|
|
2610
|
-
childCount: 0
|
|
2611
|
-
}];
|
|
2197
|
+
const handleExcludeInput = (state, value, inputSource = Script) => {
|
|
2198
|
+
return handleUpdate(state, {
|
|
2199
|
+
excludeValue: value,
|
|
2200
|
+
inputSource
|
|
2201
|
+
});
|
|
2612
2202
|
};
|
|
2613
2203
|
|
|
2614
|
-
const
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
}, ...getSearchFieldVirtualDom(SearchValue, 'Search', HandleInput, inputActions.inside, inputActions.outside, '', Boolean(searchInputErrorMessage))];
|
|
2628
|
-
if (flags & ReplaceExpanded) {
|
|
2629
|
-
dom.push(...getSearchFieldVirtualDom(ReplaceValue, 'Replace', HandleReplaceInput, replaceActions.inside, replaceActions.outside));
|
|
2630
|
-
}
|
|
2631
|
-
return dom;
|
|
2632
|
-
};
|
|
2204
|
+
const FilesToExclude = 'FilesToExclude';
|
|
2205
|
+
const FilesToInclude = 'FilesToInclude';
|
|
2206
|
+
const MatchCase = 'MatchCase';
|
|
2207
|
+
const MatchWholeWord = 'MatchWholeWord';
|
|
2208
|
+
const PreserveCase = 'PreserveCase';
|
|
2209
|
+
const ReplaceAll = 'ReplaceAll';
|
|
2210
|
+
const ReplaceValue = 'ReplaceValue';
|
|
2211
|
+
const SearchOnlyOpenEditors = 'SearchOnlyOpenEditors';
|
|
2212
|
+
const SearchValue = 'SearchValue';
|
|
2213
|
+
const ToggleReplace = 'ToggleReplace';
|
|
2214
|
+
const ToggleSearchDetails = 'ToggleSearchDetails';
|
|
2215
|
+
const UseExcludeSettings = 'UseExcludeSettings';
|
|
2216
|
+
const UseRegularExpression = 'UseRegularExpression';
|
|
2633
2217
|
|
|
2634
|
-
const
|
|
2635
|
-
|
|
2636
|
-
className: SearchHeader,
|
|
2637
|
-
role: None$1,
|
|
2638
|
-
childCount: 2,
|
|
2639
|
-
onClick: HandleHeaderClick2,
|
|
2640
|
-
onFocusIn: HandleHeaderFocusIn
|
|
2641
|
-
};
|
|
2642
|
-
const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage, matchCount) => {
|
|
2643
|
-
const dom = [parentNode, ...getSearchHeaderTopVirtualDom(flags, searchInputErrorMessage, matchCount), ...getSearchHeaderDetailsVirtualDom(flags, message)];
|
|
2644
|
-
return dom;
|
|
2218
|
+
const noop = state => {
|
|
2219
|
+
return state;
|
|
2645
2220
|
};
|
|
2646
2221
|
|
|
2647
|
-
const
|
|
2648
|
-
|
|
2649
|
-
return [];
|
|
2650
|
-
}
|
|
2651
|
-
return [{
|
|
2652
|
-
type: Div,
|
|
2653
|
-
className: SearchInputError,
|
|
2654
|
-
role: Alert,
|
|
2655
|
-
childCount: 1
|
|
2656
|
-
}, text(errorMessage)];
|
|
2222
|
+
const applyBulkReplacement = async bulkEdits => {
|
|
2223
|
+
await invoke$2('BulkReplacement.applyBulkReplacement', bulkEdits);
|
|
2657
2224
|
};
|
|
2658
2225
|
|
|
2659
|
-
const
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
if (scrollBarHeight === 0) {
|
|
2663
|
-
return [];
|
|
2226
|
+
const getReplacedMessage = (fileCount, replaceCount, replacement) => {
|
|
2227
|
+
if (replaceCount === 1) {
|
|
2228
|
+
return replacedOneOccurrenceInOneFile(replacement);
|
|
2664
2229
|
}
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
onPointerDown: HandleScrollBarPointerDown,
|
|
2670
|
-
role: ScrollBar$1,
|
|
2671
|
-
ariaControls: TreeItems,
|
|
2672
|
-
ariaValueNow: scrollBarValue
|
|
2673
|
-
}, {
|
|
2674
|
-
type: Div,
|
|
2675
|
-
className: ScrollBarThumb,
|
|
2676
|
-
height: scrollBarHeight,
|
|
2677
|
-
translate: `0 ${scrollBarY}px`,
|
|
2678
|
-
childCount: 0
|
|
2679
|
-
}];
|
|
2230
|
+
if (fileCount === 1) {
|
|
2231
|
+
return replacedManyOccurrencesInOneFile(replaceCount, replacement);
|
|
2232
|
+
}
|
|
2233
|
+
return replacedManyOccurrencesInManyFiles(replaceCount, fileCount, replacement);
|
|
2680
2234
|
};
|
|
2681
2235
|
|
|
2682
|
-
|
|
2683
|
-
//
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
case Collapsed:
|
|
2687
|
-
return 'false';
|
|
2688
|
-
case Expanded:
|
|
2689
|
-
return 'true';
|
|
2690
|
-
default:
|
|
2691
|
-
return undefined;
|
|
2236
|
+
const getFileName = text => {
|
|
2237
|
+
// TODO make api stricter so that results always have the same shape
|
|
2238
|
+
if (text.startsWith('./')) {
|
|
2239
|
+
return text.slice(2);
|
|
2692
2240
|
}
|
|
2241
|
+
return text;
|
|
2693
2242
|
};
|
|
2694
2243
|
|
|
2695
|
-
const
|
|
2696
|
-
|
|
2697
|
-
|
|
2244
|
+
const getReplaceElements = (items, workspacePath, replacement) => {
|
|
2245
|
+
let element = {
|
|
2246
|
+
uri: '',
|
|
2247
|
+
changes: []
|
|
2248
|
+
};
|
|
2249
|
+
const bulkChanges = [];
|
|
2250
|
+
let changes = [];
|
|
2251
|
+
// TODO simplify code by first matching files with their elements, then creating bulk edits
|
|
2252
|
+
for (const match of items) {
|
|
2253
|
+
const {
|
|
2254
|
+
type,
|
|
2255
|
+
text,
|
|
2256
|
+
lineNumber,
|
|
2257
|
+
end,
|
|
2258
|
+
start
|
|
2259
|
+
} = match;
|
|
2260
|
+
if (type === File) {
|
|
2261
|
+
changes = [];
|
|
2262
|
+
const fileName = getFileName(text);
|
|
2263
|
+
const absolutePath = `${workspacePath}/${fileName}`;
|
|
2264
|
+
element = {
|
|
2265
|
+
uri: absolutePath,
|
|
2266
|
+
changes
|
|
2267
|
+
};
|
|
2268
|
+
bulkChanges.push(element);
|
|
2269
|
+
} else {
|
|
2270
|
+
changes.push({
|
|
2271
|
+
text: replacement,
|
|
2272
|
+
startRowIndex: lineNumber - 1,
|
|
2273
|
+
startColumnIndex: start,
|
|
2274
|
+
endRowIndex: lineNumber,
|
|
2275
|
+
endColumnIndex: end
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2698
2278
|
}
|
|
2699
|
-
return
|
|
2700
|
-
type: Div,
|
|
2701
|
-
className: mergeClassNames(Badge, className),
|
|
2702
|
-
childCount: 1
|
|
2703
|
-
}, text(badgeText)];
|
|
2279
|
+
return bulkChanges;
|
|
2704
2280
|
};
|
|
2705
2281
|
|
|
2706
|
-
const
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
const getFileIconVirtualDom = icon => {
|
|
2282
|
+
const replaceAll = async state => {
|
|
2283
|
+
const {
|
|
2284
|
+
workspacePath,
|
|
2285
|
+
items,
|
|
2286
|
+
replacement,
|
|
2287
|
+
matchCount
|
|
2288
|
+
} = state;
|
|
2289
|
+
const bulkEdits = getReplaceElements(items, workspacePath, replacement);
|
|
2290
|
+
await applyBulkReplacement(bulkEdits);
|
|
2291
|
+
const fileCount = bulkEdits.length;
|
|
2292
|
+
const message = getReplacedMessage(fileCount, matchCount, replacement);
|
|
2718
2293
|
return {
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2294
|
+
...state,
|
|
2295
|
+
items: [],
|
|
2296
|
+
listItems: [],
|
|
2297
|
+
minLineY: 0,
|
|
2298
|
+
maxLineY: 0,
|
|
2299
|
+
message
|
|
2724
2300
|
};
|
|
2725
2301
|
};
|
|
2726
2302
|
|
|
2727
|
-
const
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
return [chevronDownVirtualDom, getFileIconVirtualDom(icon)];
|
|
2731
|
-
case Collapsed:
|
|
2732
|
-
return [chevronRightVirtualDom, getFileIconVirtualDom(icon)];
|
|
2733
|
-
default:
|
|
2734
|
-
return [];
|
|
2303
|
+
const toggleDetailsExpanded = state => {
|
|
2304
|
+
if (hasDetailsExpanded(state.flags)) {
|
|
2305
|
+
return collapseDetails(state);
|
|
2735
2306
|
}
|
|
2307
|
+
return expandDetails(state);
|
|
2736
2308
|
};
|
|
2737
2309
|
|
|
2738
|
-
const
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2310
|
+
const toggleSearchFlag = (state, flag) => {
|
|
2311
|
+
return handleUpdate(state, {
|
|
2312
|
+
flags: state.flags ^ flag
|
|
2313
|
+
});
|
|
2742
2314
|
};
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
childCount: 1
|
|
2315
|
+
|
|
2316
|
+
const toggleMatchCase = state => {
|
|
2317
|
+
return toggleSearchFlag(state, MatchCase$2);
|
|
2747
2318
|
};
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
|
|
2751
|
-
childCount: 1
|
|
2319
|
+
|
|
2320
|
+
const toggleMatchWholeWord = state => {
|
|
2321
|
+
return toggleSearchFlag(state, MatchWholeWord$2);
|
|
2752
2322
|
};
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
childCount: 1
|
|
2323
|
+
|
|
2324
|
+
const toggleOpenEditors = state => {
|
|
2325
|
+
return toggleSearchFlag(state, OpenEditors);
|
|
2757
2326
|
};
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2327
|
+
|
|
2328
|
+
const togglePreserveCase = state => {
|
|
2329
|
+
return toggleSearchFlag(state, PreserveCase$2);
|
|
2761
2330
|
};
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2331
|
+
|
|
2332
|
+
const toggleReplace = state => {
|
|
2333
|
+
return toggleSearchFlag(state, ReplaceExpanded);
|
|
2765
2334
|
};
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
const highlight = displayText.slice(matchStart, matchStart + matchLength);
|
|
2770
|
-
const after = displayText.slice(matchStart + matchLength);
|
|
2771
|
-
if (replacement) {
|
|
2772
|
-
return [label4, text(before), deleted, text(highlight), inserted, text(replacement), text(after)];
|
|
2773
|
-
}
|
|
2774
|
-
return [label3, text(before), highlighted, text(highlight), text(after)];
|
|
2775
|
-
}
|
|
2776
|
-
return [label1, text(displayText)];
|
|
2335
|
+
|
|
2336
|
+
const toggleUseIgnoreFiles = state => {
|
|
2337
|
+
return toggleSearchFlag(state, UseIgnoreFiles);
|
|
2777
2338
|
};
|
|
2778
2339
|
|
|
2779
|
-
const
|
|
2780
|
-
return
|
|
2340
|
+
const toggleUseRegularExpression = state => {
|
|
2341
|
+
return toggleSearchFlag(state, UseRegularExpression$2);
|
|
2781
2342
|
};
|
|
2782
2343
|
|
|
2783
|
-
const
|
|
2784
|
-
|
|
2785
|
-
|
|
2344
|
+
const getClickHandler = name => {
|
|
2345
|
+
switch (name) {
|
|
2346
|
+
case MatchCase:
|
|
2347
|
+
return toggleMatchCase;
|
|
2348
|
+
case ToggleReplace:
|
|
2349
|
+
return toggleReplace;
|
|
2350
|
+
case UseRegularExpression:
|
|
2351
|
+
return toggleUseRegularExpression;
|
|
2352
|
+
case ReplaceAll:
|
|
2353
|
+
return replaceAll;
|
|
2354
|
+
case MatchWholeWord:
|
|
2355
|
+
return toggleMatchWholeWord;
|
|
2356
|
+
case PreserveCase:
|
|
2357
|
+
return togglePreserveCase;
|
|
2358
|
+
case ToggleSearchDetails:
|
|
2359
|
+
return toggleDetailsExpanded;
|
|
2360
|
+
case SearchOnlyOpenEditors:
|
|
2361
|
+
return toggleOpenEditors;
|
|
2362
|
+
case UseExcludeSettings:
|
|
2363
|
+
return toggleUseIgnoreFiles;
|
|
2364
|
+
default:
|
|
2365
|
+
return noop;
|
|
2786
2366
|
}
|
|
2787
|
-
return TreeItem;
|
|
2788
2367
|
};
|
|
2789
2368
|
|
|
2790
|
-
const
|
|
2369
|
+
const handleHeaderClick = async (state, name) => {
|
|
2370
|
+
const fn = getClickHandler(name);
|
|
2371
|
+
return fn(state);
|
|
2372
|
+
};
|
|
2791
2373
|
|
|
2792
|
-
const
|
|
2793
|
-
|
|
2794
|
-
matchStart,
|
|
2795
|
-
matchLength,
|
|
2796
|
-
text: displayText,
|
|
2797
|
-
title,
|
|
2798
|
-
icon,
|
|
2799
|
-
setSize,
|
|
2800
|
-
posInSet,
|
|
2801
|
-
depth,
|
|
2802
|
-
replacement,
|
|
2803
|
-
focused,
|
|
2804
|
-
expanded,
|
|
2805
|
-
childCount,
|
|
2806
|
-
badgeText
|
|
2807
|
-
} = rowInfo;
|
|
2808
|
-
const dom = [{
|
|
2809
|
-
type: Div,
|
|
2810
|
-
role: TreeItem$1,
|
|
2811
|
-
className: getSearchResultClassName(focused),
|
|
2812
|
-
title,
|
|
2813
|
-
ariaSetSize: setSize,
|
|
2814
|
-
ariaLevel: depth,
|
|
2815
|
-
ariaPosInSet: posInSet,
|
|
2816
|
-
ariaLabel: title,
|
|
2817
|
-
ariaDescription: '',
|
|
2818
|
-
childCount,
|
|
2819
|
-
paddingLeft: getPaddingLeft(depth),
|
|
2820
|
-
paddingRight: PaddingRight,
|
|
2821
|
-
ariaExpanded: getAriaExpanded(expanded)
|
|
2822
|
-
}, ...getIconsVirtualDom(expanded, icon), ...getLabelVirtualDom(displayText, matchLength, matchStart, replacement), ...getBadgeVirtualDom(SourceControlBadge, badgeText), {
|
|
2823
|
-
type: Div,
|
|
2824
|
-
className: SearchRemove,
|
|
2825
|
-
childCount: 1
|
|
2826
|
-
}, {
|
|
2827
|
-
type: Div,
|
|
2828
|
-
className: CloseMaskIcon,
|
|
2829
|
-
childCount: 0
|
|
2830
|
-
}];
|
|
2831
|
-
return dom;
|
|
2374
|
+
const handleHeaderFocusIn = state => {
|
|
2375
|
+
return state;
|
|
2832
2376
|
};
|
|
2833
2377
|
|
|
2834
|
-
const
|
|
2835
|
-
const
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
}
|
|
2378
|
+
const handleIconThemeChange = async state => {
|
|
2379
|
+
const {
|
|
2380
|
+
items,
|
|
2381
|
+
minLineY,
|
|
2382
|
+
maxLineY
|
|
2383
|
+
} = state;
|
|
2384
|
+
const visibleItems = items.slice(minLineY, maxLineY);
|
|
2385
|
+
const icons = await getFileIcons(visibleItems);
|
|
2386
|
+
return {
|
|
2387
|
+
...state,
|
|
2388
|
+
icons
|
|
2389
|
+
};
|
|
2846
2390
|
};
|
|
2847
2391
|
|
|
2848
|
-
const
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2853
|
-
role: Tree$1,
|
|
2854
|
-
tabIndex: 0,
|
|
2855
|
-
childCount: 1 + scrollBarDomNodes
|
|
2856
|
-
}, ...getTreeItemsVirtualDom(visibleItems, deltaY, itemHeight), ...getScrollBarVirtualDom(scrollbarHeight, scrollBarY, scrollBarValue)];
|
|
2392
|
+
const handleIncludeInput = (state, includeValue, inputSource = Script) => {
|
|
2393
|
+
return handleUpdate(state, {
|
|
2394
|
+
includeValue,
|
|
2395
|
+
inputSource
|
|
2396
|
+
});
|
|
2857
2397
|
};
|
|
2858
2398
|
|
|
2859
|
-
const
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
className: mergeClassNames(Viewlet, Search$1),
|
|
2865
|
-
childCount
|
|
2866
|
-
}, ...getSearchHeaderVirtualDom(flags, message, searchInputErrorMessage, matchCount), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight)];
|
|
2399
|
+
const handleInput = (state, value, inputSource = Script) => {
|
|
2400
|
+
return handleUpdate(state, {
|
|
2401
|
+
value,
|
|
2402
|
+
inputSource
|
|
2403
|
+
});
|
|
2867
2404
|
};
|
|
2868
2405
|
|
|
2869
|
-
const
|
|
2870
|
-
|
|
2406
|
+
const handleReplaceInput = (state, value, inputSource = Script) => {
|
|
2407
|
+
return handleUpdate(state, {
|
|
2408
|
+
replacement: value,
|
|
2409
|
+
inputSource
|
|
2410
|
+
});
|
|
2871
2411
|
};
|
|
2872
2412
|
|
|
2873
|
-
const
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2413
|
+
const getInputHandler = name => {
|
|
2414
|
+
switch (name) {
|
|
2415
|
+
case SearchValue:
|
|
2416
|
+
return handleInput;
|
|
2417
|
+
case ReplaceValue:
|
|
2418
|
+
return handleReplaceInput;
|
|
2419
|
+
case FilesToExclude:
|
|
2420
|
+
return handleExcludeInput;
|
|
2421
|
+
case FilesToInclude:
|
|
2422
|
+
return handleIncludeInput;
|
|
2423
|
+
default:
|
|
2424
|
+
throw new Error(`unknown input handler: ${name}`);
|
|
2878
2425
|
}
|
|
2879
|
-
return '';
|
|
2880
|
-
};
|
|
2881
|
-
const getFileIcons = async matches => {
|
|
2882
|
-
// TODO cache file icons
|
|
2883
|
-
const promises = matches.map(getFileIcon);
|
|
2884
|
-
const icons = await Promise.all(promises);
|
|
2885
|
-
return icons;
|
|
2886
2426
|
};
|
|
2887
2427
|
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
const getNumberOfVisibleItems$1 = (listHeight, itemHeight) => {
|
|
2892
|
-
return Math.ceil(listHeight / itemHeight) + 1;
|
|
2428
|
+
const handleInput2 = (state, inputName, value, inputSource = Script) => {
|
|
2429
|
+
const fn = getInputHandler(inputName);
|
|
2430
|
+
return fn(state, value, inputSource);
|
|
2893
2431
|
};
|
|
2894
2432
|
|
|
2895
|
-
const
|
|
2896
|
-
|
|
2897
|
-
const protocolMatch = uri.match(RE_PROTOCOL);
|
|
2898
|
-
if (protocolMatch) {
|
|
2899
|
-
return protocolMatch[1];
|
|
2900
|
-
}
|
|
2901
|
-
return '';
|
|
2433
|
+
const handleListBlur = state => {
|
|
2434
|
+
return state;
|
|
2902
2435
|
};
|
|
2903
2436
|
|
|
2904
|
-
const
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2437
|
+
const handleSharedInput = (state, name, value, inputSource = Script) => {
|
|
2438
|
+
const fn = getInputHandler(name);
|
|
2439
|
+
return fn(state, value, inputSource);
|
|
2440
|
+
};
|
|
2441
|
+
|
|
2442
|
+
// TODO optimize this function to return the minimum number
|
|
2443
|
+
// of visible items needed, e.g. when not scrolled 5 items with
|
|
2444
|
+
// 20px fill 100px but when scrolled 6 items are needed
|
|
2445
|
+
const getNumberOfVisibleItems = (listHeight, itemHeight) => {
|
|
2446
|
+
return Math.ceil(listHeight / itemHeight) + 1;
|
|
2447
|
+
};
|
|
2448
|
+
const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
2449
|
+
const newMaxLineY = Math.min(index + 1, itemsLength);
|
|
2450
|
+
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
2451
|
+
const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
|
|
2452
|
+
const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
|
|
2917
2453
|
return {
|
|
2918
|
-
|
|
2919
|
-
|
|
2454
|
+
...state,
|
|
2455
|
+
focusedIndex: index,
|
|
2456
|
+
minLineY: newMinLineY,
|
|
2457
|
+
maxLineY: newMaxLineY,
|
|
2458
|
+
focused: true,
|
|
2459
|
+
deltaY: newDeltaY
|
|
2920
2460
|
};
|
|
2921
2461
|
};
|
|
2922
|
-
|
|
2923
|
-
const
|
|
2924
|
-
|
|
2925
|
-
const
|
|
2926
|
-
|
|
2462
|
+
const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
2463
|
+
const newMinLineY = index;
|
|
2464
|
+
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
2465
|
+
const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
|
|
2466
|
+
const newDeltaY = newMinLineY * itemHeight;
|
|
2467
|
+
return {
|
|
2468
|
+
...state,
|
|
2469
|
+
focusedIndex: index,
|
|
2470
|
+
minLineY: newMinLineY,
|
|
2471
|
+
maxLineY: newMaxLineY,
|
|
2472
|
+
focused: true,
|
|
2473
|
+
deltaY: newDeltaY
|
|
2474
|
+
};
|
|
2927
2475
|
};
|
|
2928
|
-
|
|
2929
|
-
const
|
|
2930
|
-
|
|
2931
|
-
|
|
2476
|
+
const focusIndex = (state, index) => {
|
|
2477
|
+
const {
|
|
2478
|
+
itemHeight,
|
|
2479
|
+
minLineY,
|
|
2480
|
+
maxLineY,
|
|
2481
|
+
headerHeight,
|
|
2482
|
+
height,
|
|
2483
|
+
items
|
|
2484
|
+
} = state;
|
|
2485
|
+
const itemsLength = items.length;
|
|
2486
|
+
if (itemsLength === 0) {
|
|
2487
|
+
return state;
|
|
2932
2488
|
}
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2489
|
+
number(itemHeight);
|
|
2490
|
+
if (index === -1) {
|
|
2491
|
+
return {
|
|
2492
|
+
...state,
|
|
2493
|
+
focusedIndex: -1,
|
|
2494
|
+
focused: true
|
|
2495
|
+
};
|
|
2496
|
+
}
|
|
2497
|
+
const listHeight = height - headerHeight;
|
|
2498
|
+
if (index < minLineY + 1) {
|
|
2499
|
+
return focusIndexScrollUp(state, index, listHeight, itemHeight, itemsLength);
|
|
2500
|
+
}
|
|
2501
|
+
if (index >= maxLineY - 1) {
|
|
2502
|
+
return focusIndexScrollDown(state, index, listHeight, itemHeight, itemsLength);
|
|
2503
|
+
}
|
|
2504
|
+
return {
|
|
2505
|
+
...state,
|
|
2506
|
+
focusedIndex: index,
|
|
2507
|
+
focused: true
|
|
2508
|
+
};
|
|
2938
2509
|
};
|
|
2939
|
-
const
|
|
2940
|
-
|
|
2941
|
-
const textSearch$6 = async (scheme, root, query) => {
|
|
2942
|
-
string(scheme);
|
|
2943
|
-
string(query);
|
|
2944
|
-
const result = await invoke$2('ExtensionHostTextSearch.executeTextSearchProvider', scheme, query);
|
|
2945
|
-
return result;
|
|
2510
|
+
const first = () => {
|
|
2511
|
+
return 0;
|
|
2946
2512
|
};
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
return invoke$2('ExtensionHostTextSearch.textSearchFetch', scheme, root, query, options, assetDir);
|
|
2513
|
+
const last = items => {
|
|
2514
|
+
return items.length - 1;
|
|
2950
2515
|
};
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
return invoke$2('ExtensionHostTextSearch.textSearchHtml', scheme, root, query);
|
|
2516
|
+
const next = (items, index) => {
|
|
2517
|
+
return (index + 1) % items.length;
|
|
2954
2518
|
};
|
|
2955
|
-
|
|
2956
|
-
|
|
2957
|
-
return invoke$2('ExtensionHostTextSearch.textSearchMemory', scheme, root, query, options, assetDir);
|
|
2519
|
+
const previous = (items, index) => {
|
|
2520
|
+
return index === 0 ? items.length - 1 : index - 1;
|
|
2958
2521
|
};
|
|
2959
|
-
|
|
2960
|
-
const
|
|
2961
|
-
|
|
2962
|
-
isCaseSensitive,
|
|
2963
|
-
searchString,
|
|
2964
|
-
useRegularExpression
|
|
2965
|
-
}) => {
|
|
2966
|
-
const ripGrepArgs = ['--hidden', '--no-require-git', '--smart-case', '--stats', '--json'];
|
|
2967
|
-
ripGrepArgs.push('--threads', `${threads}`);
|
|
2968
|
-
if (isCaseSensitive) {
|
|
2969
|
-
ripGrepArgs.push('--case-sensitive');
|
|
2970
|
-
} else {
|
|
2971
|
-
ripGrepArgs.push('--ignore-case');
|
|
2972
|
-
}
|
|
2973
|
-
if (useRegularExpression) {
|
|
2974
|
-
ripGrepArgs.push('--regexp', searchString);
|
|
2975
|
-
} else {
|
|
2976
|
-
ripGrepArgs.push('--fixed-strings');
|
|
2977
|
-
ripGrepArgs.push('--');
|
|
2978
|
-
ripGrepArgs.push(searchString);
|
|
2979
|
-
}
|
|
2980
|
-
ripGrepArgs.push('.');
|
|
2981
|
-
return ripGrepArgs;
|
|
2522
|
+
const focusFirst = state => {
|
|
2523
|
+
const firstIndex = first();
|
|
2524
|
+
return focusIndex(state, firstIndex);
|
|
2982
2525
|
};
|
|
2983
|
-
|
|
2984
|
-
const
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
const
|
|
2988
|
-
|
|
2989
|
-
const Wss = 'wss:';
|
|
2990
|
-
|
|
2991
|
-
const getWebSocketProtocol = locationProtocol => {
|
|
2992
|
-
return locationProtocol === Https ? Wss : Ws;
|
|
2526
|
+
const focusLast = state => {
|
|
2527
|
+
const {
|
|
2528
|
+
items
|
|
2529
|
+
} = state;
|
|
2530
|
+
const lastIndex = last(items);
|
|
2531
|
+
return focusIndex(state, lastIndex);
|
|
2993
2532
|
};
|
|
2994
|
-
|
|
2995
|
-
const
|
|
2996
|
-
|
|
2997
|
-
|
|
2533
|
+
const focusNext = state => {
|
|
2534
|
+
const {
|
|
2535
|
+
focusedIndex,
|
|
2536
|
+
items
|
|
2537
|
+
} = state;
|
|
2538
|
+
const nextIndex = next(items, focusedIndex);
|
|
2539
|
+
return focusIndex(state, nextIndex);
|
|
2998
2540
|
};
|
|
2999
2541
|
|
|
3000
|
-
|
|
3001
|
-
return location.host;
|
|
3002
|
-
};
|
|
3003
|
-
const getProtocol = () => {
|
|
3004
|
-
return location.protocol;
|
|
3005
|
-
};
|
|
2542
|
+
// based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
|
|
3006
2543
|
|
|
3007
|
-
const
|
|
3008
|
-
|
|
3009
|
-
const protocol = getProtocol();
|
|
3010
|
-
const wsUrl = getWebSocketUrl('search-process', host, protocol);
|
|
3011
|
-
const webSocket = new WebSocket(wsUrl);
|
|
3012
|
-
const rpc = await WebSocketRpcParent.create({
|
|
3013
|
-
webSocket,
|
|
3014
|
-
commandMap: {}
|
|
3015
|
-
});
|
|
3016
|
-
return rpc;
|
|
2544
|
+
const isLastIndex = (array, index) => {
|
|
2545
|
+
return index === array.length - 1;
|
|
3017
2546
|
};
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
rpc: undefined
|
|
2547
|
+
const lastIndex = array => {
|
|
2548
|
+
return array.length - 1;
|
|
3021
2549
|
};
|
|
3022
|
-
const
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
2550
|
+
const focusNextPage = state => {
|
|
2551
|
+
const {
|
|
2552
|
+
focusedIndex,
|
|
2553
|
+
items,
|
|
2554
|
+
maxLineY,
|
|
2555
|
+
minLineY
|
|
2556
|
+
} = state;
|
|
2557
|
+
if (isLastIndex(items, focusedIndex)) {
|
|
2558
|
+
return state;
|
|
3026
2559
|
}
|
|
3027
|
-
|
|
2560
|
+
const indexNextPage = Math.min(maxLineY + (maxLineY - minLineY) - 2, lastIndex(items));
|
|
2561
|
+
return focusIndex(state, indexNextPage);
|
|
3028
2562
|
};
|
|
3029
|
-
|
|
3030
|
-
const
|
|
3031
|
-
|
|
3032
|
-
|
|
2563
|
+
const focusPrevious = state => {
|
|
2564
|
+
const {
|
|
2565
|
+
focusedIndex,
|
|
2566
|
+
items
|
|
2567
|
+
} = state;
|
|
2568
|
+
if (focusedIndex === 0 || focusedIndex === -1) {
|
|
2569
|
+
return state;
|
|
2570
|
+
}
|
|
2571
|
+
const previousIndex = previous(items, focusedIndex);
|
|
2572
|
+
return focusIndex(state, previousIndex);
|
|
3033
2573
|
};
|
|
3034
|
-
|
|
3035
|
-
const getPortTuple = () => {
|
|
2574
|
+
const focusPreviousPage = state => {
|
|
3036
2575
|
const {
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
2576
|
+
focusedIndex,
|
|
2577
|
+
minLineY,
|
|
2578
|
+
maxLineY
|
|
2579
|
+
} = state;
|
|
2580
|
+
if (focusedIndex === 0 || focusedIndex === -1) {
|
|
2581
|
+
return state;
|
|
2582
|
+
}
|
|
2583
|
+
const indexPreviousPage = Math.max(minLineY - (maxLineY - minLineY) + 1, 0);
|
|
2584
|
+
return focusIndex(state, indexPreviousPage);
|
|
2585
|
+
};
|
|
2586
|
+
const handleScrollBarCaptureLost = state => {
|
|
3040
2587
|
return {
|
|
3041
|
-
|
|
3042
|
-
|
|
2588
|
+
...state,
|
|
2589
|
+
scrollBarActive: false
|
|
3043
2590
|
};
|
|
3044
2591
|
};
|
|
3045
|
-
|
|
3046
|
-
const
|
|
3047
|
-
|
|
3048
|
-
port1,
|
|
3049
|
-
port2
|
|
3050
|
-
} = getPortTuple();
|
|
3051
|
-
const rpcPromise = MessagePortRpcParent.create({
|
|
3052
|
-
messagePort: port2,
|
|
3053
|
-
commandMap: {},
|
|
3054
|
-
isMessagePortOpen: true
|
|
3055
|
-
});
|
|
3056
|
-
await invokeAndTransfer('SendMessagePortToElectron.sendMessagePortToElectron', port1, 'HandleMessagePortForSearchProcess.handleMessagePortForSearchProcess');
|
|
3057
|
-
port2.start();
|
|
3058
|
-
const rpc = await rpcPromise;
|
|
3059
|
-
return rpc;
|
|
3060
|
-
};
|
|
3061
|
-
|
|
3062
|
-
const state = {
|
|
3063
|
-
rpc: undefined
|
|
2592
|
+
const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
|
|
2593
|
+
const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
|
|
2594
|
+
return scrollBarOffset;
|
|
3064
2595
|
};
|
|
3065
|
-
const
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
2596
|
+
const getScrollBarY = getScrollBarOffset;
|
|
2597
|
+
const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
|
|
2598
|
+
const halfScrollBarHeight = scrollBarHeight / 2;
|
|
2599
|
+
if (relativeY <= halfScrollBarHeight) {
|
|
2600
|
+
// clicked at top
|
|
2601
|
+
return {
|
|
2602
|
+
percent: 0,
|
|
2603
|
+
handleOffset: relativeY
|
|
2604
|
+
};
|
|
3069
2605
|
}
|
|
3070
|
-
|
|
2606
|
+
if (relativeY <= height - halfScrollBarHeight) {
|
|
2607
|
+
// clicked in middle
|
|
2608
|
+
return {
|
|
2609
|
+
percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
|
|
2610
|
+
handleOffset: halfScrollBarHeight
|
|
2611
|
+
};
|
|
2612
|
+
}
|
|
2613
|
+
// clicked at bottom
|
|
2614
|
+
return {
|
|
2615
|
+
percent: 1,
|
|
2616
|
+
handleOffset: scrollBarHeight - height + relativeY
|
|
2617
|
+
};
|
|
3071
2618
|
};
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
const rpc = await getOrCreate();
|
|
3075
|
-
return rpc.invoke(method, ...params);
|
|
2619
|
+
const clamp = (num, min, max) => {
|
|
2620
|
+
return Math.min(Math.max(num, min), max);
|
|
3076
2621
|
};
|
|
2622
|
+
const setDeltaY = (state, value) => {
|
|
2623
|
+
object(state);
|
|
2624
|
+
number(value);
|
|
2625
|
+
const {
|
|
2626
|
+
itemHeight,
|
|
2627
|
+
finalDeltaY,
|
|
2628
|
+
deltaY,
|
|
2629
|
+
height,
|
|
2630
|
+
headerHeight,
|
|
2631
|
+
items
|
|
2632
|
+
} = state;
|
|
2633
|
+
const listHeight = height - headerHeight;
|
|
2634
|
+
const newDeltaY = clamp(value, 0, finalDeltaY);
|
|
2635
|
+
if (deltaY === newDeltaY) {
|
|
2636
|
+
return state;
|
|
2637
|
+
}
|
|
2638
|
+
// TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
|
|
2639
|
+
const minLineY = Math.floor(newDeltaY / itemHeight);
|
|
2640
|
+
const maxLineY = Math.min(minLineY + getNumberOfVisibleItems(listHeight, itemHeight), items.length);
|
|
3077
2641
|
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
...
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
ripGrepArgs,
|
|
3085
|
-
searchDir: root
|
|
2642
|
+
// TODO update icons
|
|
2643
|
+
return {
|
|
2644
|
+
...state,
|
|
2645
|
+
deltaY: newDeltaY,
|
|
2646
|
+
minLineY,
|
|
2647
|
+
maxLineY
|
|
3086
2648
|
};
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
2649
|
+
};
|
|
2650
|
+
const handleScrollBarClick = (state, eventY) => {
|
|
2651
|
+
const {
|
|
2652
|
+
y,
|
|
2653
|
+
deltaY,
|
|
2654
|
+
headerHeight,
|
|
2655
|
+
finalDeltaY,
|
|
2656
|
+
scrollBarHeight,
|
|
2657
|
+
height
|
|
2658
|
+
} = state;
|
|
2659
|
+
const contentHeight = height - headerHeight;
|
|
2660
|
+
const relativeY = eventY - y - headerHeight;
|
|
2661
|
+
const currentScrollBarY = getScrollBarY(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
|
|
2662
|
+
const diff = relativeY - currentScrollBarY;
|
|
2663
|
+
if (diff >= 0 && diff < scrollBarHeight) {
|
|
2664
|
+
return {
|
|
2665
|
+
...state,
|
|
2666
|
+
handleOffset: diff,
|
|
2667
|
+
scrollBarActive: true
|
|
2668
|
+
};
|
|
3095
2669
|
}
|
|
3096
|
-
const
|
|
3097
|
-
|
|
3098
|
-
|
|
2670
|
+
const {
|
|
2671
|
+
percent,
|
|
2672
|
+
handleOffset
|
|
2673
|
+
} = getNewDeltaPercent(contentHeight, scrollBarHeight, relativeY);
|
|
2674
|
+
const newDeltaY = percent * finalDeltaY;
|
|
2675
|
+
return {
|
|
2676
|
+
...setDeltaY(state, newDeltaY),
|
|
2677
|
+
handleOffset,
|
|
2678
|
+
scrollBarActive: true
|
|
2679
|
+
};
|
|
3099
2680
|
};
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
const results = [];
|
|
3105
|
-
for (const [key, value] of entries) {
|
|
3106
|
-
// @ts-ignore
|
|
3107
|
-
if (value.includes(query)) {
|
|
3108
|
-
results.push([key, [{
|
|
3109
|
-
absoluteOffset: 0,
|
|
3110
|
-
preview: value
|
|
3111
|
-
}]]);
|
|
3112
|
-
}
|
|
2681
|
+
const getNewPercent = (contentHeight, scrollBarHeight, relativeY) => {
|
|
2682
|
+
if (relativeY <= contentHeight - scrollBarHeight / 2) {
|
|
2683
|
+
// clicked in middle
|
|
2684
|
+
return relativeY / (contentHeight - scrollBarHeight);
|
|
3113
2685
|
}
|
|
3114
|
-
|
|
2686
|
+
// clicked at bottom
|
|
2687
|
+
return 1;
|
|
2688
|
+
};
|
|
2689
|
+
const handleScrollBarMove = (state, eventY) => {
|
|
2690
|
+
const {
|
|
2691
|
+
y,
|
|
2692
|
+
headerHeight,
|
|
2693
|
+
handleOffset,
|
|
2694
|
+
finalDeltaY,
|
|
2695
|
+
height,
|
|
2696
|
+
scrollBarHeight
|
|
2697
|
+
} = state;
|
|
2698
|
+
const relativeY = eventY - y - headerHeight - handleOffset;
|
|
2699
|
+
const contentHeight = height - headerHeight;
|
|
2700
|
+
const newPercent = getNewPercent(contentHeight, scrollBarHeight, relativeY);
|
|
2701
|
+
const newDeltaY = newPercent * finalDeltaY;
|
|
2702
|
+
return setDeltaY(state, newDeltaY);
|
|
2703
|
+
};
|
|
2704
|
+
const handleWheel = (state, deltaMode, deltaY) => {
|
|
2705
|
+
number(deltaMode);
|
|
2706
|
+
number(deltaY);
|
|
2707
|
+
return setDeltaY(state, state.deltaY + deltaY);
|
|
3115
2708
|
};
|
|
3116
2709
|
|
|
3117
|
-
const
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
return textSearch$1;
|
|
3123
|
-
case 'fetch':
|
|
3124
|
-
return textSearch$5;
|
|
3125
|
-
case 'html':
|
|
3126
|
-
return textSearch$4;
|
|
3127
|
-
case 'memfs':
|
|
3128
|
-
return textSearch$3;
|
|
3129
|
-
default:
|
|
3130
|
-
return textSearch$6;
|
|
2710
|
+
const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight, topHeight, itemCount) => {
|
|
2711
|
+
const relativeY = eventY - y - topHeight + deltaY;
|
|
2712
|
+
const index = Math.floor(relativeY / itemHeight);
|
|
2713
|
+
if (index >= itemCount) {
|
|
2714
|
+
return -1;
|
|
3131
2715
|
}
|
|
2716
|
+
return index;
|
|
3132
2717
|
};
|
|
3133
2718
|
|
|
3134
|
-
const
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
2719
|
+
const getTopHeight = flags => {
|
|
2720
|
+
if (flags & ReplaceExpanded && flags & DetailsExpanded) {
|
|
2721
|
+
return 190;
|
|
2722
|
+
}
|
|
2723
|
+
if (flags & DetailsExpanded) {
|
|
2724
|
+
return 158;
|
|
2725
|
+
}
|
|
2726
|
+
if (flags & ReplaceExpanded) {
|
|
2727
|
+
return 93;
|
|
2728
|
+
}
|
|
2729
|
+
return 61;
|
|
3141
2730
|
};
|
|
3142
2731
|
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
if (!value) {
|
|
3147
|
-
return '';
|
|
3148
|
-
}
|
|
3149
|
-
if (!(flags & UseRegularExpression$2)) {
|
|
3150
|
-
return '';
|
|
2732
|
+
const getFilteredResults = (results, collapsedPaths) => {
|
|
2733
|
+
if (collapsedPaths.length === 0) {
|
|
2734
|
+
return results;
|
|
3151
2735
|
}
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
if (
|
|
3156
|
-
|
|
2736
|
+
const filteredResults = [];
|
|
2737
|
+
let isExcluded = false;
|
|
2738
|
+
for (const result of results) {
|
|
2739
|
+
if (result.type === File) {
|
|
2740
|
+
filteredResults.push(result);
|
|
2741
|
+
isExcluded = collapsedPaths.includes(result.text) ? true : false;
|
|
2742
|
+
}
|
|
2743
|
+
if (result.type === Match && !isExcluded) {
|
|
2744
|
+
filteredResults.push(result);
|
|
3157
2745
|
}
|
|
3158
|
-
return '';
|
|
3159
2746
|
}
|
|
3160
|
-
return
|
|
2747
|
+
return filteredResults;
|
|
3161
2748
|
};
|
|
3162
2749
|
|
|
3163
|
-
const
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
};
|
|
3168
|
-
try {
|
|
3169
|
-
const {
|
|
3170
|
-
height,
|
|
3171
|
-
itemHeight,
|
|
3172
|
-
minimumSliderSize,
|
|
3173
|
-
headerHeight,
|
|
3174
|
-
flags,
|
|
3175
|
-
value,
|
|
3176
|
-
threads,
|
|
3177
|
-
includeValue,
|
|
3178
|
-
excludeValue
|
|
3179
|
-
} = partialNewState;
|
|
3180
|
-
if (isEmptyString(value)) {
|
|
3181
|
-
return {
|
|
3182
|
-
...partialNewState,
|
|
3183
|
-
minLineY: 0,
|
|
3184
|
-
maxLineY: 0,
|
|
3185
|
-
deltaY: 0,
|
|
3186
|
-
items: [],
|
|
3187
|
-
listItems: [],
|
|
3188
|
-
matchCount: 0,
|
|
3189
|
-
message: '',
|
|
3190
|
-
loaded: true,
|
|
3191
|
-
searchInputErrorMessage: ''
|
|
3192
|
-
};
|
|
3193
|
-
}
|
|
3194
|
-
const searchInputErrorMessage = validateSearchInput(value, flags);
|
|
3195
|
-
if (searchInputErrorMessage) {
|
|
3196
|
-
return {
|
|
3197
|
-
...partialNewState,
|
|
3198
|
-
searchInputErrorMessage: searchInputErrorMessage
|
|
3199
|
-
};
|
|
3200
|
-
}
|
|
3201
|
-
const root = state.workspacePath;
|
|
3202
|
-
const scheme = getProtocol$1(root);
|
|
3203
|
-
const results = await textSearch(root, value, {
|
|
3204
|
-
threads,
|
|
3205
|
-
isCaseSensitive: Boolean(flags & MatchCase$2),
|
|
3206
|
-
useRegularExpression: Boolean(flags & UseRegularExpression$2),
|
|
3207
|
-
exclude: excludeValue,
|
|
3208
|
-
include: includeValue,
|
|
3209
|
-
assetDir: state.assetDir,
|
|
3210
|
-
root,
|
|
3211
|
-
query: value,
|
|
3212
|
-
scheme,
|
|
3213
|
-
flags,
|
|
3214
|
-
matchWholeWord: Boolean(flags & MatchWholeWord$2)
|
|
3215
|
-
}, state.assetDir, state.platform);
|
|
3216
|
-
if (!Array.isArray(results)) {
|
|
3217
|
-
throw new TypeError('results must be of type array');
|
|
3218
|
-
}
|
|
3219
|
-
const {
|
|
3220
|
-
fileCount,
|
|
3221
|
-
resultCount
|
|
3222
|
-
} = getTextSearchResultCounts(results);
|
|
3223
|
-
const message = getStatusMessage(resultCount, fileCount);
|
|
3224
|
-
const total = results.length;
|
|
3225
|
-
const contentHeight = total * itemHeight;
|
|
3226
|
-
const listHeight = height - headerHeight;
|
|
3227
|
-
const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
|
|
3228
|
-
const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
|
|
3229
|
-
const maxLineY = Math.min(numberOfVisible, total);
|
|
3230
|
-
const finalDeltaY = Math.max(contentHeight - listHeight, 0);
|
|
3231
|
-
const visible = results.slice(0, maxLineY);
|
|
3232
|
-
const icons = await getFileIcons(visible);
|
|
3233
|
-
return {
|
|
3234
|
-
...partialNewState,
|
|
3235
|
-
minLineY: 0,
|
|
3236
|
-
deltaY: 0,
|
|
3237
|
-
value,
|
|
3238
|
-
items: results,
|
|
3239
|
-
listItems: results,
|
|
3240
|
-
message,
|
|
3241
|
-
maxLineY: maxLineY,
|
|
3242
|
-
scrollBarHeight,
|
|
3243
|
-
finalDeltaY,
|
|
3244
|
-
threads,
|
|
3245
|
-
fileCount,
|
|
3246
|
-
matchCount: resultCount,
|
|
3247
|
-
loaded: true,
|
|
3248
|
-
icons,
|
|
3249
|
-
searchInputErrorMessage: ''
|
|
3250
|
-
};
|
|
3251
|
-
} catch (error) {
|
|
3252
|
-
handleError(error);
|
|
3253
|
-
return {
|
|
3254
|
-
...partialNewState,
|
|
3255
|
-
message: `${error}`,
|
|
3256
|
-
items: [],
|
|
3257
|
-
listItems: [],
|
|
3258
|
-
matchCount: 0,
|
|
3259
|
-
fileCount: 0,
|
|
3260
|
-
minLineY: 0,
|
|
3261
|
-
maxLineY: 0
|
|
3262
|
-
};
|
|
2750
|
+
const toggleCollapsedPath = (collapsedPaths, path) => {
|
|
2751
|
+
if (collapsedPaths.includes(path)) {
|
|
2752
|
+
const index = collapsedPaths.indexOf(path);
|
|
2753
|
+
return collapsedPaths.toSpliced(index, 1);
|
|
3263
2754
|
}
|
|
2755
|
+
return [...collapsedPaths, path];
|
|
3264
2756
|
};
|
|
3265
2757
|
|
|
3266
|
-
const
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
const
|
|
3278
|
-
|
|
2758
|
+
const selectIndexFile = async (state, searchResult, index) => {
|
|
2759
|
+
const {
|
|
2760
|
+
collapsedPaths,
|
|
2761
|
+
items,
|
|
2762
|
+
itemHeight,
|
|
2763
|
+
headerHeight,
|
|
2764
|
+
height
|
|
2765
|
+
} = state;
|
|
2766
|
+
const path = searchResult.text;
|
|
2767
|
+
const newCollapsedPaths = toggleCollapsedPath(collapsedPaths, path);
|
|
2768
|
+
const filteredResults = getFilteredResults(items, newCollapsedPaths);
|
|
2769
|
+
const icons = await getFileIcons(filteredResults);
|
|
2770
|
+
const total = filteredResults.length;
|
|
2771
|
+
const listHeight = height - headerHeight;
|
|
2772
|
+
const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
|
|
2773
|
+
const maxLineY = Math.min(numberOfVisible, total);
|
|
2774
|
+
return {
|
|
2775
|
+
...state,
|
|
2776
|
+
collapsedPaths: newCollapsedPaths,
|
|
2777
|
+
listFocusedIndex: index,
|
|
2778
|
+
listFocused: true,
|
|
2779
|
+
listItems: filteredResults,
|
|
2780
|
+
maxLineY,
|
|
2781
|
+
icons
|
|
2782
|
+
};
|
|
3279
2783
|
};
|
|
3280
2784
|
|
|
3281
|
-
const
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
2785
|
+
const getFileIndex = (items, index) => {
|
|
2786
|
+
for (let i = index; i >= 0; i--) {
|
|
2787
|
+
const item = items[i];
|
|
2788
|
+
if (item.type === File) {
|
|
2789
|
+
return i;
|
|
2790
|
+
}
|
|
3287
2791
|
}
|
|
3288
|
-
return
|
|
2792
|
+
return -1;
|
|
3289
2793
|
};
|
|
3290
2794
|
|
|
3291
|
-
const
|
|
3292
|
-
|
|
3293
|
-
if (text.startsWith('./')) {
|
|
3294
|
-
return text.slice(2);
|
|
3295
|
-
}
|
|
3296
|
-
return text;
|
|
2795
|
+
const openUri = async (path, focus = true, props = {}) => {
|
|
2796
|
+
await invoke$2(/* Main.openUri */'Main.openUri', /* uri */path, /* focus */focus, props);
|
|
3297
2797
|
};
|
|
3298
2798
|
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
// TODO simplify code by first matching files with their elements, then creating bulk edits
|
|
3307
|
-
for (const match of items) {
|
|
3308
|
-
const {
|
|
3309
|
-
type,
|
|
3310
|
-
text,
|
|
3311
|
-
lineNumber,
|
|
3312
|
-
end,
|
|
3313
|
-
start
|
|
3314
|
-
} = match;
|
|
3315
|
-
if (type === File) {
|
|
3316
|
-
changes = [];
|
|
3317
|
-
const fileName = getFileName(text);
|
|
3318
|
-
const absolutePath = `${workspacePath}/${fileName}`;
|
|
3319
|
-
element = {
|
|
3320
|
-
uri: absolutePath,
|
|
3321
|
-
changes
|
|
3322
|
-
};
|
|
3323
|
-
bulkChanges.push(element);
|
|
3324
|
-
} else {
|
|
3325
|
-
changes.push({
|
|
3326
|
-
text: replacement,
|
|
3327
|
-
startRowIndex: lineNumber - 1,
|
|
3328
|
-
startColumnIndex: start,
|
|
3329
|
-
endRowIndex: lineNumber,
|
|
3330
|
-
endColumnIndex: end
|
|
3331
|
-
});
|
|
3332
|
-
}
|
|
2799
|
+
// TODO this should be in FileSystem module
|
|
2800
|
+
const pathBaseName = path => {
|
|
2801
|
+
return path.slice(path.lastIndexOf('/') + 1);
|
|
2802
|
+
};
|
|
2803
|
+
const getRelativePath = relativePath => {
|
|
2804
|
+
if (relativePath.startsWith('./')) {
|
|
2805
|
+
return `/${relativePath.slice(2)}`; // TODO support windows paths
|
|
3333
2806
|
}
|
|
3334
|
-
return
|
|
2807
|
+
return `/${relativePath}`; // TODO support windows paths
|
|
3335
2808
|
};
|
|
3336
2809
|
|
|
3337
|
-
const
|
|
2810
|
+
const selectIndexPreview = async (state, searchResult, index) => {
|
|
3338
2811
|
const {
|
|
3339
|
-
workspacePath,
|
|
3340
2812
|
items,
|
|
3341
|
-
|
|
3342
|
-
matchCount
|
|
2813
|
+
workspacePath
|
|
3343
2814
|
} = state;
|
|
3344
|
-
const
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
2815
|
+
const fileIndex = getFileIndex(items, index);
|
|
2816
|
+
if (fileIndex === -1) {
|
|
2817
|
+
throw new Error('Search result is missing file');
|
|
2818
|
+
}
|
|
2819
|
+
const {
|
|
2820
|
+
lineNumber
|
|
2821
|
+
} = searchResult;
|
|
2822
|
+
const fileResult = items[fileIndex];
|
|
2823
|
+
const relativePath = getRelativePath(fileResult.text);
|
|
2824
|
+
const absolutePath = `${workspacePath}${relativePath}`;
|
|
2825
|
+
await openUri(absolutePath, true, {
|
|
2826
|
+
selections: new Uint32Array([lineNumber, 0, lineNumber, 0])
|
|
2827
|
+
});
|
|
3348
2828
|
return {
|
|
3349
2829
|
...state,
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
minLineY: 0,
|
|
3353
|
-
maxLineY: 0,
|
|
3354
|
-
message
|
|
2830
|
+
listFocusedIndex: index,
|
|
2831
|
+
listFocused: false
|
|
3355
2832
|
};
|
|
3356
2833
|
};
|
|
3357
2834
|
|
|
3358
|
-
const
|
|
3359
|
-
|
|
3360
|
-
|
|
2835
|
+
const getSelectHandler = type => {
|
|
2836
|
+
switch (type) {
|
|
2837
|
+
case File:
|
|
2838
|
+
return selectIndexFile;
|
|
2839
|
+
case Match:
|
|
2840
|
+
return selectIndexPreview;
|
|
2841
|
+
default:
|
|
2842
|
+
throw new Error(`unexpected search result type ${type}`);
|
|
3361
2843
|
}
|
|
3362
|
-
return expandDetails(state);
|
|
3363
|
-
};
|
|
3364
|
-
|
|
3365
|
-
const toggleSearchFlag = (state, flag) => {
|
|
3366
|
-
return handleUpdate(state, {
|
|
3367
|
-
flags: state.flags ^ flag
|
|
3368
|
-
});
|
|
3369
|
-
};
|
|
3370
|
-
|
|
3371
|
-
const toggleMatchCase = state => {
|
|
3372
|
-
return toggleSearchFlag(state, MatchCase$2);
|
|
3373
2844
|
};
|
|
3374
2845
|
|
|
3375
|
-
const
|
|
3376
|
-
|
|
2846
|
+
const selectIndex = async (state, index) => {
|
|
2847
|
+
if (index === -1) {
|
|
2848
|
+
return {
|
|
2849
|
+
...state,
|
|
2850
|
+
listFocused: true,
|
|
2851
|
+
listFocusedIndex: -1
|
|
2852
|
+
};
|
|
2853
|
+
}
|
|
2854
|
+
const {
|
|
2855
|
+
listItems
|
|
2856
|
+
} = state;
|
|
2857
|
+
const searchResult = listItems[index];
|
|
2858
|
+
const fn = getSelectHandler(searchResult.type);
|
|
2859
|
+
return fn(state, searchResult, index);
|
|
3377
2860
|
};
|
|
3378
2861
|
|
|
3379
|
-
const
|
|
3380
|
-
|
|
2862
|
+
const handleClickAt = (state, eventX, eventY) => {
|
|
2863
|
+
const {
|
|
2864
|
+
x,
|
|
2865
|
+
y,
|
|
2866
|
+
itemHeight,
|
|
2867
|
+
deltaY,
|
|
2868
|
+
flags,
|
|
2869
|
+
listItems
|
|
2870
|
+
} = state;
|
|
2871
|
+
const topHeight = getTopHeight(flags);
|
|
2872
|
+
const index = getListIndex(eventX, eventY, x, y, deltaY, itemHeight, topHeight, listItems.length);
|
|
2873
|
+
return selectIndex(state, index);
|
|
3381
2874
|
};
|
|
3382
2875
|
|
|
3383
|
-
const
|
|
3384
|
-
|
|
2876
|
+
const getSavedValue = savedState => {
|
|
2877
|
+
if (savedState && typeof savedState === 'object' && 'value' in savedState && typeof savedState.value === 'string') {
|
|
2878
|
+
return savedState.value;
|
|
2879
|
+
}
|
|
2880
|
+
return '';
|
|
2881
|
+
};
|
|
2882
|
+
const getSavedReplacement = savedState => {
|
|
2883
|
+
if (savedState && typeof savedState === 'object' && 'replacement' in savedState && typeof savedState.replacement === 'string') {
|
|
2884
|
+
return savedState.replacement;
|
|
2885
|
+
}
|
|
2886
|
+
return '';
|
|
2887
|
+
};
|
|
2888
|
+
const getSavedFlags = savedState => {
|
|
2889
|
+
if (savedState && typeof savedState === 'object' && 'flags' in savedState && typeof savedState.flags === 'number') {
|
|
2890
|
+
return savedState.flags;
|
|
2891
|
+
}
|
|
2892
|
+
return 0;
|
|
2893
|
+
};
|
|
2894
|
+
const getSavedIncludeValue = savedState => {
|
|
2895
|
+
if (savedState && typeof savedState === 'object' && 'includeValue' in savedState && typeof savedState.includeValue === 'string') {
|
|
2896
|
+
return savedState.includeValue;
|
|
2897
|
+
}
|
|
2898
|
+
return '';
|
|
2899
|
+
};
|
|
2900
|
+
const getSavedExcludeValue = savedState => {
|
|
2901
|
+
if (savedState && typeof savedState === 'object' && 'excludeValue' in savedState && typeof savedState.excludeValue === 'string') {
|
|
2902
|
+
return savedState.excludeValue;
|
|
2903
|
+
}
|
|
2904
|
+
return '';
|
|
3385
2905
|
};
|
|
3386
2906
|
|
|
3387
|
-
const
|
|
3388
|
-
return
|
|
2907
|
+
const restoreState = savedState => {
|
|
2908
|
+
return {
|
|
2909
|
+
savedValue: getSavedValue(savedState),
|
|
2910
|
+
replacement: getSavedReplacement(savedState),
|
|
2911
|
+
savedCollapsedPaths: [],
|
|
2912
|
+
threads: 1,
|
|
2913
|
+
flags: getSavedFlags(savedState),
|
|
2914
|
+
includeValue: getSavedIncludeValue(savedState),
|
|
2915
|
+
excludeValue: getSavedExcludeValue(savedState)
|
|
2916
|
+
};
|
|
3389
2917
|
};
|
|
3390
2918
|
|
|
3391
|
-
const
|
|
3392
|
-
|
|
2919
|
+
const loadContent = async (state, savedState) => {
|
|
2920
|
+
const {
|
|
2921
|
+
savedValue,
|
|
2922
|
+
savedCollapsedPaths,
|
|
2923
|
+
threads,
|
|
2924
|
+
replacement,
|
|
2925
|
+
flags,
|
|
2926
|
+
includeValue,
|
|
2927
|
+
excludeValue
|
|
2928
|
+
} = restoreState(savedState);
|
|
2929
|
+
if (savedValue) {
|
|
2930
|
+
return handleUpdate(state, {
|
|
2931
|
+
value: savedValue,
|
|
2932
|
+
threads,
|
|
2933
|
+
inputSource: Script,
|
|
2934
|
+
collapsedPaths: savedCollapsedPaths,
|
|
2935
|
+
replacement,
|
|
2936
|
+
flags,
|
|
2937
|
+
includeValue,
|
|
2938
|
+
excludeValue
|
|
2939
|
+
});
|
|
2940
|
+
}
|
|
2941
|
+
return {
|
|
2942
|
+
...state,
|
|
2943
|
+
threads,
|
|
2944
|
+
flags,
|
|
2945
|
+
loaded: true
|
|
2946
|
+
};
|
|
3393
2947
|
};
|
|
3394
2948
|
|
|
3395
|
-
const
|
|
3396
|
-
return
|
|
2949
|
+
const refresh = state => {
|
|
2950
|
+
return handleUpdate(state, {});
|
|
3397
2951
|
};
|
|
3398
2952
|
|
|
3399
|
-
const
|
|
3400
|
-
switch (
|
|
3401
|
-
case
|
|
3402
|
-
return
|
|
3403
|
-
case
|
|
3404
|
-
return
|
|
3405
|
-
case
|
|
3406
|
-
return
|
|
3407
|
-
case
|
|
3408
|
-
return
|
|
3409
|
-
case
|
|
3410
|
-
return
|
|
3411
|
-
case
|
|
3412
|
-
return
|
|
3413
|
-
case
|
|
3414
|
-
return
|
|
3415
|
-
case
|
|
3416
|
-
return
|
|
3417
|
-
case
|
|
3418
|
-
return
|
|
3419
|
-
case
|
|
3420
|
-
|
|
3421
|
-
case
|
|
3422
|
-
|
|
3423
|
-
|
|
2953
|
+
const getFocusSelector = focusKey => {
|
|
2954
|
+
switch (focusKey) {
|
|
2955
|
+
case FocusSearchInput:
|
|
2956
|
+
return SearchValue;
|
|
2957
|
+
case FocusSearchReplaceInput:
|
|
2958
|
+
return ReplaceValue;
|
|
2959
|
+
case FocusToggleDetails:
|
|
2960
|
+
return ToggleSearchDetails;
|
|
2961
|
+
case FocusSearchMatchCase:
|
|
2962
|
+
return MatchCase;
|
|
2963
|
+
case FocusSearchPreserveCase:
|
|
2964
|
+
return PreserveCase;
|
|
2965
|
+
case FocusSearchRegex:
|
|
2966
|
+
return UseRegularExpression;
|
|
2967
|
+
case FocusSearchIncludeInput:
|
|
2968
|
+
return FilesToInclude;
|
|
2969
|
+
case FocusSearchExcludeInput:
|
|
2970
|
+
return FilesToExclude;
|
|
2971
|
+
case FocusSearchWholeWord:
|
|
2972
|
+
return MatchWholeWord;
|
|
2973
|
+
case FocusSearchReplaceAll:
|
|
2974
|
+
return ReplaceAll;
|
|
2975
|
+
case FocusSearchOpenEditors:
|
|
2976
|
+
return SearchOnlyOpenEditors;
|
|
2977
|
+
case FocusIgnoreFiles:
|
|
2978
|
+
return UseExcludeSettings;
|
|
2979
|
+
case FocusToggleReplace:
|
|
2980
|
+
return ToggleReplace;
|
|
3424
2981
|
default:
|
|
3425
|
-
|
|
2982
|
+
return '';
|
|
3426
2983
|
}
|
|
3427
2984
|
};
|
|
3428
2985
|
|
|
3429
|
-
const
|
|
3430
|
-
const
|
|
3431
|
-
return
|
|
2986
|
+
const renderFocus = (oldState, newState) => {
|
|
2987
|
+
const selector = getFocusSelector(newState.focus);
|
|
2988
|
+
return ['Viewlet.focusElementByName', newState.uid, selector];
|
|
2989
|
+
};
|
|
2990
|
+
|
|
2991
|
+
const None$1 = 0;
|
|
2992
|
+
const Collapsed = 1;
|
|
2993
|
+
const Expanded = 2;
|
|
2994
|
+
|
|
2995
|
+
const getMatchCount = (results, startIndex) => {
|
|
2996
|
+
for (let i = startIndex + 1; i < results.length; i++) {
|
|
2997
|
+
const result = results[i];
|
|
2998
|
+
if (result.type === File) {
|
|
2999
|
+
return i - startIndex - 1;
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
return results.length - startIndex - 1;
|
|
3003
|
+
};
|
|
3004
|
+
|
|
3005
|
+
const getChildCount = (expanded, matchCount) => {
|
|
3006
|
+
let childCount = 1;
|
|
3007
|
+
if (expanded === Expanded || expanded === Collapsed) {
|
|
3008
|
+
childCount += 2;
|
|
3009
|
+
}
|
|
3010
|
+
if (matchCount) {
|
|
3011
|
+
childCount++;
|
|
3012
|
+
}
|
|
3013
|
+
childCount++;
|
|
3014
|
+
return childCount;
|
|
3015
|
+
};
|
|
3016
|
+
|
|
3017
|
+
const getSearchDisplayResultFile = (results, fileIcons, i, setSize, collapsedPaths, text, posInSet, relativeIndex, focused, originalResults) => {
|
|
3018
|
+
const path = text;
|
|
3019
|
+
const absolutePath = getRelativePath(path);
|
|
3020
|
+
const baseName = pathBaseName(path);
|
|
3021
|
+
const index = originalResults.indexOf(results[i]);
|
|
3022
|
+
const matchCount = getMatchCount(results, index);
|
|
3023
|
+
const expanded = collapsedPaths.includes(path) ? Collapsed : Expanded;
|
|
3024
|
+
const childCount = getChildCount(expanded, matchCount);
|
|
3025
|
+
const badgeText = `${matchCount}`;
|
|
3026
|
+
return {
|
|
3027
|
+
badgeText,
|
|
3028
|
+
childCount,
|
|
3029
|
+
depth: 0,
|
|
3030
|
+
expanded,
|
|
3031
|
+
focused,
|
|
3032
|
+
icon: fileIcons[relativeIndex],
|
|
3033
|
+
matchLength: 0,
|
|
3034
|
+
matchStart: 0,
|
|
3035
|
+
posInSet,
|
|
3036
|
+
replacement: '',
|
|
3037
|
+
setSize,
|
|
3038
|
+
text: baseName,
|
|
3039
|
+
title: absolutePath
|
|
3040
|
+
};
|
|
3041
|
+
};
|
|
3042
|
+
|
|
3043
|
+
const getDisplayResultMatch = (setSize, searchTermLength, replacement, text, posInSet, start, focused) => {
|
|
3044
|
+
return {
|
|
3045
|
+
badgeText: '',
|
|
3046
|
+
childCount: getChildCount(None$1, 0),
|
|
3047
|
+
depth: 1,
|
|
3048
|
+
expanded: None$1,
|
|
3049
|
+
focused,
|
|
3050
|
+
icon: '',
|
|
3051
|
+
matchLength: searchTermLength,
|
|
3052
|
+
matchStart: start,
|
|
3053
|
+
posInSet,
|
|
3054
|
+
replacement,
|
|
3055
|
+
setSize,
|
|
3056
|
+
text: text,
|
|
3057
|
+
title: text
|
|
3058
|
+
};
|
|
3059
|
+
};
|
|
3060
|
+
|
|
3061
|
+
const getDisplayResult = (results, fileIcons, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY, originalResults) => {
|
|
3062
|
+
const result = results[i];
|
|
3063
|
+
const {
|
|
3064
|
+
type,
|
|
3065
|
+
text,
|
|
3066
|
+
start
|
|
3067
|
+
} = result;
|
|
3068
|
+
const posInSet = i + 1;
|
|
3069
|
+
const focused = i === focusedIndex;
|
|
3070
|
+
const relativeIndex = i - minLineY;
|
|
3071
|
+
switch (type) {
|
|
3072
|
+
case File:
|
|
3073
|
+
return getSearchDisplayResultFile(results, fileIcons, i, setSize, collapsedPaths, text, posInSet, relativeIndex, focused, originalResults);
|
|
3074
|
+
case Match:
|
|
3075
|
+
return getDisplayResultMatch(setSize, searchTermLength, replacement, text, posInSet, start, focused);
|
|
3076
|
+
default:
|
|
3077
|
+
throw new Error('unexpected search result type');
|
|
3078
|
+
}
|
|
3079
|
+
};
|
|
3080
|
+
|
|
3081
|
+
const getDisplayResults = (results, itemHeight, resultCount, searchTerm, minLineY, maxLineY, replacement, fileIcons, focusedIndex, collapsedPaths, originalResults) => {
|
|
3082
|
+
const displayResults = [];
|
|
3083
|
+
const setSize = resultCount;
|
|
3084
|
+
const searchTermLength = searchTerm.length;
|
|
3085
|
+
for (let i = minLineY; i < maxLineY; i++) {
|
|
3086
|
+
const displayResult = getDisplayResult(results, fileIcons, i, setSize, searchTermLength, replacement, focusedIndex, collapsedPaths, minLineY, originalResults);
|
|
3087
|
+
displayResults.push(displayResult);
|
|
3088
|
+
}
|
|
3089
|
+
return displayResults;
|
|
3432
3090
|
};
|
|
3433
3091
|
|
|
3434
|
-
const
|
|
3435
|
-
|
|
3092
|
+
const createViewModel = state => {
|
|
3093
|
+
const {
|
|
3094
|
+
listItems,
|
|
3095
|
+
itemHeight,
|
|
3096
|
+
fileCount,
|
|
3097
|
+
value,
|
|
3098
|
+
minLineY,
|
|
3099
|
+
maxLineY,
|
|
3100
|
+
replacement,
|
|
3101
|
+
icons,
|
|
3102
|
+
listFocusedIndex,
|
|
3103
|
+
collapsedPaths,
|
|
3104
|
+
items,
|
|
3105
|
+
listFocused,
|
|
3106
|
+
deltaY,
|
|
3107
|
+
finalDeltaY,
|
|
3108
|
+
height,
|
|
3109
|
+
headerHeight,
|
|
3110
|
+
flags,
|
|
3111
|
+
message,
|
|
3112
|
+
searchInputErrorMessage,
|
|
3113
|
+
scrollBarHeight,
|
|
3114
|
+
matchCount
|
|
3115
|
+
} = state;
|
|
3116
|
+
const displayResults = getDisplayResults(listItems, itemHeight, fileCount, value, minLineY, maxLineY, replacement, icons, listFocusedIndex, collapsedPaths, items);
|
|
3117
|
+
const focusOutline = listFocused && listFocusedIndex === -1;
|
|
3118
|
+
const scrollBarValue = deltaY / finalDeltaY * 100;
|
|
3119
|
+
const scrollBarY = getScrollBarY$1(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
|
|
3120
|
+
return {
|
|
3121
|
+
displayResults,
|
|
3122
|
+
flags,
|
|
3123
|
+
message,
|
|
3124
|
+
focusOutline,
|
|
3125
|
+
searchInputErrorMessage,
|
|
3126
|
+
scrollBarHeight,
|
|
3127
|
+
scrollBarY,
|
|
3128
|
+
scrollBarValue,
|
|
3129
|
+
deltaY,
|
|
3130
|
+
itemHeight,
|
|
3131
|
+
matchCount
|
|
3132
|
+
};
|
|
3133
|
+
};
|
|
3134
|
+
|
|
3135
|
+
const Actions = 'Actions';
|
|
3136
|
+
const Badge = 'Badge';
|
|
3137
|
+
const Chevron = 'Chevron';
|
|
3138
|
+
const CloseMaskIcon = 'MaskIcon MaskIconClose';
|
|
3139
|
+
const Empty = '';
|
|
3140
|
+
const FileIcon = 'FileIcon';
|
|
3141
|
+
const FocusOutline = 'FocusOutline';
|
|
3142
|
+
const Grow = 'Grow';
|
|
3143
|
+
const Highlight = 'Highlight';
|
|
3144
|
+
const HighlightDeleted = 'HighlightDeleted';
|
|
3145
|
+
const HighlightInserted = 'HighlightInserted';
|
|
3146
|
+
const IconButton = 'IconButton';
|
|
3147
|
+
const Label = 'Label';
|
|
3148
|
+
const List = 'List';
|
|
3149
|
+
const MaskIcon = 'MaskIcon';
|
|
3150
|
+
const MaskIconBook = 'MaskIconBook';
|
|
3151
|
+
const MaskIconCaseSensitive = 'MaskIconCaseSensitive';
|
|
3152
|
+
const MaskIconChevronDown = 'MaskIconChevronDown';
|
|
3153
|
+
const MaskIconChevronRight = 'MaskIconChevronRight';
|
|
3154
|
+
const MaskIconEllipsis = 'MaskIconEllipsis';
|
|
3155
|
+
const MaskIconExclude = 'MaskIconExclude';
|
|
3156
|
+
const MaskIconPreserveCase = 'MaskIconPreserveCase';
|
|
3157
|
+
const MaskIconRegex = 'MaskIconRegex';
|
|
3158
|
+
const MaskIconReplaceAll = 'MaskIconReplaceAll';
|
|
3159
|
+
const MaskIconWholeWord = 'MaskIconWholeWord';
|
|
3160
|
+
const MultilineInputBox = 'MultilineInputBox';
|
|
3161
|
+
const ScrollBar$1 = 'ScrollBar';
|
|
3162
|
+
const ScrollBarThumb = 'ScrollBarThumb';
|
|
3163
|
+
const ScrollBarVertical = 'ScrollBarVertical';
|
|
3164
|
+
const Search$1 = 'Search';
|
|
3165
|
+
const SearchField = 'SearchField';
|
|
3166
|
+
const SearchFieldButton = 'SearchFieldButton';
|
|
3167
|
+
const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
|
|
3168
|
+
const SearchFieldButtonDisabled = 'SearchFieldButtonDisabled';
|
|
3169
|
+
const SearchFieldButtons = 'SearchFieldButtons';
|
|
3170
|
+
const SearchFieldContainer = 'SearchFieldContainer';
|
|
3171
|
+
const SearchFieldError = 'SearchFieldError';
|
|
3172
|
+
const SearchHeader = 'SearchHeader';
|
|
3173
|
+
const SearchHeaderDetails = 'SearchHeaderDetails';
|
|
3174
|
+
const SearchHeaderDetailsExpanded = 'SearchHeaderDetailsExpanded';
|
|
3175
|
+
const SearchHeaderDetailsExpandedTop = 'SearchHeaderDetailsExpandedTop';
|
|
3176
|
+
const SearchHeaderDetailsHeading = 'SearchHeaderDetailsHeading';
|
|
3177
|
+
const SearchHeaderTop = 'SearchHeaderTop';
|
|
3178
|
+
const SearchHeaderTopRight = 'SearchHeaderTopRight';
|
|
3179
|
+
const SearchInputError = 'SearchInputError';
|
|
3180
|
+
const SearchRemove = 'SearchRemove';
|
|
3181
|
+
const SearchToggleButton = 'SearchToggleButton';
|
|
3182
|
+
const SearchToggleButtonExpanded = 'SearchToggleButtonExpanded';
|
|
3183
|
+
const SourceControlBadge = 'SourceControlBadge';
|
|
3184
|
+
const ToggleDetails = 'ToggleDetails';
|
|
3185
|
+
const Tree$1 = 'Tree';
|
|
3186
|
+
const TreeItem$1 = 'TreeItem';
|
|
3187
|
+
const TreeItemActive = 'TreeItemActive';
|
|
3188
|
+
const TreeItems$1 = 'TreeItems';
|
|
3189
|
+
const Viewlet = 'Viewlet';
|
|
3190
|
+
const ViewletSearchMessage = 'ViewletSearchMessage';
|
|
3191
|
+
const ViewletSearchMessageIndented = 'ViewletSearchMessageIndented';
|
|
3192
|
+
|
|
3193
|
+
const Alert = 'alert';
|
|
3194
|
+
const Button$2 = 'button';
|
|
3195
|
+
const CheckBox = 'checkbox';
|
|
3196
|
+
const None = 'none';
|
|
3197
|
+
const ScrollBar = 'scrollbar';
|
|
3198
|
+
const Status = 'status';
|
|
3199
|
+
const ToolBar = 'toolbar';
|
|
3200
|
+
const Tree = 'tree';
|
|
3201
|
+
const TreeItem = 'treeitem';
|
|
3202
|
+
|
|
3203
|
+
const HandleClick = 'handleClick';
|
|
3204
|
+
const HandleExcludeInput = 'handleExcludeInput';
|
|
3205
|
+
const HandleHeaderClick2 = 'handleHeaderClick2';
|
|
3206
|
+
const HandleHeaderFocusIn = 'handleHeaderFocusIn';
|
|
3207
|
+
const HandleIncludeInput = 'handleIncludeInput';
|
|
3208
|
+
const HandleInput = 'handleInput';
|
|
3209
|
+
const HandleInput2 = 'handleInput2';
|
|
3210
|
+
const HandleListBlur = 'handleListBlur';
|
|
3211
|
+
const HandleReplaceInput = 'handleReplaceInput';
|
|
3212
|
+
const HandleScrollBarPointerDown = 'handleScrollBarPointerDown';
|
|
3213
|
+
const HandleToggleButtonClick = 'handleToggleButtonClick';
|
|
3214
|
+
const HandleWheel = 'handleWheel';
|
|
3215
|
+
const HandleListFocus = 'handleListFocus';
|
|
3216
|
+
const HandleContextMenu = 'handleContextMenu';
|
|
3217
|
+
|
|
3218
|
+
const mergeClassNames = (...classNames) => {
|
|
3219
|
+
return classNames.filter(Boolean).join(' ');
|
|
3220
|
+
};
|
|
3221
|
+
const Text$1 = 12;
|
|
3222
|
+
const SetText = 1;
|
|
3223
|
+
const SetAttribute = 3;
|
|
3224
|
+
const RemoveAttribute = 4;
|
|
3225
|
+
const Add = 6;
|
|
3226
|
+
const NavigateChild = 7;
|
|
3227
|
+
const NavigateParent = 8;
|
|
3228
|
+
const RemoveChild = 9;
|
|
3229
|
+
const NavigateSibling = 10;
|
|
3230
|
+
const applyPendingPatches = (patches, pendingPatches, skip) => {
|
|
3231
|
+
for (let k = 0; k < pendingPatches.length - skip; k += 2) {
|
|
3232
|
+
const type = pendingPatches[k];
|
|
3233
|
+
const index = pendingPatches[k + 1];
|
|
3234
|
+
if (type === NavigateParent) {
|
|
3235
|
+
patches.push({
|
|
3236
|
+
type
|
|
3237
|
+
});
|
|
3238
|
+
} else {
|
|
3239
|
+
patches.push({
|
|
3240
|
+
type,
|
|
3241
|
+
index
|
|
3242
|
+
});
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
pendingPatches.length = 0;
|
|
3246
|
+
};
|
|
3247
|
+
const isKey = key => {
|
|
3248
|
+
return key !== 'type' && key !== 'childCount';
|
|
3249
|
+
};
|
|
3250
|
+
const getKeys = node => {
|
|
3251
|
+
const keys = Object.keys(node).filter(isKey);
|
|
3252
|
+
return keys;
|
|
3253
|
+
};
|
|
3254
|
+
const getTotalChildCount = (nodes, index) => {
|
|
3255
|
+
let i = index;
|
|
3256
|
+
let pending = 1;
|
|
3257
|
+
while (pending) {
|
|
3258
|
+
const node = nodes[i];
|
|
3259
|
+
pending += node.childCount;
|
|
3260
|
+
pending--;
|
|
3261
|
+
i++;
|
|
3262
|
+
}
|
|
3263
|
+
return i - index;
|
|
3264
|
+
};
|
|
3265
|
+
const diff = (oldNodes, newNodes) => {
|
|
3266
|
+
const patches = [];
|
|
3267
|
+
const pendingPatches = [];
|
|
3268
|
+
let i = 0;
|
|
3269
|
+
let j = 0;
|
|
3270
|
+
let siblingOffset = 0;
|
|
3271
|
+
let maxSiblingOffset = 1;
|
|
3272
|
+
const indexStack = [0, 1];
|
|
3273
|
+
while (i < oldNodes.length && j < newNodes.length) {
|
|
3274
|
+
const oldNode = oldNodes[i];
|
|
3275
|
+
const newNode = newNodes[j];
|
|
3276
|
+
|
|
3277
|
+
// TODO maybe don't have the current element in indexstack
|
|
3278
|
+
if (siblingOffset === maxSiblingOffset) {
|
|
3279
|
+
indexStack.pop();
|
|
3280
|
+
indexStack.pop();
|
|
3281
|
+
pendingPatches.push(NavigateParent, 0);
|
|
3282
|
+
maxSiblingOffset = indexStack.pop();
|
|
3283
|
+
siblingOffset = indexStack.pop() + 1;
|
|
3284
|
+
}
|
|
3285
|
+
while (siblingOffset === maxSiblingOffset) {
|
|
3286
|
+
pendingPatches.push(NavigateParent, 0);
|
|
3287
|
+
maxSiblingOffset = indexStack.pop();
|
|
3288
|
+
siblingOffset = indexStack.pop() + 1;
|
|
3289
|
+
}
|
|
3290
|
+
if (oldNode.type !== newNode.type) {
|
|
3291
|
+
let skip = 0;
|
|
3292
|
+
if (pendingPatches.length > 0 && pendingPatches.at(-2) === NavigateChild) {
|
|
3293
|
+
skip = 2;
|
|
3294
|
+
}
|
|
3295
|
+
applyPendingPatches(patches, pendingPatches, skip);
|
|
3296
|
+
const oldTotal = getTotalChildCount(oldNodes, i);
|
|
3297
|
+
const newTotal = getTotalChildCount(newNodes, j);
|
|
3298
|
+
patches.push({
|
|
3299
|
+
type: RemoveChild,
|
|
3300
|
+
index: siblingOffset
|
|
3301
|
+
});
|
|
3302
|
+
patches.push({
|
|
3303
|
+
type: Add,
|
|
3304
|
+
nodes: newNodes.slice(j, j + newTotal)
|
|
3305
|
+
});
|
|
3306
|
+
siblingOffset++;
|
|
3307
|
+
i += oldTotal;
|
|
3308
|
+
j += newTotal;
|
|
3309
|
+
continue;
|
|
3310
|
+
}
|
|
3311
|
+
if (oldNode.type === Text$1 && newNode.type === Text$1) {
|
|
3312
|
+
if (oldNode.text !== newNode.text) {
|
|
3313
|
+
if (siblingOffset !== 0) {
|
|
3314
|
+
pendingPatches.push(NavigateSibling, siblingOffset);
|
|
3315
|
+
}
|
|
3316
|
+
applyPendingPatches(patches, pendingPatches, 0);
|
|
3317
|
+
patches.push({
|
|
3318
|
+
type: SetText,
|
|
3319
|
+
value: newNode.text
|
|
3320
|
+
});
|
|
3321
|
+
}
|
|
3322
|
+
i++;
|
|
3323
|
+
j++;
|
|
3324
|
+
siblingOffset++;
|
|
3325
|
+
continue;
|
|
3326
|
+
}
|
|
3327
|
+
const oldKeys = getKeys(oldNode);
|
|
3328
|
+
const newKeys = getKeys(newNode);
|
|
3329
|
+
let hasAttributeChanges = false;
|
|
3330
|
+
for (const key of newKeys) {
|
|
3331
|
+
if (oldNode[key] !== newNode[key]) {
|
|
3332
|
+
hasAttributeChanges = true;
|
|
3333
|
+
break;
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
3336
|
+
for (const key of oldKeys) {
|
|
3337
|
+
if (!(key in newNode)) {
|
|
3338
|
+
hasAttributeChanges = true;
|
|
3339
|
+
break;
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
if (hasAttributeChanges) {
|
|
3343
|
+
if (siblingOffset > 0) {
|
|
3344
|
+
pendingPatches.push(NavigateSibling, siblingOffset);
|
|
3345
|
+
}
|
|
3346
|
+
applyPendingPatches(patches, pendingPatches, 0);
|
|
3347
|
+
for (const key of newKeys) {
|
|
3348
|
+
if (oldNode[key] !== newNode[key]) {
|
|
3349
|
+
patches.push({
|
|
3350
|
+
type: SetAttribute,
|
|
3351
|
+
key,
|
|
3352
|
+
value: newNode[key]
|
|
3353
|
+
});
|
|
3354
|
+
}
|
|
3355
|
+
}
|
|
3356
|
+
for (const key of oldKeys) {
|
|
3357
|
+
if (!(key in newNode)) {
|
|
3358
|
+
patches.push({
|
|
3359
|
+
type: RemoveAttribute,
|
|
3360
|
+
key
|
|
3361
|
+
});
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
}
|
|
3365
|
+
if (oldNode.childCount && newNode.childCount) {
|
|
3366
|
+
maxSiblingOffset = oldNode.childCount;
|
|
3367
|
+
indexStack.push(0, maxSiblingOffset);
|
|
3368
|
+
pendingPatches.push(NavigateChild, 0);
|
|
3369
|
+
i++;
|
|
3370
|
+
j++;
|
|
3371
|
+
continue;
|
|
3372
|
+
}
|
|
3373
|
+
if (oldNode.childCount) {
|
|
3374
|
+
applyPendingPatches(patches, pendingPatches, 0);
|
|
3375
|
+
for (let k = 0; k < oldNode.childCount; k++) {
|
|
3376
|
+
patches.push({
|
|
3377
|
+
type: RemoveChild,
|
|
3378
|
+
index: 0
|
|
3379
|
+
});
|
|
3380
|
+
}
|
|
3381
|
+
i += getTotalChildCount(oldNodes, i);
|
|
3382
|
+
j++;
|
|
3383
|
+
siblingOffset++;
|
|
3384
|
+
continue;
|
|
3385
|
+
}
|
|
3386
|
+
if (newNode.childCount) {
|
|
3387
|
+
applyPendingPatches(patches, pendingPatches, 0);
|
|
3388
|
+
const total = getTotalChildCount(newNodes, j);
|
|
3389
|
+
patches.push({
|
|
3390
|
+
type: Add,
|
|
3391
|
+
nodes: newNodes.slice(j + 1, j + total)
|
|
3392
|
+
});
|
|
3393
|
+
i++;
|
|
3394
|
+
j += total;
|
|
3395
|
+
continue;
|
|
3396
|
+
}
|
|
3397
|
+
i++;
|
|
3398
|
+
j++;
|
|
3399
|
+
siblingOffset++;
|
|
3400
|
+
}
|
|
3401
|
+
while (i < oldNodes.length) {
|
|
3402
|
+
if (indexStack.length !== 2) {
|
|
3403
|
+
patches.push({
|
|
3404
|
+
type: NavigateParent
|
|
3405
|
+
});
|
|
3406
|
+
}
|
|
3407
|
+
patches.push({
|
|
3408
|
+
type: RemoveChild,
|
|
3409
|
+
index: siblingOffset
|
|
3410
|
+
});
|
|
3411
|
+
i += getTotalChildCount(oldNodes, i);
|
|
3412
|
+
indexStack.pop();
|
|
3413
|
+
indexStack.pop();
|
|
3414
|
+
}
|
|
3415
|
+
while (j < newNodes.length) {
|
|
3416
|
+
if (siblingOffset > 0) {
|
|
3417
|
+
patches.push({
|
|
3418
|
+
type: NavigateSibling,
|
|
3419
|
+
index: siblingOffset
|
|
3420
|
+
});
|
|
3421
|
+
siblingOffset = 0;
|
|
3422
|
+
}
|
|
3423
|
+
const count = getTotalChildCount(newNodes, j);
|
|
3424
|
+
patches.push({
|
|
3425
|
+
type: Add,
|
|
3426
|
+
nodes: newNodes.slice(j, j + count)
|
|
3427
|
+
});
|
|
3428
|
+
j += count;
|
|
3429
|
+
}
|
|
3430
|
+
return patches;
|
|
3431
|
+
};
|
|
3432
|
+
|
|
3433
|
+
const Button$1 = 1;
|
|
3434
|
+
const Del = 21;
|
|
3435
|
+
const Div = 4;
|
|
3436
|
+
const H4 = 24;
|
|
3437
|
+
const Img = 17;
|
|
3438
|
+
const Ins = 20;
|
|
3439
|
+
const Span = 8;
|
|
3440
|
+
const Text = 12;
|
|
3441
|
+
const TextArea = 62;
|
|
3442
|
+
|
|
3443
|
+
const getSearchDetailsToggleVirtualDom = () => {
|
|
3444
|
+
return [{
|
|
3445
|
+
type: Div,
|
|
3446
|
+
className: ToggleDetails,
|
|
3447
|
+
role: Button$2,
|
|
3448
|
+
tabIndex: 0,
|
|
3449
|
+
ariaLabel: toggleSearchDetails(),
|
|
3450
|
+
title: toggleSearchDetails(),
|
|
3451
|
+
name: ToggleSearchDetails,
|
|
3452
|
+
childCount: 1
|
|
3453
|
+
}, {
|
|
3454
|
+
type: Div,
|
|
3455
|
+
className: mergeClassNames(MaskIcon, MaskIconEllipsis),
|
|
3456
|
+
childCount: 0
|
|
3457
|
+
}];
|
|
3436
3458
|
};
|
|
3437
3459
|
|
|
3438
|
-
const
|
|
3439
|
-
const {
|
|
3440
|
-
items,
|
|
3441
|
-
minLineY,
|
|
3442
|
-
maxLineY
|
|
3443
|
-
} = state;
|
|
3444
|
-
const visibleItems = items.slice(minLineY, maxLineY);
|
|
3445
|
-
const icons = await getFileIcons(visibleItems);
|
|
3460
|
+
const text = data => {
|
|
3446
3461
|
return {
|
|
3447
|
-
|
|
3448
|
-
|
|
3462
|
+
type: Text,
|
|
3463
|
+
text: data,
|
|
3464
|
+
childCount: 0
|
|
3449
3465
|
};
|
|
3450
3466
|
};
|
|
3451
3467
|
|
|
3452
|
-
const
|
|
3453
|
-
|
|
3454
|
-
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
};
|
|
3458
|
-
|
|
3459
|
-
const handleInput = (state, value, inputSource = Script) => {
|
|
3460
|
-
return handleUpdate(state, {
|
|
3461
|
-
value,
|
|
3462
|
-
inputSource
|
|
3463
|
-
});
|
|
3464
|
-
};
|
|
3465
|
-
|
|
3466
|
-
const handleListBlur = state => {
|
|
3467
|
-
return state;
|
|
3468
|
+
const getClassName = indented => {
|
|
3469
|
+
if (indented) {
|
|
3470
|
+
return mergeClassNames(ViewletSearchMessage, ViewletSearchMessageIndented);
|
|
3471
|
+
}
|
|
3472
|
+
return ViewletSearchMessage;
|
|
3468
3473
|
};
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3474
|
+
const getSearchMessageVirtualDom = (message, indented) => {
|
|
3475
|
+
return [{
|
|
3476
|
+
type: Div,
|
|
3477
|
+
className: getClassName(indented),
|
|
3478
|
+
role: Status,
|
|
3479
|
+
tabIndex: 0,
|
|
3480
|
+
childCount: 1
|
|
3481
|
+
}, text(message)];
|
|
3475
3482
|
};
|
|
3476
3483
|
|
|
3477
|
-
const
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
|
|
3482
|
-
|
|
3483
|
-
case 'files-to-exclude-value':
|
|
3484
|
-
return handleExcludeInput;
|
|
3485
|
-
default:
|
|
3486
|
-
throw new Error(`unknown input handler: ${name}`);
|
|
3487
|
-
}
|
|
3484
|
+
const getSearchHeaderDetailsCollapsedVirtualDom = message => {
|
|
3485
|
+
return [{
|
|
3486
|
+
type: Div,
|
|
3487
|
+
className: SearchHeaderDetails,
|
|
3488
|
+
childCount: 2
|
|
3489
|
+
}, ...getSearchMessageVirtualDom(message, true), ...getSearchDetailsToggleVirtualDom()];
|
|
3488
3490
|
};
|
|
3489
3491
|
|
|
3490
|
-
const
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3492
|
+
const CheckBoxEnabled = 1;
|
|
3493
|
+
const CheckBoxDisabled = 2;
|
|
3494
|
+
const ButtonEnabled = 2;
|
|
3495
|
+
const ButtonDisabled = 3;
|
|
3494
3496
|
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
const
|
|
3504
|
-
const newMinLineY = Math.max(newMaxLineY - fittingItems, 0);
|
|
3505
|
-
const newDeltaY = itemsLength < fittingItems ? 0 : newMinLineY * itemHeight - listHeight % itemHeight + itemHeight;
|
|
3506
|
-
return {
|
|
3507
|
-
...state,
|
|
3508
|
-
focusedIndex: index,
|
|
3509
|
-
minLineY: newMinLineY,
|
|
3510
|
-
maxLineY: newMaxLineY,
|
|
3511
|
-
focused: true,
|
|
3512
|
-
deltaY: newDeltaY
|
|
3513
|
-
};
|
|
3514
|
-
};
|
|
3515
|
-
const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
|
|
3516
|
-
const newMinLineY = index;
|
|
3517
|
-
const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
|
|
3518
|
-
const newMaxLineY = Math.min(newMinLineY + fittingItems, itemsLength);
|
|
3519
|
-
const newDeltaY = newMinLineY * itemHeight;
|
|
3497
|
+
const getInputActionsExclude = flags => {
|
|
3498
|
+
const inside = [{
|
|
3499
|
+
icon: MaskIconExclude,
|
|
3500
|
+
title: useExcludeSettings(),
|
|
3501
|
+
command: 'toggleUseExcludeSettings',
|
|
3502
|
+
flag: flags & UseIgnoreFiles ? CheckBoxEnabled : CheckBoxDisabled,
|
|
3503
|
+
name: UseExcludeSettings
|
|
3504
|
+
}];
|
|
3505
|
+
const outside = [];
|
|
3520
3506
|
return {
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
minLineY: newMinLineY,
|
|
3524
|
-
maxLineY: newMaxLineY,
|
|
3525
|
-
focused: true,
|
|
3526
|
-
deltaY: newDeltaY
|
|
3507
|
+
inside,
|
|
3508
|
+
outside
|
|
3527
3509
|
};
|
|
3528
3510
|
};
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
|
|
3533
|
-
|
|
3534
|
-
|
|
3535
|
-
|
|
3536
|
-
|
|
3537
|
-
}
|
|
3538
|
-
const
|
|
3539
|
-
if (itemsLength === 0) {
|
|
3540
|
-
return state;
|
|
3541
|
-
}
|
|
3542
|
-
number(itemHeight);
|
|
3543
|
-
if (index === -1) {
|
|
3544
|
-
return {
|
|
3545
|
-
...state,
|
|
3546
|
-
focusedIndex: -1,
|
|
3547
|
-
focused: true
|
|
3548
|
-
};
|
|
3549
|
-
}
|
|
3550
|
-
const listHeight = height - headerHeight;
|
|
3551
|
-
if (index < minLineY + 1) {
|
|
3552
|
-
return focusIndexScrollUp(state, index, listHeight, itemHeight, itemsLength);
|
|
3553
|
-
}
|
|
3554
|
-
if (index >= maxLineY - 1) {
|
|
3555
|
-
return focusIndexScrollDown(state, index, listHeight, itemHeight, itemsLength);
|
|
3556
|
-
}
|
|
3511
|
+
|
|
3512
|
+
const getInputActionsInclude = flags => {
|
|
3513
|
+
const inside = [{
|
|
3514
|
+
icon: MaskIconBook,
|
|
3515
|
+
title: searchOnlyOpenEditors(),
|
|
3516
|
+
command: 'searchOnlyOpenEditors',
|
|
3517
|
+
flag: flags & OpenEditors ? CheckBoxEnabled : CheckBoxDisabled,
|
|
3518
|
+
name: SearchOnlyOpenEditors
|
|
3519
|
+
}];
|
|
3520
|
+
const outside = [];
|
|
3557
3521
|
return {
|
|
3558
|
-
|
|
3559
|
-
|
|
3560
|
-
focused: true
|
|
3522
|
+
inside,
|
|
3523
|
+
outside
|
|
3561
3524
|
};
|
|
3562
3525
|
};
|
|
3563
|
-
const first = () => {
|
|
3564
|
-
return 0;
|
|
3565
|
-
};
|
|
3566
|
-
const last = items => {
|
|
3567
|
-
return items.length - 1;
|
|
3568
|
-
};
|
|
3569
|
-
const next = (items, index) => {
|
|
3570
|
-
return (index + 1) % items.length;
|
|
3571
|
-
};
|
|
3572
|
-
const previous = (items, index) => {
|
|
3573
|
-
return index === 0 ? items.length - 1 : index - 1;
|
|
3574
|
-
};
|
|
3575
|
-
const focusFirst = state => {
|
|
3576
|
-
const firstIndex = first();
|
|
3577
|
-
return focusIndex(state, firstIndex);
|
|
3578
|
-
};
|
|
3579
|
-
const focusLast = state => {
|
|
3580
|
-
const {
|
|
3581
|
-
items
|
|
3582
|
-
} = state;
|
|
3583
|
-
const lastIndex = last(items);
|
|
3584
|
-
return focusIndex(state, lastIndex);
|
|
3585
|
-
};
|
|
3586
|
-
const focusNext = state => {
|
|
3587
|
-
const {
|
|
3588
|
-
focusedIndex,
|
|
3589
|
-
items
|
|
3590
|
-
} = state;
|
|
3591
|
-
const nextIndex = next(items, focusedIndex);
|
|
3592
|
-
return focusIndex(state, nextIndex);
|
|
3593
|
-
};
|
|
3594
|
-
|
|
3595
|
-
// based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
|
|
3596
3526
|
|
|
3597
|
-
const
|
|
3598
|
-
return
|
|
3599
|
-
};
|
|
3600
|
-
const lastIndex = array => {
|
|
3601
|
-
return array.length - 1;
|
|
3602
|
-
};
|
|
3603
|
-
const focusNextPage = state => {
|
|
3604
|
-
const {
|
|
3605
|
-
focusedIndex,
|
|
3606
|
-
items,
|
|
3607
|
-
maxLineY,
|
|
3608
|
-
minLineY
|
|
3609
|
-
} = state;
|
|
3610
|
-
if (isLastIndex(items, focusedIndex)) {
|
|
3611
|
-
return state;
|
|
3612
|
-
}
|
|
3613
|
-
const indexNextPage = Math.min(maxLineY + (maxLineY - minLineY) - 2, lastIndex(items));
|
|
3614
|
-
return focusIndex(state, indexNextPage);
|
|
3527
|
+
const getSearchFieldButtonClassName = flag => {
|
|
3528
|
+
return mergeClassNames(SearchFieldButton, flag === CheckBoxEnabled ? SearchFieldButtonChecked : '', flag === ButtonDisabled ? SearchFieldButtonDisabled : '');
|
|
3615
3529
|
};
|
|
3616
|
-
|
|
3617
|
-
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3530
|
+
|
|
3531
|
+
// TODO maybe move logic to viewmodel, which returns ariaChecked 1 | 2 | 3
|
|
3532
|
+
const getAriaChecked = flag => {
|
|
3533
|
+
switch (flag) {
|
|
3534
|
+
case CheckBoxEnabled:
|
|
3535
|
+
return true;
|
|
3536
|
+
case CheckBoxDisabled:
|
|
3537
|
+
return false;
|
|
3538
|
+
default:
|
|
3539
|
+
return undefined;
|
|
3623
3540
|
}
|
|
3624
|
-
const previousIndex = previous(items, focusedIndex);
|
|
3625
|
-
return focusIndex(state, previousIndex);
|
|
3626
3541
|
};
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
|
|
3542
|
+
|
|
3543
|
+
// TODO have have separate renderers for checkbox and button elements
|
|
3544
|
+
const getRole = flag => {
|
|
3545
|
+
switch (flag) {
|
|
3546
|
+
case CheckBoxEnabled:
|
|
3547
|
+
case CheckBoxDisabled:
|
|
3548
|
+
return CheckBox;
|
|
3549
|
+
default:
|
|
3550
|
+
return undefined;
|
|
3635
3551
|
}
|
|
3636
|
-
const indexPreviousPage = Math.max(minLineY - (maxLineY - minLineY) + 1, 0);
|
|
3637
|
-
return focusIndex(state, indexPreviousPage);
|
|
3638
3552
|
};
|
|
3639
|
-
const
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3553
|
+
const getDisabled = flag => {
|
|
3554
|
+
switch (flag) {
|
|
3555
|
+
case ButtonDisabled:
|
|
3556
|
+
return true;
|
|
3557
|
+
default:
|
|
3558
|
+
return undefined;
|
|
3559
|
+
}
|
|
3644
3560
|
};
|
|
3645
|
-
const
|
|
3646
|
-
const
|
|
3647
|
-
|
|
3561
|
+
const getSearchFieldButtonVirtualDom = button => {
|
|
3562
|
+
const {
|
|
3563
|
+
icon,
|
|
3564
|
+
title,
|
|
3565
|
+
name,
|
|
3566
|
+
flag
|
|
3567
|
+
} = button;
|
|
3568
|
+
const ariaChecked = getAriaChecked(flag);
|
|
3569
|
+
const role = getRole(flag);
|
|
3570
|
+
const disabled = getDisabled(flag);
|
|
3571
|
+
return [{
|
|
3572
|
+
type: Button$1,
|
|
3573
|
+
className: getSearchFieldButtonClassName(flag),
|
|
3574
|
+
name,
|
|
3575
|
+
title,
|
|
3576
|
+
role,
|
|
3577
|
+
ariaChecked,
|
|
3578
|
+
disabled,
|
|
3579
|
+
tabIndex: 0,
|
|
3580
|
+
childCount: 1
|
|
3581
|
+
}, {
|
|
3582
|
+
type: Span,
|
|
3583
|
+
className: mergeClassNames(MaskIcon, icon),
|
|
3584
|
+
childCount: 0
|
|
3585
|
+
}];
|
|
3648
3586
|
};
|
|
3649
|
-
|
|
3650
|
-
const
|
|
3651
|
-
|
|
3652
|
-
if (relativeY <= halfScrollBarHeight) {
|
|
3653
|
-
// clicked at top
|
|
3654
|
-
return {
|
|
3655
|
-
percent: 0,
|
|
3656
|
-
handleOffset: relativeY
|
|
3657
|
-
};
|
|
3658
|
-
}
|
|
3659
|
-
if (relativeY <= height - halfScrollBarHeight) {
|
|
3660
|
-
// clicked in middle
|
|
3587
|
+
|
|
3588
|
+
const getOutSideButtonsDom = outsideButtons => {
|
|
3589
|
+
if (outsideButtons.length === 0) {
|
|
3661
3590
|
return {
|
|
3662
|
-
|
|
3663
|
-
|
|
3591
|
+
preNodes: [],
|
|
3592
|
+
postNodes: []
|
|
3664
3593
|
};
|
|
3665
3594
|
}
|
|
3666
|
-
// clicked at bottom
|
|
3667
3595
|
return {
|
|
3668
|
-
|
|
3669
|
-
|
|
3596
|
+
preNodes: [{
|
|
3597
|
+
type: Div,
|
|
3598
|
+
className: SearchFieldContainer,
|
|
3599
|
+
role: None,
|
|
3600
|
+
childCount: 1 + outsideButtons.length
|
|
3601
|
+
}],
|
|
3602
|
+
postNodes: outsideButtons.flatMap(getSearchFieldButtonVirtualDom)
|
|
3670
3603
|
};
|
|
3671
3604
|
};
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
};
|
|
3675
|
-
const setDeltaY = (state, value) => {
|
|
3676
|
-
object(state);
|
|
3677
|
-
number(value);
|
|
3605
|
+
|
|
3606
|
+
const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, outsideButtons, onFocus = '', hasError = false) => {
|
|
3678
3607
|
const {
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
3682
|
-
|
|
3683
|
-
|
|
3684
|
-
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3608
|
+
preNodes,
|
|
3609
|
+
postNodes
|
|
3610
|
+
} = getOutSideButtonsDom(outsideButtons);
|
|
3611
|
+
const searchFieldClassName = hasError ? mergeClassNames(SearchField, SearchFieldError) : SearchField;
|
|
3612
|
+
const dom = [...preNodes, {
|
|
3613
|
+
type: Div,
|
|
3614
|
+
className: searchFieldClassName,
|
|
3615
|
+
role: None,
|
|
3616
|
+
childCount: 2
|
|
3617
|
+
}, {
|
|
3618
|
+
type: TextArea,
|
|
3619
|
+
className: MultilineInputBox,
|
|
3620
|
+
spellcheck: false,
|
|
3621
|
+
autocapitalize: 'off',
|
|
3622
|
+
autocorrect: 'off',
|
|
3623
|
+
placeholder,
|
|
3624
|
+
name,
|
|
3625
|
+
onInput,
|
|
3626
|
+
onFocus,
|
|
3627
|
+
childCount: 0
|
|
3628
|
+
}, {
|
|
3629
|
+
type: Div,
|
|
3630
|
+
className: SearchFieldButtons,
|
|
3631
|
+
childCount: insideButtons.length
|
|
3632
|
+
}, ...insideButtons.flatMap(getSearchFieldButtonVirtualDom), ...postNodes];
|
|
3633
|
+
return dom;
|
|
3634
|
+
};
|
|
3635
|
+
|
|
3636
|
+
const getSearchHeaderDetailsExpandedVirtualDom = (flags, message) => {
|
|
3637
|
+
const includeButtons = getInputActionsInclude(flags);
|
|
3638
|
+
const excludeButtons = getInputActionsExclude(flags);
|
|
3639
|
+
return [{
|
|
3640
|
+
type: Div,
|
|
3641
|
+
className: SearchHeaderDetailsExpanded,
|
|
3642
|
+
childCount: 5
|
|
3643
|
+
}, {
|
|
3644
|
+
type: Div,
|
|
3645
|
+
className: SearchHeaderDetailsExpandedTop,
|
|
3646
|
+
childCount: 2
|
|
3647
|
+
}, ...getSearchDetailsToggleVirtualDom(), {
|
|
3648
|
+
type: H4,
|
|
3649
|
+
className: SearchHeaderDetailsHeading,
|
|
3650
|
+
childCount: 1
|
|
3651
|
+
}, text(filesToInclude()), ...getSearchFieldVirtualDom(FilesToInclude, 'Include', HandleInput2, includeButtons.inside, includeButtons.outside), {
|
|
3652
|
+
type: H4,
|
|
3653
|
+
className: SearchHeaderDetailsHeading,
|
|
3654
|
+
childCount: 1
|
|
3655
|
+
}, text(filesToExclude()), ...getSearchFieldVirtualDom(FilesToExclude, 'Exclude', HandleInput2, excludeButtons.inside, excludeButtons.outside), ...getSearchMessageVirtualDom(message, false)];
|
|
3656
|
+
};
|
|
3657
|
+
|
|
3658
|
+
const getSearchHeaderDetailsVirtualDom = (flags, message) => {
|
|
3659
|
+
if (flags & DetailsExpanded) {
|
|
3660
|
+
return getSearchHeaderDetailsExpandedVirtualDom(flags, message);
|
|
3690
3661
|
}
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
const maxLineY = Math.min(minLineY + getNumberOfVisibleItems(listHeight, itemHeight), items.length);
|
|
3662
|
+
return getSearchHeaderDetailsCollapsedVirtualDom(message);
|
|
3663
|
+
};
|
|
3694
3664
|
|
|
3695
|
-
|
|
3665
|
+
const getInputActionsInput = flags => {
|
|
3666
|
+
const inside = [{
|
|
3667
|
+
icon: MaskIconCaseSensitive,
|
|
3668
|
+
flag: flags & MatchCase$2 ? CheckBoxEnabled : CheckBoxDisabled,
|
|
3669
|
+
title: matchCase(),
|
|
3670
|
+
name: MatchCase
|
|
3671
|
+
}, {
|
|
3672
|
+
icon: MaskIconWholeWord,
|
|
3673
|
+
flag: flags & MatchWholeWord$2 ? CheckBoxEnabled : CheckBoxDisabled,
|
|
3674
|
+
title: matchWholeWord(),
|
|
3675
|
+
name: MatchWholeWord
|
|
3676
|
+
}, {
|
|
3677
|
+
icon: MaskIconRegex,
|
|
3678
|
+
flag: flags & UseRegularExpression$2 ? CheckBoxEnabled : CheckBoxDisabled,
|
|
3679
|
+
title: useRegularExpression(),
|
|
3680
|
+
name: UseRegularExpression
|
|
3681
|
+
}];
|
|
3682
|
+
const outside = [];
|
|
3696
3683
|
return {
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
minLineY,
|
|
3700
|
-
maxLineY
|
|
3684
|
+
inside,
|
|
3685
|
+
outside
|
|
3701
3686
|
};
|
|
3702
3687
|
};
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
return {
|
|
3718
|
-
...state,
|
|
3719
|
-
handleOffset: diff,
|
|
3720
|
-
scrollBarActive: true
|
|
3721
|
-
};
|
|
3722
|
-
}
|
|
3723
|
-
const {
|
|
3724
|
-
percent,
|
|
3725
|
-
handleOffset
|
|
3726
|
-
} = getNewDeltaPercent(contentHeight, scrollBarHeight, relativeY);
|
|
3727
|
-
const newDeltaY = percent * finalDeltaY;
|
|
3688
|
+
|
|
3689
|
+
const getInputActionsReplace = (flags, matchCount) => {
|
|
3690
|
+
const inside = [{
|
|
3691
|
+
icon: MaskIconPreserveCase,
|
|
3692
|
+
flag: flags & PreserveCase$2 ? CheckBoxEnabled : CheckBoxDisabled,
|
|
3693
|
+
title: preserveCase(),
|
|
3694
|
+
name: PreserveCase
|
|
3695
|
+
}];
|
|
3696
|
+
const outside = [{
|
|
3697
|
+
icon: MaskIconReplaceAll,
|
|
3698
|
+
flag: matchCount === 0 ? ButtonDisabled : ButtonEnabled,
|
|
3699
|
+
title: replaceAll$1(),
|
|
3700
|
+
name: ReplaceAll
|
|
3701
|
+
}];
|
|
3728
3702
|
return {
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
scrollBarActive: true
|
|
3703
|
+
inside,
|
|
3704
|
+
outside
|
|
3732
3705
|
};
|
|
3733
3706
|
};
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
} = state;
|
|
3751
|
-
const relativeY = eventY - y - headerHeight - handleOffset;
|
|
3752
|
-
const contentHeight = height - headerHeight;
|
|
3753
|
-
const newPercent = getNewPercent(contentHeight, scrollBarHeight, relativeY);
|
|
3754
|
-
const newDeltaY = newPercent * finalDeltaY;
|
|
3755
|
-
return setDeltaY(state, newDeltaY);
|
|
3756
|
-
};
|
|
3757
|
-
const handleWheel = (state, deltaMode, deltaY) => {
|
|
3758
|
-
number(deltaMode);
|
|
3759
|
-
number(deltaY);
|
|
3760
|
-
return setDeltaY(state, state.deltaY + deltaY);
|
|
3707
|
+
|
|
3708
|
+
const getSearchToggleVirtualDom = flags => {
|
|
3709
|
+
return [{
|
|
3710
|
+
type: Button$1,
|
|
3711
|
+
className: mergeClassNames(IconButton, SearchToggleButton, flags & ReplaceExpanded ? SearchToggleButtonExpanded : ''),
|
|
3712
|
+
title: toggleReplace$1(),
|
|
3713
|
+
ariaLabel: toggleReplace$1(),
|
|
3714
|
+
ariaExpanded: Boolean(flags & ReplaceExpanded),
|
|
3715
|
+
childCount: 1,
|
|
3716
|
+
'data-command': 'toggleReplace',
|
|
3717
|
+
name: ToggleReplace
|
|
3718
|
+
}, {
|
|
3719
|
+
type: Div,
|
|
3720
|
+
className: mergeClassNames(MaskIcon, flags & ReplaceExpanded ? MaskIconChevronDown : MaskIconChevronRight),
|
|
3721
|
+
childCount: 0
|
|
3722
|
+
}];
|
|
3761
3723
|
};
|
|
3762
3724
|
|
|
3763
|
-
const
|
|
3764
|
-
const
|
|
3765
|
-
const
|
|
3766
|
-
|
|
3767
|
-
|
|
3725
|
+
const getSearchHeaderTopVirtualDom = (flags, searchInputErrorMessage, matchCount) => {
|
|
3726
|
+
const inputActions = getInputActionsInput(flags);
|
|
3727
|
+
const replaceActions = getInputActionsReplace(flags, matchCount);
|
|
3728
|
+
const dom = [{
|
|
3729
|
+
type: Div,
|
|
3730
|
+
className: SearchHeaderTop,
|
|
3731
|
+
role: None,
|
|
3732
|
+
childCount: 2
|
|
3733
|
+
}, ...getSearchToggleVirtualDom(flags), {
|
|
3734
|
+
type: Div,
|
|
3735
|
+
className: SearchHeaderTopRight,
|
|
3736
|
+
role: None,
|
|
3737
|
+
childCount: flags & ReplaceExpanded ? 2 : 1
|
|
3738
|
+
}, ...getSearchFieldVirtualDom(SearchValue, 'Search', HandleInput2, inputActions.inside, inputActions.outside, '', Boolean(searchInputErrorMessage))];
|
|
3739
|
+
if (flags & ReplaceExpanded) {
|
|
3740
|
+
dom.push(...getSearchFieldVirtualDom(ReplaceValue, 'Replace', HandleInput2, replaceActions.inside, replaceActions.outside));
|
|
3768
3741
|
}
|
|
3769
|
-
return
|
|
3742
|
+
return dom;
|
|
3770
3743
|
};
|
|
3771
3744
|
|
|
3772
|
-
const
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
|
|
3781
|
-
|
|
3782
|
-
return
|
|
3745
|
+
const parentNode = {
|
|
3746
|
+
type: Div,
|
|
3747
|
+
className: SearchHeader,
|
|
3748
|
+
role: None,
|
|
3749
|
+
childCount: 2,
|
|
3750
|
+
onClick: HandleHeaderClick2,
|
|
3751
|
+
onFocusIn: HandleHeaderFocusIn
|
|
3752
|
+
};
|
|
3753
|
+
const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage, matchCount) => {
|
|
3754
|
+
const dom = [parentNode, ...getSearchHeaderTopVirtualDom(flags, searchInputErrorMessage, matchCount), ...getSearchHeaderDetailsVirtualDom(flags, message)];
|
|
3755
|
+
return dom;
|
|
3783
3756
|
};
|
|
3784
3757
|
|
|
3785
|
-
const
|
|
3786
|
-
if (
|
|
3787
|
-
return
|
|
3788
|
-
}
|
|
3789
|
-
const filteredResults = [];
|
|
3790
|
-
let isExcluded = false;
|
|
3791
|
-
for (const result of results) {
|
|
3792
|
-
if (result.type === File) {
|
|
3793
|
-
filteredResults.push(result);
|
|
3794
|
-
isExcluded = collapsedPaths.includes(result.text) ? true : false;
|
|
3795
|
-
}
|
|
3796
|
-
if (result.type === Match && !isExcluded) {
|
|
3797
|
-
filteredResults.push(result);
|
|
3798
|
-
}
|
|
3758
|
+
const getSearchInputErrorVirtualDom = errorMessage => {
|
|
3759
|
+
if (!errorMessage) {
|
|
3760
|
+
return [];
|
|
3799
3761
|
}
|
|
3800
|
-
return
|
|
3762
|
+
return [{
|
|
3763
|
+
type: Div,
|
|
3764
|
+
className: SearchInputError,
|
|
3765
|
+
role: Alert,
|
|
3766
|
+
childCount: 1
|
|
3767
|
+
}, text(errorMessage)];
|
|
3801
3768
|
};
|
|
3802
3769
|
|
|
3803
|
-
const
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3770
|
+
const TreeItems = 'TreeItems';
|
|
3771
|
+
|
|
3772
|
+
const getScrollBarVirtualDom = (scrollBarHeight, scrollBarY, scrollBarValue) => {
|
|
3773
|
+
if (scrollBarHeight === 0) {
|
|
3774
|
+
return [];
|
|
3807
3775
|
}
|
|
3808
|
-
return [
|
|
3776
|
+
return [{
|
|
3777
|
+
type: Div,
|
|
3778
|
+
className: mergeClassNames(ScrollBar$1, ScrollBarVertical),
|
|
3779
|
+
childCount: 1,
|
|
3780
|
+
onPointerDown: HandleScrollBarPointerDown,
|
|
3781
|
+
role: ScrollBar,
|
|
3782
|
+
ariaControls: TreeItems,
|
|
3783
|
+
ariaValueNow: scrollBarValue
|
|
3784
|
+
}, {
|
|
3785
|
+
type: Div,
|
|
3786
|
+
className: ScrollBarThumb,
|
|
3787
|
+
height: scrollBarHeight,
|
|
3788
|
+
translate: `0 ${scrollBarY}px`,
|
|
3789
|
+
childCount: 0
|
|
3790
|
+
}];
|
|
3809
3791
|
};
|
|
3810
3792
|
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
|
|
3817
|
-
|
|
3818
|
-
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
const icons = await getFileIcons(filteredResults);
|
|
3823
|
-
const total = filteredResults.length;
|
|
3824
|
-
const listHeight = height - headerHeight;
|
|
3825
|
-
const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
|
|
3826
|
-
const maxLineY = Math.min(numberOfVisible, total);
|
|
3827
|
-
return {
|
|
3828
|
-
...state,
|
|
3829
|
-
collapsedPaths: newCollapsedPaths,
|
|
3830
|
-
listFocusedIndex: index,
|
|
3831
|
-
listFocused: true,
|
|
3832
|
-
listItems: filteredResults,
|
|
3833
|
-
maxLineY,
|
|
3834
|
-
icons
|
|
3835
|
-
};
|
|
3793
|
+
// TODO instead of setting string, support enum in virtual dom and send enum to renderer process
|
|
3794
|
+
// which converts it to a boolean
|
|
3795
|
+
const getAriaExpanded = expanded => {
|
|
3796
|
+
switch (expanded) {
|
|
3797
|
+
case Collapsed:
|
|
3798
|
+
return 'false';
|
|
3799
|
+
case Expanded:
|
|
3800
|
+
return 'true';
|
|
3801
|
+
default:
|
|
3802
|
+
return undefined;
|
|
3803
|
+
}
|
|
3836
3804
|
};
|
|
3837
3805
|
|
|
3838
|
-
const
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
if (item.type === File) {
|
|
3842
|
-
return i;
|
|
3843
|
-
}
|
|
3806
|
+
const getBadgeVirtualDom = (className, badgeText) => {
|
|
3807
|
+
if (!badgeText) {
|
|
3808
|
+
return [];
|
|
3844
3809
|
}
|
|
3845
|
-
return
|
|
3810
|
+
return [{
|
|
3811
|
+
type: Div,
|
|
3812
|
+
className: mergeClassNames(Badge, className),
|
|
3813
|
+
childCount: 1
|
|
3814
|
+
}, text(badgeText)];
|
|
3846
3815
|
};
|
|
3847
3816
|
|
|
3848
|
-
const
|
|
3849
|
-
|
|
3817
|
+
const chevronDownVirtualDom = {
|
|
3818
|
+
type: Div,
|
|
3819
|
+
className: mergeClassNames(Chevron, MaskIconChevronDown),
|
|
3820
|
+
childCount: 0
|
|
3821
|
+
};
|
|
3822
|
+
const chevronRightVirtualDom = {
|
|
3823
|
+
type: Div,
|
|
3824
|
+
className: mergeClassNames(Chevron, MaskIconChevronRight),
|
|
3825
|
+
childCount: 0
|
|
3850
3826
|
};
|
|
3851
3827
|
|
|
3852
|
-
const
|
|
3853
|
-
const {
|
|
3854
|
-
items,
|
|
3855
|
-
workspacePath
|
|
3856
|
-
} = state;
|
|
3857
|
-
const fileIndex = getFileIndex(items, index);
|
|
3858
|
-
if (fileIndex === -1) {
|
|
3859
|
-
throw new Error('Search result is missing file');
|
|
3860
|
-
}
|
|
3861
|
-
const {
|
|
3862
|
-
lineNumber
|
|
3863
|
-
} = searchResult;
|
|
3864
|
-
const fileResult = items[fileIndex];
|
|
3865
|
-
const relativePath = getRelativePath(fileResult.text);
|
|
3866
|
-
const absolutePath = `${workspacePath}${relativePath}`;
|
|
3867
|
-
await openUri(absolutePath, true, {
|
|
3868
|
-
selections: new Uint32Array([lineNumber, 0, lineNumber, 0])
|
|
3869
|
-
});
|
|
3828
|
+
const getFileIconVirtualDom = icon => {
|
|
3870
3829
|
return {
|
|
3871
|
-
|
|
3872
|
-
|
|
3873
|
-
|
|
3830
|
+
type: Img,
|
|
3831
|
+
className: FileIcon,
|
|
3832
|
+
src: icon,
|
|
3833
|
+
role: None,
|
|
3834
|
+
childCount: 0
|
|
3874
3835
|
};
|
|
3875
3836
|
};
|
|
3876
3837
|
|
|
3877
|
-
const
|
|
3878
|
-
switch (
|
|
3879
|
-
case
|
|
3880
|
-
return
|
|
3881
|
-
case
|
|
3882
|
-
return
|
|
3838
|
+
const getIconsVirtualDom = (expanded, icon) => {
|
|
3839
|
+
switch (expanded) {
|
|
3840
|
+
case Expanded:
|
|
3841
|
+
return [chevronDownVirtualDom, getFileIconVirtualDom(icon)];
|
|
3842
|
+
case Collapsed:
|
|
3843
|
+
return [chevronRightVirtualDom, getFileIconVirtualDom(icon)];
|
|
3883
3844
|
default:
|
|
3884
|
-
|
|
3845
|
+
return [];
|
|
3885
3846
|
}
|
|
3886
3847
|
};
|
|
3887
3848
|
|
|
3888
|
-
const
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
listFocused: true,
|
|
3893
|
-
listFocusedIndex: -1
|
|
3894
|
-
};
|
|
3895
|
-
}
|
|
3896
|
-
const {
|
|
3897
|
-
listItems
|
|
3898
|
-
} = state;
|
|
3899
|
-
const searchResult = listItems[index];
|
|
3900
|
-
const fn = getSelectHandler(searchResult.type);
|
|
3901
|
-
return fn(state, searchResult, index);
|
|
3849
|
+
const deleted = {
|
|
3850
|
+
type: Del,
|
|
3851
|
+
className: HighlightDeleted,
|
|
3852
|
+
childCount: 1
|
|
3902
3853
|
};
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
y,
|
|
3908
|
-
itemHeight,
|
|
3909
|
-
deltaY,
|
|
3910
|
-
flags,
|
|
3911
|
-
listItems
|
|
3912
|
-
} = state;
|
|
3913
|
-
const topHeight = getTopHeight(flags);
|
|
3914
|
-
const index = getListIndex(eventX, eventY, x, y, deltaY, itemHeight, topHeight, listItems.length);
|
|
3915
|
-
return selectIndex(state, index);
|
|
3854
|
+
const inserted = {
|
|
3855
|
+
type: Ins,
|
|
3856
|
+
className: HighlightInserted,
|
|
3857
|
+
childCount: 1
|
|
3916
3858
|
};
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
}
|
|
3922
|
-
return '';
|
|
3859
|
+
const highlighted = {
|
|
3860
|
+
type: Span,
|
|
3861
|
+
className: Highlight,
|
|
3862
|
+
childCount: 1
|
|
3923
3863
|
};
|
|
3924
|
-
const
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
return '';
|
|
3864
|
+
const label1 = {
|
|
3865
|
+
type: Div,
|
|
3866
|
+
className: mergeClassNames(Label, Grow),
|
|
3867
|
+
childCount: 1
|
|
3929
3868
|
};
|
|
3930
|
-
const
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
}
|
|
3934
|
-
return 0;
|
|
3869
|
+
const label3 = {
|
|
3870
|
+
...label1,
|
|
3871
|
+
childCount: 3
|
|
3935
3872
|
};
|
|
3936
|
-
const
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
}
|
|
3940
|
-
return '';
|
|
3873
|
+
const label4 = {
|
|
3874
|
+
...label1,
|
|
3875
|
+
childCount: 4
|
|
3941
3876
|
};
|
|
3942
|
-
const
|
|
3943
|
-
if (
|
|
3944
|
-
|
|
3877
|
+
const getLabelVirtualDom = (displayText, matchLength, matchStart, replacement) => {
|
|
3878
|
+
if (matchLength) {
|
|
3879
|
+
const before = displayText.slice(0, matchStart);
|
|
3880
|
+
const highlight = displayText.slice(matchStart, matchStart + matchLength);
|
|
3881
|
+
const after = displayText.slice(matchStart + matchLength);
|
|
3882
|
+
if (replacement) {
|
|
3883
|
+
return [label4, text(before), deleted, text(highlight), inserted, text(replacement), text(after)];
|
|
3884
|
+
}
|
|
3885
|
+
return [label3, text(before), highlighted, text(highlight), text(after)];
|
|
3945
3886
|
}
|
|
3946
|
-
return
|
|
3887
|
+
return [label1, text(displayText)];
|
|
3947
3888
|
};
|
|
3948
3889
|
|
|
3949
|
-
const
|
|
3950
|
-
return {
|
|
3951
|
-
savedValue: getSavedValue(savedState),
|
|
3952
|
-
replacement: getSavedReplacement(savedState),
|
|
3953
|
-
savedCollapsedPaths: [],
|
|
3954
|
-
threads: 1,
|
|
3955
|
-
flags: getSavedFlags(savedState),
|
|
3956
|
-
includeValue: getSavedIncludeValue(savedState),
|
|
3957
|
-
excludeValue: getSavedExcludeValue(savedState)
|
|
3958
|
-
};
|
|
3890
|
+
const getPaddingLeft = depth => {
|
|
3891
|
+
return `${Number(depth) + 1}rem`; // TODO use classname and dynamic css
|
|
3959
3892
|
};
|
|
3960
3893
|
|
|
3961
|
-
const
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
savedCollapsedPaths,
|
|
3965
|
-
threads,
|
|
3966
|
-
replacement,
|
|
3967
|
-
flags,
|
|
3968
|
-
includeValue,
|
|
3969
|
-
excludeValue
|
|
3970
|
-
} = restoreState(savedState);
|
|
3971
|
-
if (savedValue) {
|
|
3972
|
-
return handleUpdate(state, {
|
|
3973
|
-
value: savedValue,
|
|
3974
|
-
threads,
|
|
3975
|
-
inputSource: Script,
|
|
3976
|
-
collapsedPaths: savedCollapsedPaths,
|
|
3977
|
-
replacement,
|
|
3978
|
-
flags,
|
|
3979
|
-
includeValue,
|
|
3980
|
-
excludeValue
|
|
3981
|
-
});
|
|
3894
|
+
const getSearchResultClassName = focused => {
|
|
3895
|
+
if (focused) {
|
|
3896
|
+
return TreeItem$1 + ' ' + TreeItemActive;
|
|
3982
3897
|
}
|
|
3983
|
-
return
|
|
3984
|
-
...state,
|
|
3985
|
-
threads,
|
|
3986
|
-
flags,
|
|
3987
|
-
loaded: true
|
|
3988
|
-
};
|
|
3898
|
+
return TreeItem$1;
|
|
3989
3899
|
};
|
|
3990
3900
|
|
|
3991
|
-
const
|
|
3992
|
-
|
|
3901
|
+
const PaddingRight = '12px';
|
|
3902
|
+
|
|
3903
|
+
const getSearchResultVirtualDom = rowInfo => {
|
|
3904
|
+
const {
|
|
3905
|
+
matchStart,
|
|
3906
|
+
matchLength,
|
|
3907
|
+
text: displayText,
|
|
3908
|
+
title,
|
|
3909
|
+
icon,
|
|
3910
|
+
setSize,
|
|
3911
|
+
posInSet,
|
|
3912
|
+
depth,
|
|
3913
|
+
replacement,
|
|
3914
|
+
focused,
|
|
3915
|
+
expanded,
|
|
3916
|
+
childCount,
|
|
3917
|
+
badgeText
|
|
3918
|
+
} = rowInfo;
|
|
3919
|
+
const dom = [{
|
|
3920
|
+
type: Div,
|
|
3921
|
+
role: TreeItem,
|
|
3922
|
+
className: getSearchResultClassName(focused),
|
|
3923
|
+
title,
|
|
3924
|
+
ariaSetSize: setSize,
|
|
3925
|
+
ariaLevel: depth,
|
|
3926
|
+
ariaPosInSet: posInSet,
|
|
3927
|
+
ariaLabel: title,
|
|
3928
|
+
ariaDescription: '',
|
|
3929
|
+
childCount,
|
|
3930
|
+
paddingLeft: getPaddingLeft(depth),
|
|
3931
|
+
paddingRight: PaddingRight,
|
|
3932
|
+
ariaExpanded: getAriaExpanded(expanded)
|
|
3933
|
+
}, ...getIconsVirtualDom(expanded, icon), ...getLabelVirtualDom(displayText, matchLength, matchStart, replacement), ...getBadgeVirtualDom(SourceControlBadge, badgeText), {
|
|
3934
|
+
type: Div,
|
|
3935
|
+
className: SearchRemove,
|
|
3936
|
+
childCount: 1
|
|
3937
|
+
}, {
|
|
3938
|
+
type: Div,
|
|
3939
|
+
className: CloseMaskIcon,
|
|
3940
|
+
childCount: 0
|
|
3941
|
+
}];
|
|
3942
|
+
return dom;
|
|
3993
3943
|
};
|
|
3994
3944
|
|
|
3995
|
-
const
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
case FocusSearchRegex:
|
|
4008
|
-
return UseRegularExpression;
|
|
4009
|
-
case FocusSearchIncludeInput:
|
|
4010
|
-
return FilesToInclude;
|
|
4011
|
-
case FocusSearchExcludeInput:
|
|
4012
|
-
return FilesToExclude;
|
|
4013
|
-
case FocusSearchWholeWord:
|
|
4014
|
-
return MatchWholeWord;
|
|
4015
|
-
case FocusSearchReplaceAll:
|
|
4016
|
-
return ReplaceAll;
|
|
4017
|
-
case FocusSearchOpenEditors:
|
|
4018
|
-
return SearchOnlyOpenEditors;
|
|
4019
|
-
case FocusIgnoreFiles:
|
|
4020
|
-
return UseExcludeSettings;
|
|
4021
|
-
case FocusToggleReplace:
|
|
4022
|
-
return ToggleReplace;
|
|
4023
|
-
default:
|
|
4024
|
-
return '';
|
|
4025
|
-
}
|
|
3945
|
+
const getTreeItemsVirtualDom = (visibleItems, deltaY, itemHeight) => {
|
|
3946
|
+
const pixelOffset = deltaY % itemHeight;
|
|
3947
|
+
return [{
|
|
3948
|
+
type: Div,
|
|
3949
|
+
className: TreeItems$1,
|
|
3950
|
+
childCount: visibleItems.length,
|
|
3951
|
+
onClick: HandleClick,
|
|
3952
|
+
onBlur: HandleListBlur,
|
|
3953
|
+
onWheel: HandleWheel,
|
|
3954
|
+
id: TreeItems,
|
|
3955
|
+
top: `${-pixelOffset}px`
|
|
3956
|
+
}, ...visibleItems.flatMap(getSearchResultVirtualDom)];
|
|
4026
3957
|
};
|
|
4027
3958
|
|
|
4028
|
-
const
|
|
4029
|
-
const
|
|
4030
|
-
return [
|
|
3959
|
+
const getSearchResultsVirtualDom = (visibleItems, focusOutline, scrollbarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight) => {
|
|
3960
|
+
const scrollBarDomNodes = scrollbarHeight === 0 ? 0 : 1;
|
|
3961
|
+
return [{
|
|
3962
|
+
type: Div,
|
|
3963
|
+
className: mergeClassNames(Viewlet, List, Tree$1, focusOutline ? FocusOutline : Empty),
|
|
3964
|
+
role: Tree,
|
|
3965
|
+
tabIndex: 0,
|
|
3966
|
+
childCount: 1 + scrollBarDomNodes
|
|
3967
|
+
}, ...getTreeItemsVirtualDom(visibleItems, deltaY, itemHeight), ...getScrollBarVirtualDom(scrollbarHeight, scrollBarY, scrollBarValue)];
|
|
4031
3968
|
};
|
|
4032
3969
|
|
|
4033
|
-
const
|
|
4034
|
-
const
|
|
4035
|
-
|
|
4036
|
-
|
|
4037
|
-
|
|
4038
|
-
|
|
4039
|
-
|
|
4040
|
-
|
|
4041
|
-
replacement,
|
|
4042
|
-
icons,
|
|
4043
|
-
listFocusedIndex,
|
|
4044
|
-
collapsedPaths,
|
|
4045
|
-
items,
|
|
4046
|
-
listFocused,
|
|
4047
|
-
deltaY,
|
|
4048
|
-
finalDeltaY,
|
|
4049
|
-
height,
|
|
4050
|
-
headerHeight,
|
|
4051
|
-
flags,
|
|
4052
|
-
message,
|
|
4053
|
-
searchInputErrorMessage,
|
|
4054
|
-
scrollBarHeight,
|
|
4055
|
-
matchCount
|
|
4056
|
-
} = state;
|
|
4057
|
-
const displayResults = getDisplayResults(listItems, itemHeight, fileCount, value, minLineY, maxLineY, replacement, icons, listFocusedIndex, collapsedPaths, items);
|
|
4058
|
-
const focusOutline = listFocused && listFocusedIndex === -1;
|
|
4059
|
-
const scrollBarValue = deltaY / finalDeltaY * 100;
|
|
4060
|
-
const scrollBarY = getScrollBarY$1(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
|
|
4061
|
-
return {
|
|
4062
|
-
displayResults,
|
|
4063
|
-
flags,
|
|
4064
|
-
message,
|
|
4065
|
-
focusOutline,
|
|
4066
|
-
searchInputErrorMessage,
|
|
4067
|
-
scrollBarHeight,
|
|
4068
|
-
scrollBarY,
|
|
4069
|
-
scrollBarValue,
|
|
4070
|
-
deltaY,
|
|
4071
|
-
itemHeight,
|
|
4072
|
-
matchCount
|
|
4073
|
-
};
|
|
3970
|
+
const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchInputErrorMessage, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight, matchCount) => {
|
|
3971
|
+
const errorDom = getSearchInputErrorVirtualDom(searchInputErrorMessage);
|
|
3972
|
+
const childCount = 2 + (errorDom.length > 0 ? 1 : 0);
|
|
3973
|
+
return [{
|
|
3974
|
+
type: Div,
|
|
3975
|
+
className: mergeClassNames(Viewlet, Search$1),
|
|
3976
|
+
childCount
|
|
3977
|
+
}, ...getSearchHeaderVirtualDom(flags, message, searchInputErrorMessage, matchCount), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight)];
|
|
4074
3978
|
};
|
|
4075
3979
|
|
|
4076
3980
|
const renderItems = (oldState, newState) => {
|
|
@@ -4130,6 +4034,50 @@ const render2 = (uid, diffResult) => {
|
|
|
4130
4034
|
return commands;
|
|
4131
4035
|
};
|
|
4132
4036
|
|
|
4037
|
+
const Button = 1;
|
|
4038
|
+
|
|
4039
|
+
const getIconVirtualDom = (icon, type = Div) => {
|
|
4040
|
+
return {
|
|
4041
|
+
type,
|
|
4042
|
+
className: mergeClassNames(MaskIcon, `MaskIcon${icon}`),
|
|
4043
|
+
role: None,
|
|
4044
|
+
childCount: 0
|
|
4045
|
+
};
|
|
4046
|
+
};
|
|
4047
|
+
|
|
4048
|
+
const getActionButtonVirtualDom = action => {
|
|
4049
|
+
const {
|
|
4050
|
+
id,
|
|
4051
|
+
icon,
|
|
4052
|
+
command
|
|
4053
|
+
} = action;
|
|
4054
|
+
return [{
|
|
4055
|
+
type: Button$1,
|
|
4056
|
+
className: IconButton,
|
|
4057
|
+
title: id,
|
|
4058
|
+
'data-command': command,
|
|
4059
|
+
childCount: 1
|
|
4060
|
+
}, getIconVirtualDom(icon)];
|
|
4061
|
+
};
|
|
4062
|
+
|
|
4063
|
+
const getActionVirtualDom = action => {
|
|
4064
|
+
switch (action.type) {
|
|
4065
|
+
case Button:
|
|
4066
|
+
return getActionButtonVirtualDom(action);
|
|
4067
|
+
default:
|
|
4068
|
+
return [];
|
|
4069
|
+
}
|
|
4070
|
+
};
|
|
4071
|
+
|
|
4072
|
+
const getActionsVirtualDom = actions => {
|
|
4073
|
+
return [{
|
|
4074
|
+
type: Div,
|
|
4075
|
+
className: Actions,
|
|
4076
|
+
role: ToolBar,
|
|
4077
|
+
childCount: actions.length
|
|
4078
|
+
}, ...actions.flatMap(getActionVirtualDom)];
|
|
4079
|
+
};
|
|
4080
|
+
|
|
4133
4081
|
const renderActions = uid => {
|
|
4134
4082
|
const {
|
|
4135
4083
|
oldState,
|
|
@@ -4145,6 +4093,9 @@ const renderActions = uid => {
|
|
|
4145
4093
|
|
|
4146
4094
|
const renderEventListeners = () => {
|
|
4147
4095
|
return [{
|
|
4096
|
+
name: HandleInput2,
|
|
4097
|
+
params: ['handleInput2', 'event.target.name', 'event.target.value', User]
|
|
4098
|
+
}, {
|
|
4148
4099
|
name: HandleExcludeInput,
|
|
4149
4100
|
params: ['handleExcludeInput', 'event.target.value']
|
|
4150
4101
|
}, {
|
|
@@ -4158,7 +4109,7 @@ const renderEventListeners = () => {
|
|
|
4158
4109
|
params: ['handleInput', 'event.target.value', User]
|
|
4159
4110
|
}, {
|
|
4160
4111
|
name: HandleClick,
|
|
4161
|
-
params: ['
|
|
4112
|
+
params: ['handleClickAt', 'event.clientX', 'event.clientY']
|
|
4162
4113
|
}, {
|
|
4163
4114
|
name: HandleToggleButtonClick,
|
|
4164
4115
|
params: ['handleToggleButtonClick']
|
|
@@ -4209,6 +4160,10 @@ const renderIncremental = uid => {
|
|
|
4209
4160
|
return patches;
|
|
4210
4161
|
};
|
|
4211
4162
|
|
|
4163
|
+
const prompt = (text, options) => {
|
|
4164
|
+
return invoke$2('ConfirmPrompt.prompt', text, options);
|
|
4165
|
+
};
|
|
4166
|
+
|
|
4212
4167
|
const getReplaceAllConfirmText = (matchCount, fileCount, replacement) => {
|
|
4213
4168
|
if (matchCount === 1) {
|
|
4214
4169
|
if (replacement) {
|
|
@@ -4237,7 +4192,7 @@ const replaceAllAndPrompt = async (workspacePath, items, replacement, matchCount
|
|
|
4237
4192
|
const confirmTitle = replaceAll$1();
|
|
4238
4193
|
const confirmAccept = replace();
|
|
4239
4194
|
const confirmText = getReplaceAllConfirmText(matchCount, fileCount, replacement);
|
|
4240
|
-
const shouldReplace = await
|
|
4195
|
+
const shouldReplace = await prompt(confirmText, {
|
|
4241
4196
|
title: confirmTitle,
|
|
4242
4197
|
confirmMessage: confirmAccept
|
|
4243
4198
|
});
|
|
@@ -4438,7 +4393,7 @@ const wrapCommand = fn => {
|
|
|
4438
4393
|
};
|
|
4439
4394
|
|
|
4440
4395
|
const commandMap = {
|
|
4441
|
-
'TextSearch.clearSearchResults': wrapCommand(clearSearchResults
|
|
4396
|
+
'TextSearch.clearSearchResults': wrapCommand(clearSearchResults),
|
|
4442
4397
|
'TextSearch.collapseDetails': wrapCommand(collapseDetails),
|
|
4443
4398
|
'TextSearch.copy': wrapCommand(copy),
|
|
4444
4399
|
'TextSearch.diff2': diff2,
|
|
@@ -4476,6 +4431,7 @@ const commandMap = {
|
|
|
4476
4431
|
'TextSearch.handleIconThemeChange': wrapCommand(handleIconThemeChange),
|
|
4477
4432
|
'TextSearch.handleIncludeInput': wrapCommand(handleIncludeInput),
|
|
4478
4433
|
'TextSearch.handleInput': wrapCommand(handleInput),
|
|
4434
|
+
'TextSearch.handleInput2': wrapCommand(handleInput2),
|
|
4479
4435
|
'TextSearch.handleListBlur': wrapCommand(handleListBlur),
|
|
4480
4436
|
'TextSearch.handleReplaceInput': wrapCommand(handleReplaceInput),
|
|
4481
4437
|
'TextSearch.handleScrollBarCaptureLost': wrapCommand(handleScrollBarCaptureLost),
|
|
@@ -4509,11 +4465,7 @@ const commandMap = {
|
|
|
4509
4465
|
'TextSearch.terminate': terminate,
|
|
4510
4466
|
// TODO needed?
|
|
4511
4467
|
'TextSearch.replaceAllAndPrompt': replaceAllAndPrompt,
|
|
4512
|
-
'TextSearch.textSearch': textSearch
|
|
4513
|
-
'TextSearch.getActions': getActions,
|
|
4514
|
-
'TextSearch.getActionsVirtualDom': getActionsVirtualDom,
|
|
4515
|
-
'TextSearch.getSearchDisplayResults': getDisplayResults,
|
|
4516
|
-
'TextSearch.getVirtualDom': getSearchVirtualDom
|
|
4468
|
+
'TextSearch.textSearch': textSearch
|
|
4517
4469
|
};
|
|
4518
4470
|
|
|
4519
4471
|
const listen = async () => {
|