@lvce-editor/text-search-worker 4.0.0 → 4.2.0

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