@lvce-editor/text-search-worker 5.24.0 → 5.26.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.
@@ -1223,9 +1223,12 @@ const ClientY = 'event.clientY';
1223
1223
  const DeltaMode = 'event.deltaMode';
1224
1224
  const DeltaY = 'event.deltaY';
1225
1225
  const TargetName = 'event.target.name';
1226
+ const TargetSelectionEnd = 'event.target.selectionEnd';
1227
+ const TargetSelectionStart = 'event.target.selectionStart';
1226
1228
  const TargetValue = 'event.target.value';
1227
1229
 
1228
1230
  const Search$1 = 18;
1231
+ const InputContextMenu = 91;
1229
1232
 
1230
1233
  const None$1 = 0;
1231
1234
 
@@ -1731,7 +1734,7 @@ const collapseDetails = state => {
1731
1734
  };
1732
1735
  };
1733
1736
 
1734
- const copy = async state => {
1737
+ const copy$1 = async state => {
1735
1738
  const {
1736
1739
  items,
1737
1740
  focusedIndex
@@ -1847,7 +1850,25 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
1847
1850
  limit: 20_000,
1848
1851
  fileIconCache: {},
1849
1852
  removeButtonWidth: 20,
1850
- removeButtonRight: 0
1853
+ removeButtonRight: 0,
1854
+ selections: {
1855
+ SearchValue: {
1856
+ start: 0,
1857
+ end: 0
1858
+ },
1859
+ ReplaceValue: {
1860
+ start: 0,
1861
+ end: 0
1862
+ },
1863
+ FilesToExclude: {
1864
+ start: 0,
1865
+ end: 0
1866
+ },
1867
+ FilesToInclude: {
1868
+ start: 0,
1869
+ end: 0
1870
+ }
1871
+ }
1851
1872
  };
1852
1873
  set(uid, state, state);
1853
1874
  return state;
@@ -1860,6 +1881,7 @@ const RenderReplaceValue = 4;
1860
1881
  const RenderIncludeValue = 5;
1861
1882
  const RenderExcludeValue = 6;
1862
1883
  const RenderFocusContext = 7;
1884
+ const RenderSelections = 8;
1863
1885
 
1864
1886
  const diffType$5 = RenderExcludeValue;
1865
1887
  const isEqual$6 = (oldState, newState) => {
@@ -2156,6 +2178,10 @@ const ConfirmReplaceOneOccurrenceInOneFile = "Replace 1 occurrence across 1 file
2156
2178
  const ConfirmReplaceOneOccurrenceInOneFileNoValue = 'Replace 1 occurrence across 1 file';
2157
2179
  const CopyPath = 'Copy Path';
2158
2180
  const Dismiss = 'Dismiss';
2181
+ const Cut = 'Cut';
2182
+ const Copy = 'Copy';
2183
+ const Paste = 'Paste';
2184
+ const SelectAll = 'SelectAll';
2159
2185
  const Exclude = 'Exclude';
2160
2186
  const FilesToExclude$1 = 'Files to Exclude';
2161
2187
  const FilesToInclude$1 = 'Files to Include';
@@ -2282,6 +2308,18 @@ const replace = () => {
2282
2308
  const dismiss = () => {
2283
2309
  return i18nString(Dismiss);
2284
2310
  };
2311
+ const cut = () => {
2312
+ return i18nString(Cut);
2313
+ };
2314
+ const copy = () => {
2315
+ return i18nString(Copy);
2316
+ };
2317
+ const paste = () => {
2318
+ return i18nString(Paste);
2319
+ };
2320
+ const selectAll = () => {
2321
+ return i18nString(SelectAll);
2322
+ };
2285
2323
  const theResultSetOnlyContainsASubSetOfMatches = () => {
2286
2324
  return i18nString(TheResultSetOnlyContainsASubSetOfMatches);
2287
2325
  };
@@ -2635,7 +2673,41 @@ const getKeyBindings = () => {
2635
2673
  return [...getSearchHeaderKeyBindings(), ...getSearchResultKeyBindings()];
2636
2674
  };
2637
2675
 
2638
- const getMenuEntries = () => {
2676
+ const getMenuEntriesInput = options => {
2677
+ const {
2678
+ inputName
2679
+ } = options;
2680
+ if (!inputName) {
2681
+ return [];
2682
+ }
2683
+ return [{
2684
+ id: 'cut',
2685
+ label: cut(),
2686
+ flags: None$1,
2687
+ command: 'Search.handleInputCut',
2688
+ args: [inputName]
2689
+ }, {
2690
+ id: 'copy',
2691
+ label: copy(),
2692
+ flags: None$1,
2693
+ command: 'Search.handleInputCopy',
2694
+ args: [inputName]
2695
+ }, {
2696
+ id: 'paste',
2697
+ label: paste(),
2698
+ flags: None$1,
2699
+ command: 'Search.handleInputPaste',
2700
+ args: [inputName]
2701
+ }, {
2702
+ id: 'selectAll',
2703
+ label: selectAll(),
2704
+ flags: None$1,
2705
+ command: 'Search.handleInputSelectAll',
2706
+ args: [inputName]
2707
+ }];
2708
+ };
2709
+
2710
+ const getMenuEntriesList = () => {
2639
2711
  return [{
2640
2712
  id: 'dismiss',
2641
2713
  label: dismiss(),
@@ -2649,8 +2721,18 @@ const getMenuEntries = () => {
2649
2721
  }];
2650
2722
  };
2651
2723
 
2724
+ const getMenuEntries = (state, props) => {
2725
+ if (props.menuId === Search$1) {
2726
+ return getMenuEntriesList();
2727
+ }
2728
+ if (props.menuId === InputContextMenu) {
2729
+ return getMenuEntriesInput(props);
2730
+ }
2731
+ return [];
2732
+ };
2733
+
2652
2734
  const getMenuEntryIds = () => {
2653
- return [Search$1];
2735
+ return [Search$1, InputContextMenu];
2654
2736
  };
2655
2737
 
2656
2738
  const handleError = error => {
@@ -3307,6 +3389,99 @@ const handleInputBlur = async (state, name) => {
3307
3389
  return state;
3308
3390
  };
3309
3391
 
3392
+ const show2 = async (uid, menuId, x, y, args) => {
3393
+ await showContextMenu2(uid, menuId, x, y, args);
3394
+ };
3395
+
3396
+ const handleInputContextMenu = async (state, name, button, x, y) => {
3397
+ const {
3398
+ uid
3399
+ } = state;
3400
+ await show2(uid, InputContextMenu, x, y, {
3401
+ menuId: InputContextMenu,
3402
+ inputName: name
3403
+ });
3404
+ return state;
3405
+ };
3406
+
3407
+ const handleInputCopy = async (state, name) => {
3408
+ // TODO write selected text to clipboard
3409
+ return state;
3410
+ };
3411
+
3412
+ const getNewText = (currentText, selectionStart, selectionEnd, insertedText) => {
3413
+ const pre = currentText.slice(0, selectionStart);
3414
+ const post = currentText.slice(selectionEnd);
3415
+ const merged = pre + insertedText + post;
3416
+ return merged;
3417
+ };
3418
+
3419
+ const readText = async () => {
3420
+ return await invoke$1('ClipBoard.readText');
3421
+ };
3422
+
3423
+ const isSelectionKey = (name, selections) => {
3424
+ return name in selections;
3425
+ };
3426
+ const getCurrentValue = (state, name) => {
3427
+ switch (name) {
3428
+ case SearchValue:
3429
+ return state.value;
3430
+ case FilesToExclude:
3431
+ return state.excludeValue;
3432
+ case FilesToInclude:
3433
+ return state.includeValue;
3434
+ case ReplaceValue:
3435
+ return state.replacement;
3436
+ default:
3437
+ return '';
3438
+ }
3439
+ };
3440
+ const handleInputPaste = async (state, name) => {
3441
+ const {
3442
+ selections
3443
+ } = state;
3444
+ if (!isSelectionKey(name, selections)) {
3445
+ return state;
3446
+ }
3447
+ const selection = selections[name];
3448
+ const {
3449
+ start,
3450
+ end
3451
+ } = selection;
3452
+ const currentText = getCurrentValue(state, name);
3453
+ const insertedText = await readText();
3454
+ const newText = getNewText(currentText, start, end, insertedText);
3455
+ if (newText) {
3456
+ return state;
3457
+ }
3458
+ // TODO paste text
3459
+ return state;
3460
+ };
3461
+
3462
+ const handleInputCut = async (state, name) => {
3463
+ const {
3464
+ selections
3465
+ } = state;
3466
+ if (!isSelectionKey(name, selections)) {
3467
+ return state;
3468
+ }
3469
+ const selection = selections[name];
3470
+ const {
3471
+ start,
3472
+ end
3473
+ } = selection;
3474
+ const currentText = getCurrentValue(state, name);
3475
+ const insertedText = '';
3476
+ // TODO get cut text
3477
+ const newText = getNewText(currentText, start, end, insertedText);
3478
+ if (newText) {
3479
+ return state;
3480
+ }
3481
+ // TODO cut text
3482
+ return state;
3483
+ };
3484
+
3310
3485
  const getSearchFocusKey = key => {
3311
3486
  switch (key) {
3312
3487
  case SearchValue:
@@ -3350,6 +3525,22 @@ const handleInputFocus = (state, name) => {
3350
3525
  };
3351
3526
  };
3352
3527
 
3528
+ const handleInputSelectionChange = async (state, name, selectionStart, selectionEnd) => {
3529
+ const {
3530
+ selections
3531
+ } = state;
3532
+ return {
3533
+ ...state,
3534
+ selections: {
3535
+ ...selections,
3536
+ [name]: {
3537
+ selectionStart,
3538
+ selectionEnd
3539
+ }
3540
+ }
3541
+ };
3542
+ };
3543
+
3353
3544
  const handleListBlur = state => {
3354
3545
  return {
3355
3546
  ...state,
@@ -3469,6 +3660,7 @@ const focusIndexScrollDown = (state, index, listHeight, itemHeight, itemsLength)
3469
3660
  return {
3470
3661
  ...state,
3471
3662
  focusedIndex: index,
3663
+ listFocusedIndex: index,
3472
3664
  minLineY: newMinLineY,
3473
3665
  maxLineY: newMaxLineY,
3474
3666
  focused: true,
@@ -3491,6 +3683,7 @@ const focusIndexScrollUp = (state, index, listHeight, itemHeight, itemsLength) =
3491
3683
  return {
3492
3684
  ...state,
3493
3685
  focusedIndex: index,
3686
+ listFocusedIndex: index,
3494
3687
  minLineY: newMinLineY,
3495
3688
  maxLineY: newMaxLineY,
3496
3689
  focused: true,
@@ -3516,6 +3709,7 @@ const focusIndex = (state, index) => {
3516
3709
  return {
3517
3710
  ...state,
3518
3711
  focusedIndex: -1,
3712
+ listFocusedIndex: -1,
3519
3713
  focused: true
3520
3714
  };
3521
3715
  }
@@ -3529,6 +3723,7 @@ const focusIndex = (state, index) => {
3529
3723
  return {
3530
3724
  ...state,
3531
3725
  focusedIndex: index,
3726
+ listFocusedIndex: index,
3532
3727
  focused: true
3533
3728
  };
3534
3729
  };
@@ -4270,6 +4465,8 @@ const HandleWheel = 16;
4270
4465
  const HandleInputFocus = 17;
4271
4466
  const HandleInputBlur = 18;
4272
4467
  const HandleListPointerDown = 19;
4468
+ const HandleInputContextMenu = 20;
4469
+ const HandleInputSelectionChange = 21;
4273
4470
 
4274
4471
  const getSearchDetailsToggleVirtualDom = () => {
4275
4472
  return [{
@@ -4449,7 +4646,8 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
4449
4646
  onInput,
4450
4647
  onFocus: HandleInputFocus,
4451
4648
  onBlur: HandleInputBlur,
4452
- onContextMenu: HandleListContextMenu,
4649
+ onContextMenu: HandleInputContextMenu,
4650
+ onSelectionChange: HandleInputSelectionChange,
4453
4651
  childCount: 0
4454
4652
  }, {
4455
4653
  type: Div,
@@ -4887,6 +5085,13 @@ const renderItems = (oldState, newState) => {
4887
5085
  return [SetDom2, newState.uid, dom];
4888
5086
  };
4889
5087
 
5088
+ const renderSelections = (oldState, newState) => {
5089
+ // const { selections, uid } = newState
5090
+
5091
+ // TODO
5092
+ return [];
5093
+ };
5094
+
4890
5095
  const renderValue = (oldState, newState) => {
4891
5096
  return [SetValueByName, SearchValue, newState.value];
4892
5097
  };
@@ -4916,6 +5121,8 @@ const getRenderer = diffType => {
4916
5121
  return renderItems;
4917
5122
  case RenderFocusContext:
4918
5123
  return renderFocusContext;
5124
+ case RenderSelections:
5125
+ return renderSelections;
4919
5126
  default:
4920
5127
  throw new Error('unknown renderer');
4921
5128
  }
@@ -5057,6 +5264,13 @@ const renderEventListeners = () => {
5057
5264
  name: HandleListContextMenu,
5058
5265
  params: ['handleContextMenu', Button$1, ClientX, ClientY],
5059
5266
  preventDefault: true
5267
+ }, {
5268
+ name: HandleInputContextMenu,
5269
+ params: ['handleInputContextMenu', TargetName, Button$1, ClientX, ClientY],
5270
+ preventDefault: true
5271
+ }, {
5272
+ name: HandleInputSelectionChange,
5273
+ params: ['handleInputSelectionChange', TargetName, TargetSelectionStart, TargetSelectionEnd]
5060
5274
  }, {
5061
5275
  name: HandleHeaderContextMenu,
5062
5276
  params: ['handleHeaderContextMenu'],
@@ -5269,10 +5483,6 @@ const viewAsTree = async state => {
5269
5483
 
5270
5484
  const Keyboard = -1;
5271
5485
 
5272
- const show2 = async (uid, menuId, x, y, args) => {
5273
- await showContextMenu2(uid, menuId, x, y, args);
5274
- };
5275
-
5276
5486
  const handleContextMenuKeyboard = async state => {
5277
5487
  const {
5278
5488
  x,
@@ -5314,7 +5524,7 @@ const commandMap = {
5314
5524
  'TextSearch.clearSearchResults': wrapCommand(clearSearchResults$1),
5315
5525
  'TextSearch.collapseAll': wrapCommand(collapseAll$1),
5316
5526
  'TextSearch.collapseDetails': wrapCommand(collapseDetails),
5317
- 'TextSearch.copy': wrapCommand(copy),
5527
+ 'TextSearch.copy': wrapCommand(copy$1),
5318
5528
  'TextSearch.copyPath': wrapCommand(copyPath$1),
5319
5529
  'TextSearch.diff2': diff2,
5320
5530
  'TextSearch.dismissItem': wrapCommand(dismissItem),
@@ -5341,6 +5551,7 @@ const commandMap = {
5341
5551
  'TextSearch.focusReplaceValuePrevious': wrapCommand(focusReplaceValuePrevious),
5342
5552
  'TextSearch.focusSearchValue': wrapCommand(focusSearchValue$1),
5343
5553
  'TextSearch.focusSearchValueNext': wrapCommand(focusSearchValueNext),
5554
+ 'TextSearch.getMenuEntries': wrapGetter(getMenuEntries),
5344
5555
  'TextSearch.handleClickAt': wrapCommand(handleClickAt),
5345
5556
  'TextSearch.handleContextMenu': wrapCommand(handleContextMenu),
5346
5557
  'TextSearch.handleExcludeInput': wrapCommand(handleExcludeInput),
@@ -5354,7 +5565,12 @@ const commandMap = {
5354
5565
  'TextSearch.handleInput': wrapCommand(handleInput),
5355
5566
  'TextSearch.handleInput2': wrapCommand(handleInput2),
5356
5567
  'TextSearch.handleInputBlur': wrapCommand(handleInputBlur),
5568
+ 'TextSearch.handleInputContextMenu': wrapCommand(handleInputContextMenu),
5569
+ 'TextSearch.handleInputCopy': wrapCommand(handleInputCopy),
5570
+ 'TextSearch.handleInputCut': wrapCommand(handleInputCut),
5357
5571
  'TextSearch.handleInputFocus': wrapCommand(handleInputFocus),
5572
+ 'TextSearch.handleInputPaste': wrapCommand(handleInputPaste),
5573
+ 'TextSearch.handleInputSelectionChange': wrapCommand(handleInputSelectionChange),
5358
5574
  'TextSearch.handleListBlur': wrapCommand(handleListBlur),
5359
5575
  'TextSearch.handleListFocus': wrapCommand(handleListFocus),
5360
5576
  'TextSearch.handleListPointerDown': wrapCommand(handleListPointerDown),
@@ -5397,7 +5613,6 @@ const commandMap = {
5397
5613
  'TextSearch.terminate': terminate,
5398
5614
  'TextSearch.renderActions': renderActions,
5399
5615
  'TextSearch.getMenuEntryIds': getMenuEntryIds,
5400
- 'TextSearch.getMenuEntries': getMenuEntries,
5401
5616
  // TODO needed?
5402
5617
  'TextSearch.replaceAllAndPrompt': replaceAllAndPrompt,
5403
5618
  'TextSearch.textSearch': textSearch$6
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "5.24.0",
3
+ "version": "5.26.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"