@lvce-editor/text-search-worker 3.52.0 → 4.1.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,
@@ -1306,12 +1309,6 @@ const diff2 = uid => {
1306
1309
 
1307
1310
  // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
1308
1311
 
1309
- const isLastIndex = (array, index) => {
1310
- return index === array.length - 1;
1311
- };
1312
- const lastIndex = array => {
1313
- return array.length - 1;
1314
- };
1315
1312
  const remove = (array, index, deleteCount) => {
1316
1313
  return array.toSpliced(index, deleteCount);
1317
1314
  };
@@ -1754,7 +1751,7 @@ const focusSearchValueNext = state => {
1754
1751
  };
1755
1752
 
1756
1753
  const Alert = 'alert';
1757
- const Button$3 = 'button';
1754
+ const Button$2 = 'button';
1758
1755
  const CheckBox = 'checkbox';
1759
1756
  const None$1 = 'none';
1760
1757
  const ScrollBar$1 = 'scrollbar';
@@ -1792,7 +1789,7 @@ const MultilineInputBox = 'MultilineInputBox';
1792
1789
  const ScrollBar = 'ScrollBar';
1793
1790
  const ScrollBarThumb = 'ScrollBarThumb';
1794
1791
  const ScrollBarVertical = 'ScrollBarVertical';
1795
- const Search$2 = 'Search';
1792
+ const Search$1 = 'Search';
1796
1793
  const SearchField = 'SearchField';
1797
1794
  const SearchFieldButton = 'SearchFieldButton';
1798
1795
  const SearchFieldButtonChecked = 'SearchFieldButtonChecked';
@@ -1821,146 +1818,21 @@ const Viewlet = 'Viewlet';
1821
1818
  const ViewletSearchMessage = 'ViewletSearchMessage';
1822
1819
  const ViewletSearchMessageIndented = 'ViewletSearchMessageIndented';
1823
1820
 
1824
- const Button$2 = 1;
1825
-
1826
- var __defProp = Object.defineProperty;
1827
- var __export = (target, all) => {
1828
- for (var name in all) __defProp(target, name, {
1829
- get: all[name],
1830
- enumerable: true
1831
- });
1832
- };
1833
-
1834
- // src/parts/MergeClassNames/MergeClassNames.ts
1835
- var mergeClassNames = (...classNames) => {
1836
- return classNames.filter(Boolean).join(" ");
1837
- };
1838
-
1839
- // src/parts/VirtualDomElements/VirtualDomElements.ts
1840
- var VirtualDomElements_exports = {};
1841
- __export(VirtualDomElements_exports, {
1842
- A: () => A,
1843
- Abbr: () => Abbr,
1844
- Article: () => Article,
1845
- Aside: () => Aside,
1846
- Audio: () => Audio,
1847
- Br: () => Br,
1848
- Button: () => Button$1,
1849
- Cite: () => Cite,
1850
- Col: () => Col,
1851
- ColGroup: () => ColGroup,
1852
- Data: () => Data,
1853
- Dd: () => Dd,
1854
- Del: () => Del$1,
1855
- Div: () => Div$1,
1856
- Dl: () => Dl,
1857
- Figcaption: () => Figcaption,
1858
- Figure: () => Figure,
1859
- Footer: () => Footer,
1860
- H1: () => H1,
1861
- H2: () => H2,
1862
- H3: () => H3,
1863
- H4: () => H4$1,
1864
- H5: () => H5,
1865
- H6: () => H6,
1866
- Header: () => Header,
1867
- Hr: () => Hr,
1868
- I: () => I,
1869
- Img: () => Img$1,
1870
- Input: () => Input,
1871
- Ins: () => Ins$1,
1872
- Kbd: () => Kbd,
1873
- Li: () => Li,
1874
- Nav: () => Nav,
1875
- Ol: () => Ol,
1876
- Option: () => Option,
1877
- P: () => P,
1878
- Pre: () => Pre,
1879
- Root: () => Root,
1880
- Search: () => Search$1,
1881
- Section: () => Section,
1882
- Select: () => Select,
1883
- Span: () => Span$1,
1884
- TBody: () => TBody,
1885
- THead: () => THead,
1886
- Table: () => Table,
1887
- Td: () => Td,
1888
- Text: () => Text$1,
1889
- TextArea: () => TextArea$1,
1890
- Tfoot: () => Tfoot,
1891
- Th: () => Th,
1892
- Time: () => Time,
1893
- Tr: () => Tr,
1894
- Ul: () => Ul,
1895
- Video: () => Video
1896
- });
1897
- var Audio = 0;
1898
- var Button$1 = 1;
1899
- var Col = 2;
1900
- var ColGroup = 3;
1901
- var Div$1 = 4;
1902
- var H1 = 5;
1903
- var Input = 6;
1904
- var Kbd = 7;
1905
- var Span$1 = 8;
1906
- var Table = 9;
1907
- var TBody = 10;
1908
- var Td = 11;
1909
- var Text$1 = 12;
1910
- var Th = 13;
1911
- var THead = 14;
1912
- var Tr = 15;
1913
- var I = 16;
1914
- var Img$1 = 17;
1915
- var Root = 0;
1916
- var Ins$1 = 20;
1917
- var Del$1 = 21;
1918
- var H2 = 22;
1919
- var H3 = 23;
1920
- var H4$1 = 24;
1921
- var H5 = 25;
1922
- var H6 = 26;
1923
- var Article = 27;
1924
- var Aside = 28;
1925
- var Footer = 29;
1926
- var Header = 30;
1927
- var Nav = 40;
1928
- var Section = 41;
1929
- var Search$1 = 42;
1930
- var Dd = 43;
1931
- var Dl = 44;
1932
- var Figcaption = 45;
1933
- var Figure = 46;
1934
- var Hr = 47;
1935
- var Li = 48;
1936
- var Ol = 49;
1937
- var P = 50;
1938
- var Pre = 51;
1939
- var A = 53;
1940
- var Abbr = 54;
1941
- var Br = 55;
1942
- var Cite = 56;
1943
- var Data = 57;
1944
- var Time = 58;
1945
- var Tfoot = 59;
1946
- var Ul = 60;
1947
- var Video = 61;
1948
- var TextArea$1 = 62;
1949
- var Select = 63;
1950
- var Option = 64;
1951
-
1952
- // src/parts/PatchType/PatchType.ts
1953
- var SetText = 1;
1954
- var SetAttribute = 3;
1955
- var RemoveAttribute = 4;
1956
- var Add = 6;
1957
- var NavigateChild = 7;
1958
- var NavigateParent = 8;
1959
- var RemoveChild = 9;
1960
- var NavigateSibling = 10;
1961
-
1962
- // src/parts/ApplyPendingPatches/ApplyPendingPatches.ts
1963
- var applyPendingPatches = (patches, pendingPatches, skip) => {
1821
+ const Button$1 = 1;
1822
+
1823
+ const mergeClassNames = (...classNames) => {
1824
+ return classNames.filter(Boolean).join(' ');
1825
+ };
1826
+ const Text$1 = 12;
1827
+ const SetText = 1;
1828
+ const SetAttribute = 3;
1829
+ const RemoveAttribute = 4;
1830
+ const Add = 6;
1831
+ const NavigateChild = 7;
1832
+ const NavigateParent = 8;
1833
+ const RemoveChild = 9;
1834
+ const NavigateSibling = 10;
1835
+ const applyPendingPatches = (patches, pendingPatches, skip) => {
1964
1836
  for (let k = 0; k < pendingPatches.length - skip; k += 2) {
1965
1837
  const type = pendingPatches[k];
1966
1838
  const index = pendingPatches[k + 1];
@@ -1977,20 +1849,14 @@ var applyPendingPatches = (patches, pendingPatches, skip) => {
1977
1849
  }
1978
1850
  pendingPatches.length = 0;
1979
1851
  };
1980
-
1981
- // src/parts/IsKey/IsKey.ts
1982
- var isKey = key => {
1983
- return key !== "type" && key !== "childCount";
1852
+ const isKey = key => {
1853
+ return key !== 'type' && key !== 'childCount';
1984
1854
  };
1985
-
1986
- // src/parts/GetKeys/GetKeys.ts
1987
- var getKeys = node => {
1855
+ const getKeys = node => {
1988
1856
  const keys = Object.keys(node).filter(isKey);
1989
1857
  return keys;
1990
1858
  };
1991
-
1992
- // src/parts/GetTotalChildCount/GetTotalChildCount.ts
1993
- var getTotalChildCount = (nodes, index) => {
1859
+ const getTotalChildCount = (nodes, index) => {
1994
1860
  let i = index;
1995
1861
  let pending = 1;
1996
1862
  while (pending) {
@@ -2001,9 +1867,7 @@ var getTotalChildCount = (nodes, index) => {
2001
1867
  }
2002
1868
  return i - index;
2003
1869
  };
2004
-
2005
- // src/parts/VirtualDomDiff/VirtualDomDiff.ts
2006
- var diff = (oldNodes, newNodes) => {
1870
+ const diff = (oldNodes, newNodes) => {
2007
1871
  const patches = [];
2008
1872
  const pendingPatches = [];
2009
1873
  let i = 0;
@@ -2014,6 +1878,8 @@ var diff = (oldNodes, newNodes) => {
2014
1878
  while (i < oldNodes.length && j < newNodes.length) {
2015
1879
  const oldNode = oldNodes[i];
2016
1880
  const newNode = newNodes[j];
1881
+
1882
+ // TODO maybe don't have the current element in indexstack
2017
1883
  if (siblingOffset === maxSiblingOffset) {
2018
1884
  indexStack.pop();
2019
1885
  indexStack.pop();
@@ -2205,7 +2071,7 @@ const getActionButtonVirtualDom = action => {
2205
2071
 
2206
2072
  const getActionVirtualDom = action => {
2207
2073
  switch (action.type) {
2208
- case Button$2:
2074
+ case Button$1:
2209
2075
  return getActionButtonVirtualDom(action);
2210
2076
  default:
2211
2077
  return [];
@@ -2227,20 +2093,6 @@ const getCommandIds = () => {
2227
2093
  return commandIds;
2228
2094
  };
2229
2095
 
2230
- const getFlags = uid => {
2231
- const {
2232
- newState
2233
- } = get(uid);
2234
- return newState.flags;
2235
- };
2236
-
2237
- const getFocus = uid => {
2238
- const {
2239
- newState
2240
- } = get(uid);
2241
- return newState.focus;
2242
- };
2243
-
2244
2096
  const Tab = 2;
2245
2097
  const Enter = 3;
2246
2098
  const End = 255;
@@ -2310,27 +2162,27 @@ const Refresh = 'Refresh';
2310
2162
 
2311
2163
  const getActions = () => {
2312
2164
  return [{
2313
- type: Button$2,
2165
+ type: Button$1,
2314
2166
  id: refresh$1(),
2315
2167
  icon: Refresh,
2316
2168
  command: 'refresh'
2317
2169
  }, {
2318
- type: Button$2,
2170
+ type: Button$1,
2319
2171
  id: clearSearchResults(),
2320
2172
  icon: ClearAll,
2321
2173
  command: 'clearSearchResults'
2322
2174
  }, {
2323
- type: Button$2,
2175
+ type: Button$1,
2324
2176
  id: openNewSearchEditor(),
2325
2177
  icon: NewFile,
2326
2178
  command: ''
2327
2179
  }, {
2328
- type: Button$2,
2180
+ type: Button$1,
2329
2181
  id: viewAsTree(),
2330
2182
  icon: ListFlat,
2331
2183
  command: ''
2332
2184
  }, {
2333
- type: Button$2,
2185
+ type: Button$1,
2334
2186
  id: collapseAll(),
2335
2187
  icon: CollapseAll,
2336
2188
  command: ''
@@ -2481,7 +2333,7 @@ const getSearchDetailsToggleVirtualDom = () => {
2481
2333
  return [{
2482
2334
  type: Div,
2483
2335
  className: ToggleDetails,
2484
- role: Button$3,
2336
+ role: Button$2,
2485
2337
  tabIndex: 0,
2486
2338
  ariaLabel: toggleSearchDetails(),
2487
2339
  title: toggleSearchDetails(),
@@ -3009,7 +2861,7 @@ const getSearchVirtualDom = (visibleItems, flags, message, focusOutline, searchI
3009
2861
  const childCount = 2 + (errorDom.length > 0 ? 1 : 0);
3010
2862
  return [{
3011
2863
  type: Div,
3012
- className: mergeClassNames(Viewlet, Search$2),
2864
+ className: mergeClassNames(Viewlet, Search$1),
3013
2865
  childCount
3014
2866
  }, ...getSearchHeaderVirtualDom(flags, message, searchInputErrorMessage, matchCount), ...errorDom, ...getSearchResultsVirtualDom(visibleItems, focusOutline, scrollBarHeight, scrollBarY, scrollBarValue, deltaY, itemHeight)];
3015
2867
  };
@@ -3036,7 +2888,7 @@ const getFileIcons = async matches => {
3036
2888
  // TODO optimize this function to return the minimum number
3037
2889
  // of visible items needed, e.g. when not scrolled 5 items with
3038
2890
  // 20px fill 100px but when scrolled 6 items are needed
3039
- const getNumberOfVisibleItems = (listHeight, itemHeight) => {
2891
+ const getNumberOfVisibleItems$1 = (listHeight, itemHeight) => {
3040
2892
  return Math.ceil(listHeight / itemHeight) + 1;
3041
2893
  };
3042
2894
 
@@ -3080,33 +2932,11 @@ const getScrollBarSize = (size, contentSize, minimumSliderSize) => {
3080
2932
  }
3081
2933
  return Math.max(Math.round(size ** 2 / contentSize), minimumSliderSize);
3082
2934
  };
3083
- const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
2935
+ const getScrollBarOffset$1 = (delta, finalDelta, size, scrollBarSize) => {
3084
2936
  const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
3085
2937
  return scrollBarOffset;
3086
2938
  };
3087
- const getScrollBarY = getScrollBarOffset;
3088
- const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
3089
- const halfScrollBarHeight = scrollBarHeight / 2;
3090
- if (relativeY <= halfScrollBarHeight) {
3091
- // clicked at top
3092
- return {
3093
- percent: 0,
3094
- handleOffset: relativeY
3095
- };
3096
- }
3097
- if (relativeY <= height - halfScrollBarHeight) {
3098
- // clicked in middle
3099
- return {
3100
- percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
3101
- handleOffset: halfScrollBarHeight
3102
- };
3103
- }
3104
- // clicked at bottom
3105
- return {
3106
- percent: 1,
3107
- handleOffset: scrollBarHeight - height + relativeY
3108
- };
3109
- };
2939
+ const getScrollBarY$1 = getScrollBarOffset$1;
3110
2940
 
3111
2941
  const textSearch$6 = async (scheme, root, query) => {
3112
2942
  string(scheme);
@@ -3395,7 +3225,7 @@ const handleUpdate = async (state, update) => {
3395
3225
  const contentHeight = total * itemHeight;
3396
3226
  const listHeight = height - headerHeight;
3397
3227
  const scrollBarHeight = getScrollBarSize(height, contentHeight, minimumSliderSize);
3398
- const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
3228
+ const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
3399
3229
  const maxLineY = Math.min(numberOfVisible, total);
3400
3230
  const finalDeltaY = Math.max(contentHeight - listHeight, 0);
3401
3231
  const visible = results.slice(0, maxLineY);
@@ -3444,6 +3274,10 @@ const noop = state => {
3444
3274
  return state;
3445
3275
  };
3446
3276
 
3277
+ const applyBulkReplacement = async bulkEdits => {
3278
+ await invoke$2('BulkReplacement.applyBulkReplacement', bulkEdits);
3279
+ };
3280
+
3447
3281
  const getReplacedMessage = (fileCount, replaceCount, replacement) => {
3448
3282
  if (replaceCount === 1) {
3449
3283
  return replacedOneOccurrenceInOneFile(replacement);
@@ -3508,7 +3342,7 @@ const replaceAll = async state => {
3508
3342
  matchCount
3509
3343
  } = state;
3510
3344
  const bulkEdits = getReplaceElements(items, workspacePath, replacement);
3511
- await invoke$2('BulkReplacement.applyBulkReplacement', bulkEdits);
3345
+ await applyBulkReplacement(bulkEdits);
3512
3346
  const fileCount = bulkEdits.length;
3513
3347
  const message = getReplacedMessage(fileCount, matchCount, replacement);
3514
3348
  return {
@@ -3658,6 +3492,12 @@ const handleSharedInput = (state, name, value, inputSource = Script) => {
3658
3492
  return fn(state, value, inputSource);
3659
3493
  };
3660
3494
 
3495
+ // TODO optimize this function to return the minimum number
3496
+ // of visible items needed, e.g. when not scrolled 5 items with
3497
+ // 20px fill 100px but when scrolled 6 items are needed
3498
+ const getNumberOfVisibleItems = (listHeight, itemHeight) => {
3499
+ return Math.ceil(listHeight / itemHeight) + 1;
3500
+ };
3661
3501
  const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength) => {
3662
3502
  const newMaxLineY = Math.min(index + 1, itemsLength);
3663
3503
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
@@ -3672,7 +3512,6 @@ const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength)
3672
3512
  deltaY: newDeltaY
3673
3513
  };
3674
3514
  };
3675
-
3676
3515
  const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) => {
3677
3516
  const newMinLineY = index;
3678
3517
  const fittingItems = getNumberOfVisibleItems(listHeight, itemHeight);
@@ -3687,7 +3526,6 @@ const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) =
3687
3526
  deltaY: newDeltaY
3688
3527
  };
3689
3528
  };
3690
-
3691
3529
  const focusIndex = (state, index) => {
3692
3530
  const {
3693
3531
  itemHeight,
@@ -3722,7 +3560,6 @@ const focusIndex = (state, index) => {
3722
3560
  focused: true
3723
3561
  };
3724
3562
  };
3725
-
3726
3563
  const first = () => {
3727
3564
  return 0;
3728
3565
  };
@@ -3735,12 +3572,10 @@ const next = (items, index) => {
3735
3572
  const previous = (items, index) => {
3736
3573
  return index === 0 ? items.length - 1 : index - 1;
3737
3574
  };
3738
-
3739
3575
  const focusFirst = state => {
3740
3576
  const firstIndex = first();
3741
3577
  return focusIndex(state, firstIndex);
3742
3578
  };
3743
-
3744
3579
  const focusLast = state => {
3745
3580
  const {
3746
3581
  items
@@ -3748,7 +3583,6 @@ const focusLast = state => {
3748
3583
  const lastIndex = last(items);
3749
3584
  return focusIndex(state, lastIndex);
3750
3585
  };
3751
-
3752
3586
  const focusNext = state => {
3753
3587
  const {
3754
3588
  focusedIndex,
@@ -3758,6 +3592,14 @@ const focusNext = state => {
3758
3592
  return focusIndex(state, nextIndex);
3759
3593
  };
3760
3594
 
3595
+ // based on https://github.com/microsoft/vscode/blob/c0769274fa136b45799edeccc0d0a2f645b75caf/src/vs/base/common/arrays.ts#L625 (License MIT)
3596
+
3597
+ const isLastIndex = (array, index) => {
3598
+ return index === array.length - 1;
3599
+ };
3600
+ const lastIndex = array => {
3601
+ return array.length - 1;
3602
+ };
3761
3603
  const focusNextPage = state => {
3762
3604
  const {
3763
3605
  focusedIndex,
@@ -3771,7 +3613,6 @@ const focusNextPage = state => {
3771
3613
  const indexNextPage = Math.min(maxLineY + (maxLineY - minLineY) - 2, lastIndex(items));
3772
3614
  return focusIndex(state, indexNextPage);
3773
3615
  };
3774
-
3775
3616
  const focusPrevious = state => {
3776
3617
  const {
3777
3618
  focusedIndex,
@@ -3783,7 +3624,6 @@ const focusPrevious = state => {
3783
3624
  const previousIndex = previous(items, focusedIndex);
3784
3625
  return focusIndex(state, previousIndex);
3785
3626
  };
3786
-
3787
3627
  const focusPreviousPage = state => {
3788
3628
  const {
3789
3629
  focusedIndex,
@@ -3796,6 +3636,129 @@ const focusPreviousPage = state => {
3796
3636
  const indexPreviousPage = Math.max(minLineY - (maxLineY - minLineY) + 1, 0);
3797
3637
  return focusIndex(state, indexPreviousPage);
3798
3638
  };
3639
+ const handleScrollBarCaptureLost = state => {
3640
+ return {
3641
+ ...state,
3642
+ scrollBarActive: false
3643
+ };
3644
+ };
3645
+ const getScrollBarOffset = (delta, finalDelta, size, scrollBarSize) => {
3646
+ const scrollBarOffset = delta / finalDelta * (size - scrollBarSize);
3647
+ return scrollBarOffset;
3648
+ };
3649
+ const getScrollBarY = getScrollBarOffset;
3650
+ const getNewDeltaPercent = (height, scrollBarHeight, relativeY) => {
3651
+ const halfScrollBarHeight = scrollBarHeight / 2;
3652
+ if (relativeY <= halfScrollBarHeight) {
3653
+ // clicked at top
3654
+ return {
3655
+ percent: 0,
3656
+ handleOffset: relativeY
3657
+ };
3658
+ }
3659
+ if (relativeY <= height - halfScrollBarHeight) {
3660
+ // clicked in middle
3661
+ return {
3662
+ percent: (relativeY - halfScrollBarHeight) / (height - scrollBarHeight),
3663
+ handleOffset: halfScrollBarHeight
3664
+ };
3665
+ }
3666
+ // clicked at bottom
3667
+ return {
3668
+ percent: 1,
3669
+ handleOffset: scrollBarHeight - height + relativeY
3670
+ };
3671
+ };
3672
+ const clamp = (num, min, max) => {
3673
+ return Math.min(Math.max(num, min), max);
3674
+ };
3675
+ const setDeltaY = (state, value) => {
3676
+ object(state);
3677
+ number(value);
3678
+ const {
3679
+ itemHeight,
3680
+ finalDeltaY,
3681
+ deltaY,
3682
+ height,
3683
+ headerHeight,
3684
+ items
3685
+ } = state;
3686
+ const listHeight = height - headerHeight;
3687
+ const newDeltaY = clamp(value, 0, finalDeltaY);
3688
+ if (deltaY === newDeltaY) {
3689
+ return state;
3690
+ }
3691
+ // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
3692
+ const minLineY = Math.floor(newDeltaY / itemHeight);
3693
+ const maxLineY = Math.min(minLineY + getNumberOfVisibleItems(listHeight, itemHeight), items.length);
3694
+
3695
+ // TODO update icons
3696
+ return {
3697
+ ...state,
3698
+ deltaY: newDeltaY,
3699
+ minLineY,
3700
+ maxLineY
3701
+ };
3702
+ };
3703
+ const handleScrollBarClick = (state, eventY) => {
3704
+ const {
3705
+ y,
3706
+ deltaY,
3707
+ headerHeight,
3708
+ finalDeltaY,
3709
+ scrollBarHeight,
3710
+ height
3711
+ } = state;
3712
+ const contentHeight = height - headerHeight;
3713
+ const relativeY = eventY - y - headerHeight;
3714
+ const currentScrollBarY = getScrollBarY(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
3715
+ const diff = relativeY - currentScrollBarY;
3716
+ if (diff >= 0 && diff < scrollBarHeight) {
3717
+ return {
3718
+ ...state,
3719
+ handleOffset: diff,
3720
+ scrollBarActive: true
3721
+ };
3722
+ }
3723
+ const {
3724
+ percent,
3725
+ handleOffset
3726
+ } = getNewDeltaPercent(contentHeight, scrollBarHeight, relativeY);
3727
+ const newDeltaY = percent * finalDeltaY;
3728
+ return {
3729
+ ...setDeltaY(state, newDeltaY),
3730
+ handleOffset,
3731
+ scrollBarActive: true
3732
+ };
3733
+ };
3734
+ const getNewPercent = (contentHeight, scrollBarHeight, relativeY) => {
3735
+ if (relativeY <= contentHeight - scrollBarHeight / 2) {
3736
+ // clicked in middle
3737
+ return relativeY / (contentHeight - scrollBarHeight);
3738
+ }
3739
+ // clicked at bottom
3740
+ return 1;
3741
+ };
3742
+ const handleScrollBarMove = (state, eventY) => {
3743
+ const {
3744
+ y,
3745
+ headerHeight,
3746
+ handleOffset,
3747
+ finalDeltaY,
3748
+ height,
3749
+ scrollBarHeight
3750
+ } = state;
3751
+ const relativeY = eventY - y - headerHeight - handleOffset;
3752
+ const contentHeight = height - headerHeight;
3753
+ const newPercent = getNewPercent(contentHeight, scrollBarHeight, relativeY);
3754
+ const newDeltaY = newPercent * finalDeltaY;
3755
+ return setDeltaY(state, newDeltaY);
3756
+ };
3757
+ const handleWheel = (state, deltaMode, deltaY) => {
3758
+ number(deltaMode);
3759
+ number(deltaY);
3760
+ return setDeltaY(state, state.deltaY + deltaY);
3761
+ };
3799
3762
 
3800
3763
  const getListIndex = (eventX, eventY, x, y, deltaY, itemHeight, topHeight, itemCount) => {
3801
3764
  const relativeY = eventY - y - topHeight + deltaY;
@@ -3859,7 +3822,7 @@ const selectIndexFile = async (state, searchResult, index) => {
3859
3822
  const icons = await getFileIcons(filteredResults);
3860
3823
  const total = filteredResults.length;
3861
3824
  const listHeight = height - headerHeight;
3862
- const numberOfVisible = getNumberOfVisibleItems(listHeight, itemHeight);
3825
+ const numberOfVisible = getNumberOfVisibleItems$1(listHeight, itemHeight);
3863
3826
  const maxLineY = Math.min(numberOfVisible, total);
3864
3827
  return {
3865
3828
  ...state,
@@ -3952,108 +3915,6 @@ const handleClickAt = (state, eventX, eventY) => {
3952
3915
  return selectIndex(state, index);
3953
3916
  };
3954
3917
 
3955
- const handleScrollBarCaptureLost = state => {
3956
- return {
3957
- ...state,
3958
- scrollBarActive: false
3959
- };
3960
- };
3961
-
3962
- const clamp = (num, min, max) => {
3963
- return Math.min(Math.max(num, min), max);
3964
- };
3965
-
3966
- const setDeltaY = (state, value) => {
3967
- object(state);
3968
- number(value);
3969
- const {
3970
- itemHeight,
3971
- finalDeltaY,
3972
- deltaY,
3973
- height,
3974
- headerHeight,
3975
- listItems
3976
- } = state;
3977
- const listHeight = height - headerHeight;
3978
- const newDeltaY = clamp(value, 0, finalDeltaY);
3979
- if (deltaY === newDeltaY) {
3980
- return state;
3981
- }
3982
- // TODO when it only moves by one px, extensions don't need to be rerendered, only negative margin
3983
- const minLineY = Math.floor(newDeltaY / itemHeight);
3984
- const maxLineY = Math.min(minLineY + getNumberOfVisibleItems(listHeight, itemHeight), listItems.length);
3985
-
3986
- // TODO update icons
3987
- return {
3988
- ...state,
3989
- deltaY: newDeltaY,
3990
- minLineY,
3991
- maxLineY
3992
- };
3993
- };
3994
-
3995
- const handleScrollBarClick = (state, eventY) => {
3996
- const {
3997
- y,
3998
- deltaY,
3999
- headerHeight,
4000
- finalDeltaY,
4001
- scrollBarHeight,
4002
- height
4003
- } = state;
4004
- const contentHeight = height - headerHeight;
4005
- const relativeY = eventY - y - headerHeight;
4006
- const currentScrollBarY = getScrollBarY(deltaY, finalDeltaY, contentHeight, scrollBarHeight);
4007
- const diff = relativeY - currentScrollBarY;
4008
- if (diff >= 0 && diff < scrollBarHeight) {
4009
- return {
4010
- ...state,
4011
- handleOffset: diff,
4012
- scrollBarActive: true
4013
- };
4014
- }
4015
- const {
4016
- percent,
4017
- handleOffset
4018
- } = getNewDeltaPercent(contentHeight, scrollBarHeight, relativeY);
4019
- const newDeltaY = percent * finalDeltaY;
4020
- return {
4021
- ...setDeltaY(state, newDeltaY),
4022
- handleOffset,
4023
- scrollBarActive: true
4024
- };
4025
- };
4026
-
4027
- const getNewPercent = (contentHeight, scrollBarHeight, relativeY) => {
4028
- if (relativeY <= contentHeight - scrollBarHeight / 2) {
4029
- // clicked in middle
4030
- return relativeY / (contentHeight - scrollBarHeight);
4031
- }
4032
- // clicked at bottom
4033
- return 1;
4034
- };
4035
- const handleScrollBarMove = (state, eventY) => {
4036
- const {
4037
- y,
4038
- headerHeight,
4039
- handleOffset,
4040
- finalDeltaY,
4041
- height,
4042
- scrollBarHeight
4043
- } = state;
4044
- const relativeY = eventY - y - headerHeight - handleOffset;
4045
- const contentHeight = height - headerHeight;
4046
- const newPercent = getNewPercent(contentHeight, scrollBarHeight, relativeY);
4047
- const newDeltaY = newPercent * finalDeltaY;
4048
- return setDeltaY(state, newDeltaY);
4049
- };
4050
-
4051
- const handleWheel = (state, deltaMode, deltaY) => {
4052
- number(deltaMode);
4053
- number(deltaY);
4054
- return setDeltaY(state, state.deltaY + deltaY);
4055
- };
4056
-
4057
3918
  const getSavedValue = savedState => {
4058
3919
  if (savedState && typeof savedState === 'object' && 'value' in savedState && typeof savedState.value === 'string') {
4059
3920
  return savedState.value;
@@ -4084,6 +3945,7 @@ const getSavedExcludeValue = savedState => {
4084
3945
  }
4085
3946
  return '';
4086
3947
  };
3948
+
4087
3949
  const restoreState = savedState => {
4088
3950
  return {
4089
3951
  savedValue: getSavedValue(savedState),
@@ -4195,7 +4057,7 @@ const createViewModel = state => {
4195
4057
  const displayResults = getDisplayResults(listItems, itemHeight, fileCount, value, minLineY, maxLineY, replacement, icons, listFocusedIndex, collapsedPaths, items);
4196
4058
  const focusOutline = listFocused && listFocusedIndex === -1;
4197
4059
  const scrollBarValue = deltaY / finalDeltaY * 100;
4198
- const scrollBarY = getScrollBarY(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
4060
+ const scrollBarY = getScrollBarY$1(deltaY, finalDeltaY, height - headerHeight, scrollBarHeight);
4199
4061
  return {
4200
4062
  displayResults,
4201
4063
  flags,
@@ -4268,16 +4130,6 @@ const render2 = (uid, diffResult) => {
4268
4130
  return commands;
4269
4131
  };
4270
4132
 
4271
- const doRender = uid => {
4272
- const {
4273
- oldState,
4274
- newState
4275
- } = get(uid);
4276
- const diffResult = diff$1(oldState, newState);
4277
- const commands = applyRender(oldState, newState, diffResult);
4278
- return commands;
4279
- };
4280
-
4281
4133
  const renderActions = uid => {
4282
4134
  const {
4283
4135
  oldState,
@@ -4340,7 +4192,7 @@ const getDom = state => {
4340
4192
  const displayResults = getDisplayResults(state.listItems, state.itemHeight, state.fileCount, state.value, state.minLineY, state.maxLineY, state.replacement, state.icons, state.listFocusedIndex, state.collapsedPaths, state.items);
4341
4193
  const focusOutline = state.listFocused && state.listFocusedIndex === -1;
4342
4194
  const scrollBarValue = state.deltaY / state.finalDeltaY * 100;
4343
- const scrollBarY = getScrollBarY(state.deltaY, state.finalDeltaY, state.height - state.headerHeight, state.scrollBarHeight);
4195
+ const scrollBarY = getScrollBarY$1(state.deltaY, state.finalDeltaY, state.height - state.headerHeight, state.scrollBarHeight);
4344
4196
  const dom = getSearchVirtualDom(displayResults, state.flags, state.message, focusOutline, state.searchInputErrorMessage, state.scrollBarHeight, scrollBarY, scrollBarValue, state.deltaY, state.itemHeight, state.matchCount);
4345
4197
  return dom;
4346
4198
  };
@@ -4555,22 +4407,32 @@ const handleContextMenuMouseAt = async (state, x, y) => {
4555
4407
  return state;
4556
4408
  };
4557
4409
 
4558
- const handleContextMenu = (state, button, x, y) => {
4410
+ const getContextMenuHandler = button => {
4559
4411
  switch (button) {
4560
4412
  case Keyboard:
4561
- return handleContextMenuKeyboard(state);
4413
+ return handleContextMenuKeyboard;
4562
4414
  default:
4563
- return handleContextMenuMouseAt(state, x, y);
4415
+ return handleContextMenuMouseAt;
4564
4416
  }
4565
4417
  };
4566
4418
 
4419
+ const handleContextMenu = async (state, button, x, y) => {
4420
+ const fn = getContextMenuHandler(button);
4421
+ const newState = await fn(state, x, y);
4422
+ return newState;
4423
+ };
4424
+
4567
4425
  const wrapCommand = fn => {
4568
4426
  const wrapped = async (uid, ...args) => {
4569
4427
  const {
4570
4428
  newState
4571
4429
  } = get(uid);
4572
4430
  const newerState = await fn(newState, ...args);
4573
- set(uid, newState, newerState);
4431
+ if (newState === newerState) {
4432
+ return;
4433
+ }
4434
+ const latest = get(uid);
4435
+ set(uid, latest.oldState, newerState);
4574
4436
  };
4575
4437
  return wrapped;
4576
4438
  };
@@ -4604,11 +4466,7 @@ const commandMap = {
4604
4466
  'TextSearch.focusReplaceValuePrevious': wrapCommand(focusReplaceValuePrevious),
4605
4467
  'TextSearch.focusSearchValue': wrapCommand(focusSearchValue$1),
4606
4468
  'TextSearch.focusSearchValueNext': wrapCommand(focusSearchValueNext),
4607
- 'TextSearch.getActions': wrapCommand(getActions),
4608
- 'TextSearch.getActionsVirtualDom': wrapCommand(getActionsVirtualDom),
4609
4469
  'TextSearch.getCommandIds': getCommandIds,
4610
- 'TextSearch.getSearchDisplayResults': wrapCommand(getDisplayResults),
4611
- 'TextSearch.getVirtualDom': wrapCommand(getSearchVirtualDom),
4612
4470
  'TextSearch.handleClickAt': wrapCommand(handleClickAt),
4613
4471
  'TextSearch.handleContextMenu': wrapCommand(handleContextMenu),
4614
4472
  'TextSearch.handleExcludeInput': wrapCommand(handleExcludeInput),
@@ -4628,9 +4486,8 @@ const commandMap = {
4628
4486
  'TextSearch.launchSearchProcess': wrapCommand(launchSearchProcess),
4629
4487
  'TextSearch.loadContent': wrapCommand(loadContent),
4630
4488
  'TextSearch.refresh': wrapCommand(refresh),
4631
- 'TextSearch.renderActions': wrapCommand(renderActions),
4489
+ 'TextSearch.renderActions': renderActions,
4632
4490
  'TextSearch.replaceAll': wrapCommand(replaceAll),
4633
- 'TextSearch.replaceAllAndPrompt': wrapCommand(replaceAllAndPrompt),
4634
4491
  'TextSearch.selectIndex': wrapCommand(selectIndex),
4635
4492
  'TextSearch.submit': wrapCommand(submit),
4636
4493
  'TextSearch.toggleMatchCase': wrapCommand(toggleMatchCase),
@@ -4650,12 +4507,13 @@ const commandMap = {
4650
4507
  'TextSearch.restoreState': restoreState,
4651
4508
  'TextSearch.saveState': saveState,
4652
4509
  'TextSearch.terminate': terminate,
4653
- // deprecated
4654
- 'TextSearch.getFlags': getFlags,
4655
- 'TextSearch.getFocus': getFocus,
4656
- 'TextSearch.render': doRender,
4657
4510
  // TODO needed?
4658
- 'TextSearch.textSearch': textSearch
4511
+ 'TextSearch.replaceAllAndPrompt': replaceAllAndPrompt,
4512
+ 'TextSearch.textSearch': textSearch,
4513
+ 'TextSearch.getActions': getActions,
4514
+ 'TextSearch.getActionsVirtualDom': getActionsVirtualDom,
4515
+ 'TextSearch.getSearchDisplayResults': getDisplayResults,
4516
+ 'TextSearch.getVirtualDom': getSearchVirtualDom
4659
4517
  };
4660
4518
 
4661
4519
  const listen = async () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "3.52.0",
3
+ "version": "4.1.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"