@lvce-editor/text-search-worker 5.25.0 → 5.27.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,10 +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;
1229
- const InputContextMenu$1 = 91;
1231
+ const InputContextMenu = 91;
1230
1232
 
1231
1233
  const None$1 = 0;
1232
1234
 
@@ -1848,7 +1850,25 @@ const create = (uid, x, y, width, height, workspacePath, assetDir, itemHeight, v
1848
1850
  limit: 20_000,
1849
1851
  fileIconCache: {},
1850
1852
  removeButtonWidth: 20,
1851
- 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
+ }
1852
1872
  };
1853
1873
  set(uid, state, state);
1854
1874
  return state;
@@ -1861,6 +1881,7 @@ const RenderReplaceValue = 4;
1861
1881
  const RenderIncludeValue = 5;
1862
1882
  const RenderExcludeValue = 6;
1863
1883
  const RenderFocusContext = 7;
1884
+ const RenderSelections = 8;
1864
1885
 
1865
1886
  const diffType$5 = RenderExcludeValue;
1866
1887
  const isEqual$6 = (oldState, newState) => {
@@ -2652,27 +2673,37 @@ const getKeyBindings = () => {
2652
2673
  return [...getSearchHeaderKeyBindings(), ...getSearchResultKeyBindings()];
2653
2674
  };
2654
2675
 
2655
- const getMenuEntriesInput = () => {
2676
+ const getMenuEntriesInput = options => {
2677
+ const {
2678
+ inputName
2679
+ } = options;
2680
+ if (!inputName) {
2681
+ return [];
2682
+ }
2656
2683
  return [{
2657
2684
  id: 'cut',
2658
2685
  label: cut(),
2659
2686
  flags: None$1,
2660
- command: 'Search.cut'
2687
+ command: 'Search.handleInputCut',
2688
+ args: [inputName]
2661
2689
  }, {
2662
2690
  id: 'copy',
2663
2691
  label: copy(),
2664
2692
  flags: None$1,
2665
- command: 'Search.copy'
2693
+ command: 'Search.handleInputCopy',
2694
+ args: [inputName]
2666
2695
  }, {
2667
2696
  id: 'paste',
2668
2697
  label: paste(),
2669
2698
  flags: None$1,
2670
- command: 'Search.paste'
2699
+ command: 'Search.handleInputPaste',
2700
+ args: [inputName]
2671
2701
  }, {
2672
2702
  id: 'selectAll',
2673
2703
  label: selectAll(),
2674
2704
  flags: None$1,
2675
- command: 'Search.selectAll'
2705
+ command: 'Search.handleInputSelectAll',
2706
+ args: [inputName]
2676
2707
  }];
2677
2708
  };
2678
2709
 
@@ -2694,13 +2725,12 @@ const getMenuEntries = (state, props) => {
2694
2725
  if (props.menuId === Search$1) {
2695
2726
  return getMenuEntriesList();
2696
2727
  }
2697
- if (props.menuId === InputContextMenu$1) {
2698
- return getMenuEntriesInput();
2728
+ if (props.menuId === InputContextMenu) {
2729
+ return getMenuEntriesInput(props);
2699
2730
  }
2700
2731
  return [];
2701
2732
  };
2702
2733
 
2703
- const InputContextMenu = 91;
2704
2734
  const getMenuEntryIds = () => {
2705
2735
  return [Search$1, InputContextMenu];
2706
2736
  };
@@ -3363,16 +3393,144 @@ const show2 = async (uid, menuId, x, y, args) => {
3363
3393
  await showContextMenu2(uid, menuId, x, y, args);
3364
3394
  };
3365
3395
 
3366
- const handleInputContextMenu = async (state, button, x, y) => {
3396
+ const handleInputContextMenu = async (state, name, button, x, y) => {
3367
3397
  const {
3368
3398
  uid
3369
3399
  } = state;
3370
- await show2(uid, InputContextMenu$1, x, y, {
3371
- menuId: InputContextMenu$1
3400
+ await show2(uid, InputContextMenu, x, y, {
3401
+ menuId: InputContextMenu,
3402
+ inputName: name
3372
3403
  });
3373
3404
  return state;
3374
3405
  };
3375
3406
 
3407
+ const writeText = async text => {
3408
+ await writeClipBoardText(text);
3409
+ };
3410
+ const readText = async () => {
3411
+ return await invoke$1('ClipBoard.readText');
3412
+ };
3413
+
3414
+ const getNewText = (currentText, selectionStart, selectionEnd, insertedText) => {
3415
+ const pre = currentText.slice(0, selectionStart);
3416
+ const post = currentText.slice(selectionEnd);
3417
+ const merged = pre + insertedText + post;
3418
+ return merged;
3419
+ };
3420
+
3421
+ const isSelectionKey = (name, selections) => {
3422
+ return name in selections;
3423
+ };
3424
+ const getCurrentValue = (state, name) => {
3425
+ switch (name) {
3426
+ case SearchValue:
3427
+ return state.value;
3428
+ case FilesToExclude:
3429
+ return state.excludeValue;
3430
+ case FilesToInclude:
3431
+ return state.includeValue;
3432
+ case ReplaceValue:
3433
+ return state.replacement;
3434
+ default:
3435
+ return '';
3436
+ }
3437
+ };
3438
+ const updateValue = (state, name, newValue) => {
3439
+ switch (name) {
3440
+ case SearchValue:
3441
+ return {
3442
+ ...state,
3443
+ value: newValue
3444
+ };
3445
+ case ReplaceValue:
3446
+ return {
3447
+ ...state,
3448
+ replacement: newValue
3449
+ };
3450
+ case FilesToInclude:
3451
+ return {
3452
+ ...state,
3453
+ includeValue: newValue
3454
+ };
3455
+ case FilesToExclude:
3456
+ return {
3457
+ ...state,
3458
+ excludeValue: newValue
3459
+ };
3460
+ default:
3461
+ return state;
3462
+ }
3463
+ };
3464
+ const handleInputPaste = async (state, name) => {
3465
+ const {
3466
+ selections
3467
+ } = state;
3468
+ if (!isSelectionKey(name, selections)) {
3469
+ return state;
3470
+ }
3471
+ const selection = selections[name];
3472
+ const {
3473
+ start,
3474
+ end
3475
+ } = selection;
3476
+ const currentText = getCurrentValue(state, name);
3477
+ const insertedText = await readText();
3478
+ const newText = getNewText(currentText, start, end, insertedText);
3479
+ if (newText === currentText) {
3480
+ return state;
3481
+ }
3482
+ return updateValue(state, name, newText);
3483
+ };
3484
+
3485
+ const handleInputCopy = async (state, name) => {
3486
+ const {
3487
+ selections
3488
+ } = state;
3489
+ if (!isSelectionKey(name, selections)) {
3490
+ return state;
3491
+ }
3492
+ const selection = selections[name];
3493
+ const {
3494
+ start,
3495
+ end
3496
+ } = selection;
3497
+ const currentText = getCurrentValue(state, name);
3498
+ const toCopy = currentText.slice(start, end);
3499
+ await writeText(toCopy);
3500
+ return state;
3501
+ };
3502
+
3503
+ const getNewTextCut = (currentText, selectionStart, selectionEnd) => {
3504
+ const pre = currentText.slice(0, selectionStart);
3505
+ const middle = currentText.slice(selectionStart, selectionEnd);
3506
+ const post = currentText.slice(selectionEnd);
3507
+ return {
3508
+ newText: pre + post,
3509
+ cutText: middle
3510
+ };
3511
+ };
3512
+
3513
+ const handleInputCut = async (state, name) => {
3514
+ const {
3515
+ selections
3516
+ } = state;
3517
+ if (!isSelectionKey(name, selections)) {
3518
+ return state;
3519
+ }
3520
+ const selection = selections[name];
3521
+ const {
3522
+ start,
3523
+ end
3524
+ } = selection;
3525
+ const currentText = getCurrentValue(state, name);
3526
+ const {
3527
+ newText,
3528
+ cutText
3529
+ } = getNewTextCut(currentText, start, end);
3530
+ await writeText(cutText);
3531
+ return updateValue(state, name, newText);
3532
+ };
3533
+
3376
3534
  const getSearchFocusKey = key => {
3377
3535
  switch (key) {
3378
3536
  case SearchValue:
@@ -3416,6 +3574,22 @@ const handleInputFocus = (state, name) => {
3416
3574
  };
3417
3575
  };
3418
3576
 
3577
+ const handleInputSelectionChange = async (state, name, selectionStart, selectionEnd) => {
3578
+ const {
3579
+ selections
3580
+ } = state;
3581
+ return {
3582
+ ...state,
3583
+ selections: {
3584
+ ...selections,
3585
+ [name]: {
3586
+ selectionStart,
3587
+ selectionEnd
3588
+ }
3589
+ }
3590
+ };
3591
+ };
3592
+
3419
3593
  const handleListBlur = state => {
3420
3594
  return {
3421
3595
  ...state,
@@ -4341,6 +4515,7 @@ const HandleInputFocus = 17;
4341
4515
  const HandleInputBlur = 18;
4342
4516
  const HandleListPointerDown = 19;
4343
4517
  const HandleInputContextMenu = 20;
4518
+ const HandleInputSelectionChange = 21;
4344
4519
 
4345
4520
  const getSearchDetailsToggleVirtualDom = () => {
4346
4521
  return [{
@@ -4521,6 +4696,7 @@ const getSearchFieldVirtualDom = (name, placeholder, onInput, insideButtons, out
4521
4696
  onFocus: HandleInputFocus,
4522
4697
  onBlur: HandleInputBlur,
4523
4698
  onContextMenu: HandleInputContextMenu,
4699
+ onSelectionChange: HandleInputSelectionChange,
4524
4700
  childCount: 0
4525
4701
  }, {
4526
4702
  type: Div,
@@ -4958,6 +5134,13 @@ const renderItems = (oldState, newState) => {
4958
5134
  return [SetDom2, newState.uid, dom];
4959
5135
  };
4960
5136
 
5137
+ const renderSelections = (oldState, newState) => {
5138
+ // const { selections, uid } = newState
5139
+
5140
+ // TODO
5141
+ return [];
5142
+ };
5143
+
4961
5144
  const renderValue = (oldState, newState) => {
4962
5145
  return [SetValueByName, SearchValue, newState.value];
4963
5146
  };
@@ -4987,6 +5170,8 @@ const getRenderer = diffType => {
4987
5170
  return renderItems;
4988
5171
  case RenderFocusContext:
4989
5172
  return renderFocusContext;
5173
+ case RenderSelections:
5174
+ return renderSelections;
4990
5175
  default:
4991
5176
  throw new Error('unknown renderer');
4992
5177
  }
@@ -5130,8 +5315,11 @@ const renderEventListeners = () => {
5130
5315
  preventDefault: true
5131
5316
  }, {
5132
5317
  name: HandleInputContextMenu,
5133
- params: ['handleInputContextMenu', Button$1, ClientX, ClientY],
5318
+ params: ['handleInputContextMenu', TargetName, Button$1, ClientX, ClientY],
5134
5319
  preventDefault: true
5320
+ }, {
5321
+ name: HandleInputSelectionChange,
5322
+ params: ['handleInputSelectionChange', TargetName, TargetSelectionStart, TargetSelectionEnd]
5135
5323
  }, {
5136
5324
  name: HandleHeaderContextMenu,
5137
5325
  params: ['handleHeaderContextMenu'],
@@ -5403,7 +5591,6 @@ const commandMap = {
5403
5591
  'TextSearch.focusPreserveCasePrevious': wrapCommand(focusPreserveCasePrevious),
5404
5592
  'TextSearch.focusPrevious': wrapCommand(focusPrevious),
5405
5593
  'TextSearch.focusPreviousInput': wrapCommand(focusPreviousInput),
5406
- 'TextSearch.handleInputContextMenu': wrapCommand(handleInputContextMenu),
5407
5594
  'TextSearch.focusPreviousPage': wrapCommand(focusPreviousPage),
5408
5595
  'TextSearch.focusRegex': wrapCommand(focusRegex),
5409
5596
  'TextSearch.focusRegexNext': wrapCommand(focusRegexNext),
@@ -5413,6 +5600,7 @@ const commandMap = {
5413
5600
  'TextSearch.focusReplaceValuePrevious': wrapCommand(focusReplaceValuePrevious),
5414
5601
  'TextSearch.focusSearchValue': wrapCommand(focusSearchValue$1),
5415
5602
  'TextSearch.focusSearchValueNext': wrapCommand(focusSearchValueNext),
5603
+ 'TextSearch.getMenuEntries': wrapGetter(getMenuEntries),
5416
5604
  'TextSearch.handleClickAt': wrapCommand(handleClickAt),
5417
5605
  'TextSearch.handleContextMenu': wrapCommand(handleContextMenu),
5418
5606
  'TextSearch.handleExcludeInput': wrapCommand(handleExcludeInput),
@@ -5426,7 +5614,12 @@ const commandMap = {
5426
5614
  'TextSearch.handleInput': wrapCommand(handleInput),
5427
5615
  'TextSearch.handleInput2': wrapCommand(handleInput2),
5428
5616
  'TextSearch.handleInputBlur': wrapCommand(handleInputBlur),
5617
+ 'TextSearch.handleInputContextMenu': wrapCommand(handleInputContextMenu),
5618
+ 'TextSearch.handleInputCopy': wrapCommand(handleInputCopy),
5619
+ 'TextSearch.handleInputCut': wrapCommand(handleInputCut),
5429
5620
  'TextSearch.handleInputFocus': wrapCommand(handleInputFocus),
5621
+ 'TextSearch.handleInputPaste': wrapCommand(handleInputPaste),
5622
+ 'TextSearch.handleInputSelectionChange': wrapCommand(handleInputSelectionChange),
5430
5623
  'TextSearch.handleListBlur': wrapCommand(handleListBlur),
5431
5624
  'TextSearch.handleListFocus': wrapCommand(handleListFocus),
5432
5625
  'TextSearch.handleListPointerDown': wrapCommand(handleListPointerDown),
@@ -5456,7 +5649,6 @@ const commandMap = {
5456
5649
  'TextSearch.toggleUseIgnoreFiles': wrapCommand(toggleUseIgnoreFiles),
5457
5650
  'TextSearch.toggleUseRegularExpression': wrapCommand(toggleUseRegularExpression),
5458
5651
  'TextSearch.viewAsTree': wrapCommand(viewAsTree),
5459
- 'TextSearch.getMenuEntries': wrapGetter(getMenuEntries),
5460
5652
  // not wrapped
5461
5653
  'TextSearch.initialize': initialize,
5462
5654
  'TextSearch.create': create,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "5.25.0",
3
+ "version": "5.27.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"