@lvce-editor/text-search-worker 4.6.0 → 4.8.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.
@@ -1085,7 +1085,8 @@ const clearSearchResults$1 = state => {
1085
1085
  maxLineY: 0,
1086
1086
  message: '',
1087
1087
  focus: FocusSearchInput,
1088
- focusSource: Script
1088
+ focusSource: Script,
1089
+ inputSource: Script
1089
1090
  };
1090
1091
  };
1091
1092
 
@@ -1172,13 +1173,51 @@ const create$2 = () => {
1172
1173
  return Object.keys(states).map(key => {
1173
1174
  return Number.parseInt(key);
1174
1175
  });
1176
+ },
1177
+ clear() {
1178
+ for (const key of Object.keys(states)) {
1179
+ delete states[key];
1180
+ }
1181
+ },
1182
+ wrapCommand(fn) {
1183
+ const wrapped = async (uid, ...args) => {
1184
+ const {
1185
+ newState
1186
+ } = states[uid];
1187
+ const newerState = await fn(newState, ...args);
1188
+ if (newState === newerState) {
1189
+ return;
1190
+ }
1191
+ const latest = states[uid];
1192
+ states[uid] = {
1193
+ oldState: latest.oldState,
1194
+ newState: newerState
1195
+ };
1196
+ };
1197
+ return wrapped;
1198
+ },
1199
+ diff(uid, modules, numbers) {
1200
+ const {
1201
+ oldState,
1202
+ newState
1203
+ } = states[uid];
1204
+ const diffResult = [];
1205
+ for (let i = 0; i < modules.length; i++) {
1206
+ const fn = modules[i];
1207
+ if (!fn(oldState, newState)) {
1208
+ diffResult.push(numbers[i]);
1209
+ }
1210
+ }
1211
+ return diffResult;
1175
1212
  }
1176
1213
  };
1177
1214
  };
1178
1215
 
1179
1216
  const {
1180
1217
  get,
1181
- set} = create$2();
1218
+ set,
1219
+ wrapCommand
1220
+ } = create$2();
1182
1221
 
1183
1222
  const create$1 = ({
1184
1223
  itemHeight,
@@ -1262,15 +1301,19 @@ const RenderExcludeValue = 6;
1262
1301
  const RenderFocusContext = 7;
1263
1302
 
1264
1303
  const diffType$5 = RenderExcludeValue;
1265
- const isEqual$5 = (oldState, newState) => {
1304
+ const isEqual$6 = (oldState, newState) => {
1266
1305
  return oldState.excludeValue === newState.excludeValue || newState.inputSource === User;
1267
1306
  };
1268
1307
 
1269
1308
  const diffType$4 = RenderFocus;
1270
- const isEqual$4 = (oldState, newState) => {
1309
+ const isEqual$5 = (oldState, newState) => {
1271
1310
  return oldState.focus === newState.focus || newState.focusSource === User;
1272
1311
  };
1273
1312
 
1313
+ const isEqual$4 = (oldState, newState) => {
1314
+ return oldState.focus === newState.focus;
1315
+ };
1316
+
1274
1317
  const diffType$3 = RenderIncludeValue;
1275
1318
  const isEqual$3 = (oldState, newState) => {
1276
1319
  return oldState.includeValue === newState.includeValue || newState.inputSource === User;
@@ -1291,8 +1334,8 @@ const isEqual = (oldState, newState) => {
1291
1334
  return oldState.value === newState.value || newState.inputSource === User;
1292
1335
  };
1293
1336
 
1294
- const modules = [isEqual$2, isEqual$4, isEqual$3, isEqual$5, isEqual$1, isEqual];
1295
- const numbers = [diffType$2, diffType$4, diffType$3, diffType$5, diffType$1, diffType];
1337
+ const modules = [isEqual$2, isEqual$5, isEqual$3, isEqual$6, isEqual$1, isEqual, isEqual$4];
1338
+ const numbers = [diffType$2, diffType$4, diffType$3, diffType$5, diffType$1, diffType, RenderFocusContext];
1296
1339
 
1297
1340
  const diff$1 = (oldState, newState) => {
1298
1341
  const diffResult = [];
@@ -1763,12 +1806,7 @@ const focusReplaceValue$1 = state => {
1763
1806
  };
1764
1807
  };
1765
1808
 
1766
- const setFocus = async focusKey => {
1767
- await invoke$2('Focus.setFocus', focusKey);
1768
- };
1769
-
1770
1809
  const focusSearchValue$1 = async state => {
1771
- await setFocus(FocusSearchInput);
1772
1810
  return {
1773
1811
  ...state,
1774
1812
  focus: FocusSearchInput
@@ -1782,7 +1820,7 @@ const focusSearchValueNext = state => {
1782
1820
  return focusMatchCase$1(state);
1783
1821
  };
1784
1822
 
1785
- const commandIds = ['clearSearchResults', 'collapseAll', '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', 'handleHeaderFocusOut', 'handleIconThemeChange', 'handleIconThemeChange', 'handleIncludeInput', 'handleInput', 'handleInput2', 'handleListBlur', 'handleListFocus', 'handleReplaceInput', 'handleScrollBarCaptureLost', 'handleScrollBarClick', 'handleScrollBarMove', 'handleScrollBarThumbPointerMove', 'handleTouchEnd', 'handleTouchMove', 'handleTouchStart', 'handleUpdate', 'handleWheel', 'nextHistoryResult', 'previousHistoryResult', 'refresh', 'replaceAll', 'scrollDown', 'selectIndex', 'submit', 'toggleMatchCase', 'toggleMatchWholeWord', 'togglePreserveCase', 'toggleReplace', 'toggleSearchDetails', 'toggleUseRegularExpression', 'viewAsTree'];
1823
+ const commandIds = ['clearSearchResults', 'collapseAll', 'collapseDetails', 'copy', 'dismissItem', 'dispose', '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', 'handleHeaderContextMenu', 'handleHeaderFocusIn', 'handleHeaderFocusOut', 'handleIconThemeChange', 'handleIconThemeChange', 'handleIncludeInput', 'handleInput', 'handleInput2', 'handleListBlur', 'handleListFocus', 'handleReplaceInput', 'handleScrollBarCaptureLost', 'handleScrollBarClick', 'handleScrollBarMove', 'handleScrollBarThumbPointerMove', 'handleTouchEnd', 'handleTouchMove', 'handleTouchStart', 'handleUpdate', 'handleWheel', 'nextHistoryResult', 'previousHistoryResult', 'refresh', 'replaceAll', 'scrollDown', 'selectIndex', 'submit', 'toggleMatchCase', 'toggleMatchWholeWord', 'togglePreserveCase', 'toggleReplace', 'toggleSearchDetails', 'toggleUseRegularExpression', 'viewAsTree'];
1786
1824
 
1787
1825
  const getCommandIds = () => {
1788
1826
  return commandIds;
@@ -1801,7 +1839,7 @@ const CtrlCmd = 1 << 11 >>> 0;
1801
1839
  const Shift = 1 << 10 >>> 0;
1802
1840
  const Alt = 1 << 9 >>> 0;
1803
1841
 
1804
- const getKeyBindings = () => {
1842
+ const getSearchHeaderKeyBindings = () => {
1805
1843
  return [{
1806
1844
  key: CtrlCmd | Alt | Enter,
1807
1845
  command: 'Search.replaceAll',
@@ -1823,6 +1861,18 @@ const getKeyBindings = () => {
1823
1861
  command: 'Search.nextHistoryResult',
1824
1862
  when: FocusSearchInput
1825
1863
  }, {
1864
+ key: Enter,
1865
+ command: 'Search.submit',
1866
+ when: FocusSearchInput
1867
+ }, {
1868
+ key: Enter,
1869
+ command: 'Search.submit',
1870
+ when: FocusSearchReplaceInput
1871
+ }];
1872
+ };
1873
+
1874
+ const getSearchResultKeyBindings = () => {
1875
+ return [{
1826
1876
  key: DownArrow,
1827
1877
  command: 'Search.focusNext',
1828
1878
  when: FocusSearchResults
@@ -1846,17 +1896,13 @@ const getKeyBindings = () => {
1846
1896
  key: CtrlCmd | KeyC,
1847
1897
  command: 'Search.copy',
1848
1898
  when: FocusSearchResults
1849
- }, {
1850
- key: Enter,
1851
- command: 'Search.submit',
1852
- when: FocusSearchInput
1853
- }, {
1854
- key: Enter,
1855
- command: 'Search.submit',
1856
- when: FocusSearchReplaceInput
1857
1899
  }];
1858
1900
  };
1859
1901
 
1902
+ const getKeyBindings = () => {
1903
+ return [...getSearchHeaderKeyBindings(), ...getSearchResultKeyBindings()];
1904
+ };
1905
+
1860
1906
  const handleError = error => {
1861
1907
  console.error(`[text-search-worker] ${error}`);
1862
1908
  };
@@ -2435,6 +2481,10 @@ const handleHeaderClick = async (state, name) => {
2435
2481
  return fn(state);
2436
2482
  };
2437
2483
 
2484
+ const handleHeaderContextMenu = async state => {
2485
+ return state;
2486
+ };
2487
+
2438
2488
  const handleHeaderFocusIn = state => {
2439
2489
  return state;
2440
2490
  };
@@ -2853,7 +2903,9 @@ const selectIndexFile = async (state, searchResult, index) => {
2853
2903
  listFocused: true,
2854
2904
  listItems: filteredResults,
2855
2905
  maxLineY,
2856
- icons
2906
+ icons,
2907
+ focus: FocusSearchResults,
2908
+ focusSource: Script
2857
2909
  };
2858
2910
  };
2859
2911
 
@@ -2897,9 +2949,6 @@ const selectIndexPreview = async (state, searchResult, index) => {
2897
2949
  const fileResult = items[fileIndex];
2898
2950
  const relativePath = getRelativePath(fileResult.text);
2899
2951
  const absolutePath = `${workspacePath}${relativePath}`;
2900
- if (state.focus !== FocusSearchResults) {
2901
- await setFocus(FocusSearchResults);
2902
- }
2903
2952
  await openUri(absolutePath, true, {
2904
2953
  selections: new Uint32Array([lineNumber, 0, lineNumber, 0])
2905
2954
  });
@@ -2907,7 +2956,8 @@ const selectIndexPreview = async (state, searchResult, index) => {
2907
2956
  ...state,
2908
2957
  listFocusedIndex: index,
2909
2958
  listFocused: false,
2910
- focus: FocusSearchResults
2959
+ focus: FocusSearchResults,
2960
+ focusSource: Script
2911
2961
  };
2912
2962
  };
2913
2963
 
@@ -2938,7 +2988,7 @@ const selectIndex = async (state, index) => {
2938
2988
  return fn(state, searchResult, index);
2939
2989
  };
2940
2990
 
2941
- const handleClickAt = (state, eventX, eventY) => {
2991
+ const handleClickAt = async (state, eventX, eventY) => {
2942
2992
  const {
2943
2993
  x,
2944
2994
  y,
@@ -3338,6 +3388,7 @@ const TreeItem = 'treeitem';
3338
3388
 
3339
3389
  const HandleClick = 'handleClick';
3340
3390
  const HandleContextMenu = 'handleContextMenu';
3391
+ const HandleHeaderContextMenu = 'handleHeaderContextMenu';
3341
3392
  const HandleExcludeInput = 'handleExcludeInput';
3342
3393
  const HandleHeaderClick2 = 'handleHeaderClick2';
3343
3394
  const HandleHeaderFocusIn = 'handleHeaderFocusIn';
@@ -3905,7 +3956,8 @@ const parentNode = {
3905
3956
  childCount: 2,
3906
3957
  onClick: HandleHeaderClick2,
3907
3958
  onFocusIn: HandleHeaderFocusIn,
3908
- onFocusOut: HandleHeaderFocusOut
3959
+ onFocusOut: HandleHeaderFocusOut,
3960
+ onContextMenu: HandleHeaderContextMenu
3909
3961
  };
3910
3962
  const getSearchHeaderVirtualDom = (flags, message, searchInputErrorMessage, matchCount, focus) => {
3911
3963
  const dom = [parentNode, ...getSearchHeaderTopVirtualDom(flags, searchInputErrorMessage, matchCount, focus), ...getSearchHeaderDetailsVirtualDom(flags, message)];
@@ -4311,6 +4363,10 @@ const renderEventListeners = () => {
4311
4363
  name: HandleContextMenu,
4312
4364
  params: ['handleContextMenu', 'event.button', 'event.clientX', 'event.clientY'],
4313
4365
  preventDefault: true
4366
+ }, {
4367
+ name: HandleHeaderContextMenu,
4368
+ params: ['handleHeaderContextMenu'],
4369
+ preventDefault: true
4314
4370
  }, {
4315
4371
  name: HandleWheel,
4316
4372
  params: ['handleWheel', 'event.deltaMode', 'event.deltaY'],
@@ -4463,7 +4519,6 @@ const handleFocusIn = async (state, key) => {
4463
4519
  if (state.focus === focusKey) {
4464
4520
  return state;
4465
4521
  }
4466
- await setFocus(FocusSearch);
4467
4522
  return {
4468
4523
  ...state,
4469
4524
  focus: focusKey,
@@ -4578,25 +4633,10 @@ const handleContextMenu = async (state, button, x, y) => {
4578
4633
  return newState;
4579
4634
  };
4580
4635
 
4581
- const wrapCommand = fn => {
4582
- const wrapped = async (uid, ...args) => {
4583
- const {
4584
- newState
4585
- } = get(uid);
4586
- const newerState = await fn(newState, ...args);
4587
- if (newState === newerState) {
4588
- return;
4589
- }
4590
- const latest = get(uid);
4591
- set(uid, latest.oldState, newerState);
4592
- };
4593
- return wrapped;
4594
- };
4595
-
4596
4636
  const commandMap = {
4597
4637
  'TextSearch.clearSearchResults': wrapCommand(clearSearchResults$1),
4598
- 'TextSearch.collapseDetails': wrapCommand(collapseDetails),
4599
4638
  'TextSearch.collapseAll': wrapCommand(collapseAll$1),
4639
+ 'TextSearch.collapseDetails': wrapCommand(collapseDetails),
4600
4640
  'TextSearch.copy': wrapCommand(copy),
4601
4641
  'TextSearch.diff2': diff2,
4602
4642
  'TextSearch.dismissItem': wrapCommand(dismissItem),
@@ -4624,11 +4664,11 @@ const commandMap = {
4624
4664
  'TextSearch.focusSearchValue': wrapCommand(focusSearchValue$1),
4625
4665
  'TextSearch.focusSearchValueNext': wrapCommand(focusSearchValueNext),
4626
4666
  'TextSearch.handleClickAt': wrapCommand(handleClickAt),
4627
- 'TextSearch.viewAsTree': wrapCommand(viewAsTree),
4628
4667
  'TextSearch.handleContextMenu': wrapCommand(handleContextMenu),
4629
4668
  'TextSearch.handleExcludeInput': wrapCommand(handleExcludeInput),
4630
4669
  'TextSearch.handleFocusIn': wrapCommand(handleFocusIn),
4631
4670
  'TextSearch.handleHeaderClick': wrapCommand(handleHeaderClick),
4671
+ 'TextSearch.handleHeaderContextMenu': wrapCommand(handleHeaderContextMenu),
4632
4672
  'TextSearch.handleHeaderFocusIn': wrapCommand(handleHeaderFocusIn),
4633
4673
  'TextSearch.handleHeaderFocusOut': wrapCommand(handleHeaderFocusOut),
4634
4674
  'TextSearch.handleIconThemeChange': wrapCommand(handleIconThemeChange),
@@ -4658,6 +4698,7 @@ const commandMap = {
4658
4698
  'TextSearch.toggleSearchDetails': wrapCommand(toggleDetailsExpanded),
4659
4699
  'TextSearch.toggleUseIgnoreFiles': wrapCommand(toggleUseIgnoreFiles),
4660
4700
  'TextSearch.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression),
4701
+ 'TextSearch.viewAsTree': wrapCommand(viewAsTree),
4661
4702
  // not wrapped
4662
4703
  'TextSearch.create': create,
4663
4704
  'TextSearch.getCommandIds': getCommandIds,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "4.6.0",
3
+ "version": "4.8.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"