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