@lvce-editor/text-search-worker 5.26.0 → 5.28.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.
@@ -1227,6 +1227,8 @@ const TargetSelectionEnd = 'event.target.selectionEnd';
1227
1227
  const TargetSelectionStart = 'event.target.selectionStart';
1228
1228
  const TargetValue = 'event.target.value';
1229
1229
 
1230
+ const Script$1 = 2;
1231
+
1230
1232
  const Search$1 = 18;
1231
1233
  const InputContextMenu = 91;
1232
1234
 
@@ -1310,6 +1312,10 @@ const {
1310
1312
  invokeAndTransfer,
1311
1313
  set: set$1} = create$3(RendererWorker);
1312
1314
  const showContextMenu2 = async (uid, menuId, x, y, args) => {
1315
+ number(uid);
1316
+ number(menuId);
1317
+ number(x);
1318
+ number(y);
1313
1319
  // @ts-ignore
1314
1320
  await invoke$1('ContextMenu.show2', uid, menuId, x, y, args);
1315
1321
  };
@@ -3404,25 +3410,13 @@ const handleInputContextMenu = async (state, name, button, x, y) => {
3404
3410
  return state;
3405
3411
  };
3406
3412
 
3407
- const handleInputCopy = async (state, name) => {
3408
- // TODO write selected text to clipboard
3409
- return state;
3413
+ const writeText = async text => {
3414
+ await writeClipBoardText(text);
3410
3415
  };
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
3416
  const readText = async () => {
3420
3417
  return await invoke$1('ClipBoard.readText');
3421
3418
  };
3422
3419
 
3423
- const isSelectionKey = (name, selections) => {
3424
- return name in selections;
3425
- };
3426
3420
  const getCurrentValue = (state, name) => {
3427
3421
  switch (name) {
3428
3422
  case SearchValue:
@@ -3437,6 +3431,47 @@ const getCurrentValue = (state, name) => {
3437
3431
  return '';
3438
3432
  }
3439
3433
  };
3434
+
3435
+ const getNewText = (currentText, selectionStart, selectionEnd, insertedText) => {
3436
+ const pre = currentText.slice(0, selectionStart);
3437
+ const post = currentText.slice(selectionEnd);
3438
+ const merged = pre + insertedText + post;
3439
+ return merged;
3440
+ };
3441
+
3442
+ const isSelectionKey = (name, selections) => {
3443
+ return name in selections;
3444
+ };
3445
+ const updateValue = (state, name, newValue) => {
3446
+ switch (name) {
3447
+ case SearchValue:
3448
+ return {
3449
+ ...state,
3450
+ value: newValue,
3451
+ inputSource: Script$1
3452
+ };
3453
+ case ReplaceValue:
3454
+ return {
3455
+ ...state,
3456
+ replacement: newValue,
3457
+ inputSource: Script$1
3458
+ };
3459
+ case FilesToInclude:
3460
+ return {
3461
+ ...state,
3462
+ includeValue: newValue,
3463
+ inputSource: Script$1
3464
+ };
3465
+ case FilesToExclude:
3466
+ return {
3467
+ ...state,
3468
+ excludeValue: newValue,
3469
+ inputSource: Script$1
3470
+ };
3471
+ default:
3472
+ return state;
3473
+ }
3474
+ };
3440
3475
  const handleInputPaste = async (state, name) => {
3441
3476
  const {
3442
3477
  selections
@@ -3452,13 +3487,37 @@ const handleInputPaste = async (state, name) => {
3452
3487
  const currentText = getCurrentValue(state, name);
3453
3488
  const insertedText = await readText();
3454
3489
  const newText = getNewText(currentText, start, end, insertedText);
3455
- if (newText) {
3490
+ return updateValue(state, name, newText);
3491
+ };
3492
+
3493
+ const handleInputCopy = async (state, name) => {
3494
+ const {
3495
+ selections
3496
+ } = state;
3497
+ if (!isSelectionKey(name, selections)) {
3456
3498
  return state;
3457
3499
  }
3458
- // TODO paste text
3500
+ const selection = selections[name];
3501
+ const {
3502
+ start,
3503
+ end
3504
+ } = selection;
3505
+ const currentText = getCurrentValue(state, name);
3506
+ const toCopy = currentText.slice(start, end);
3507
+ await writeText(toCopy);
3459
3508
  return state;
3460
3509
  };
3461
3510
 
3511
+ const getNewTextCut = (currentText, selectionStart, selectionEnd) => {
3512
+ const pre = currentText.slice(0, selectionStart);
3513
+ const middle = currentText.slice(selectionStart, selectionEnd);
3514
+ const post = currentText.slice(selectionEnd);
3515
+ return {
3516
+ newText: pre + post,
3517
+ cutText: middle
3518
+ };
3519
+ };
3520
+
3462
3521
  const handleInputCut = async (state, name) => {
3463
3522
  const {
3464
3523
  selections
@@ -3472,14 +3531,12 @@ const handleInputCut = async (state, name) => {
3472
3531
  end
3473
3532
  } = selection;
3474
3533
  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;
3534
+ const {
3535
+ newText,
3536
+ cutText
3537
+ } = getNewTextCut(currentText, start, end);
3538
+ await writeText(cutText);
3539
+ return updateValue(state, name, newText);
3483
3540
  };
3484
3541
 
3485
3542
  const getSearchFocusKey = key => {
@@ -3534,8 +3591,8 @@ const handleInputSelectionChange = async (state, name, selectionStart, selection
3534
3591
  selections: {
3535
3592
  ...selections,
3536
3593
  [name]: {
3537
- selectionStart,
3538
- selectionEnd
3594
+ start: selectionStart,
3595
+ end: selectionEnd
3539
3596
  }
3540
3597
  }
3541
3598
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lvce-editor/text-search-worker",
3
- "version": "5.26.0",
3
+ "version": "5.28.0",
4
4
  "description": "Text Search Worker",
5
5
  "keywords": [
6
6
  "text-search"