lexical 0.30.1-nightly.20250415.0 → 0.30.1-nightly.20250417.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.
package/Lexical.dev.js CHANGED
@@ -1786,29 +1786,108 @@ function createCommand(type) {
1786
1786
  const SELECTION_CHANGE_COMMAND = createCommand('SELECTION_CHANGE_COMMAND');
1787
1787
  const SELECTION_INSERT_CLIPBOARD_NODES_COMMAND = createCommand('SELECTION_INSERT_CLIPBOARD_NODES_COMMAND');
1788
1788
  const CLICK_COMMAND = createCommand('CLICK_COMMAND');
1789
+ /**
1790
+ * Dispatched to delete a character, the payload will be `true` if the deletion
1791
+ * is backwards (backspace or delete on macOS) and `false` if forwards
1792
+ * (delete or Fn+Delete on macOS).
1793
+ */
1789
1794
  const DELETE_CHARACTER_COMMAND = createCommand('DELETE_CHARACTER_COMMAND');
1795
+ /**
1796
+ * Dispatched to insert a line break. With a false payload the
1797
+ * cursor moves to the new line (Shift+Enter), with a true payload the cursor
1798
+ * does not move (Ctrl+O on macOS).
1799
+ */
1790
1800
  const INSERT_LINE_BREAK_COMMAND = createCommand('INSERT_LINE_BREAK_COMMAND');
1791
1801
  const INSERT_PARAGRAPH_COMMAND = createCommand('INSERT_PARAGRAPH_COMMAND');
1792
1802
  const CONTROLLED_TEXT_INSERTION_COMMAND = createCommand('CONTROLLED_TEXT_INSERTION_COMMAND');
1793
1803
  const PASTE_COMMAND = createCommand('PASTE_COMMAND');
1794
1804
  const REMOVE_TEXT_COMMAND = createCommand('REMOVE_TEXT_COMMAND');
1805
+ /**
1806
+ * Dispatched to delete a word, the payload will be `true` if the deletion is
1807
+ * backwards (Ctrl+Backspace or Opt+Delete on macOS), and `false` if
1808
+ * forwards (Ctrl+Delete or Fn+Opt+Delete on macOS).
1809
+ */
1795
1810
  const DELETE_WORD_COMMAND = createCommand('DELETE_WORD_COMMAND');
1811
+ /**
1812
+ * Dispatched to delete a line, the payload will be `true` if the deletion is
1813
+ * backwards (Cmd+Delete on macOS), and `false` if forwards
1814
+ * (Fn+Cmd+Delete on macOS).
1815
+ */
1796
1816
  const DELETE_LINE_COMMAND = createCommand('DELETE_LINE_COMMAND');
1817
+ /**
1818
+ * Dispatched to format the selected text.
1819
+ */
1797
1820
  const FORMAT_TEXT_COMMAND = createCommand('FORMAT_TEXT_COMMAND');
1821
+ /**
1822
+ * Dispatched on undo (Cmd+Z on macOS, Ctrl+Z elsewhere).
1823
+ */
1798
1824
  const UNDO_COMMAND = createCommand('UNDO_COMMAND');
1825
+ /**
1826
+ * Dispatched on redo (Shift+Cmd+Z on macOS, Shift+Ctrl+Z or Ctrl+Y elsewhere).
1827
+ */
1799
1828
  const REDO_COMMAND = createCommand('REDO_COMMAND');
1829
+ /**
1830
+ * Dispatched when any key is pressed.
1831
+ */
1800
1832
  const KEY_DOWN_COMMAND = createCommand('KEYDOWN_COMMAND');
1833
+ /**
1834
+ * Dispatched when the `'ArrowRight'` key is pressed.
1835
+ * The shift modifier key may also be down.
1836
+ */
1801
1837
  const KEY_ARROW_RIGHT_COMMAND = createCommand('KEY_ARROW_RIGHT_COMMAND');
1838
+ /**
1839
+ * Dispatched when the move to end keyboard shortcut is pressed,
1840
+ * (Cmd+Right on macOS; Ctrl+Right elsewhere).
1841
+ */
1802
1842
  const MOVE_TO_END = createCommand('MOVE_TO_END');
1843
+ /**
1844
+ * Dispatched when the `'ArrowLeft'` key is pressed.
1845
+ * The shift modifier key may also be down.
1846
+ */
1803
1847
  const KEY_ARROW_LEFT_COMMAND = createCommand('KEY_ARROW_LEFT_COMMAND');
1848
+ /**
1849
+ * Dispatched when the move to start keyboard shortcut is pressed,
1850
+ * (Cmd+Left on macOS; Ctrl+Left elsewhere).
1851
+ */
1804
1852
  const MOVE_TO_START = createCommand('MOVE_TO_START');
1853
+ /**
1854
+ * Dispatched when the `'ArrowUp'` key is pressed.
1855
+ * The shift and/or alt (option) modifier keys may also be down.
1856
+ */
1805
1857
  const KEY_ARROW_UP_COMMAND = createCommand('KEY_ARROW_UP_COMMAND');
1858
+ /**
1859
+ * Dispatched when the `'ArrowUp'` key is pressed.
1860
+ * The shift and/or alt (option) modifier keys may also be down.
1861
+ */
1806
1862
  const KEY_ARROW_DOWN_COMMAND = createCommand('KEY_ARROW_DOWN_COMMAND');
1863
+ /**
1864
+ * Dispatched when the enter key is pressed, may also be called with a null
1865
+ * payload when the intent is to insert a newline.
1866
+ */
1807
1867
  const KEY_ENTER_COMMAND = createCommand('KEY_ENTER_COMMAND');
1868
+ /**
1869
+ * Dispatched whenever the space (`' '`) key is pressed, any modifier
1870
+ * keys may be down.
1871
+ */
1808
1872
  const KEY_SPACE_COMMAND = createCommand('KEY_SPACE_COMMAND');
1873
+ /**
1874
+ * Dispatched whenever the `'Backspace'` key is pressed, the shift
1875
+ * modifier key may be down.
1876
+ */
1809
1877
  const KEY_BACKSPACE_COMMAND = createCommand('KEY_BACKSPACE_COMMAND');
1878
+ /**
1879
+ * Dispatched whenever the `'Escape'` key is pressed, any modifier
1880
+ * keys may be down.
1881
+ */
1810
1882
  const KEY_ESCAPE_COMMAND = createCommand('KEY_ESCAPE_COMMAND');
1883
+ /**
1884
+ * Dispatched whenever the `'Delete'` key is pressed (Fn+Delete on macOS).
1885
+ */
1811
1886
  const KEY_DELETE_COMMAND = createCommand('KEY_DELETE_COMMAND');
1887
+ /**
1888
+ * Dispatched whenever the `'Tab'` key is pressed. The shift modifier key
1889
+ * may be down.
1890
+ */
1812
1891
  const KEY_TAB_COMMAND = createCommand('KEY_TAB_COMMAND');
1813
1892
  const INSERT_TAB_COMMAND = createCommand('INSERT_TAB_COMMAND');
1814
1893
  const INDENT_CONTENT_COMMAND = createCommand('INDENT_CONTENT_COMMAND');
@@ -1818,8 +1897,20 @@ const FORMAT_ELEMENT_COMMAND = createCommand('FORMAT_ELEMENT_COMMAND');
1818
1897
  const DRAGSTART_COMMAND = createCommand('DRAGSTART_COMMAND');
1819
1898
  const DRAGOVER_COMMAND = createCommand('DRAGOVER_COMMAND');
1820
1899
  const DRAGEND_COMMAND = createCommand('DRAGEND_COMMAND');
1900
+ /**
1901
+ * Dispatched on a copy event, either via the clipboard or a KeyboardEvent
1902
+ * (Cmd+C on macOS, Ctrl+C elsewhere).
1903
+ */
1821
1904
  const COPY_COMMAND = createCommand('COPY_COMMAND');
1905
+ /**
1906
+ * Dispatched on a cut event, either via the clipboard or a KeyboardEvent
1907
+ * (Cmd+X on macOS, Ctrl+X elsewhere).
1908
+ */
1822
1909
  const CUT_COMMAND = createCommand('CUT_COMMAND');
1910
+ /**
1911
+ * Dispatched on the select all keyboard shortcut
1912
+ * (Cmd+A on macOS, Ctrl+A elsehwere).
1913
+ */
1823
1914
  const SELECT_ALL_COMMAND = createCommand('SELECT_ALL_COMMAND');
1824
1915
  const CLEAR_EDITOR_COMMAND = createCommand('CLEAR_EDITOR_COMMAND');
1825
1916
  const CLEAR_HISTORY_COMMAND = createCommand('CLEAR_HISTORY_COMMAND');
@@ -1827,6 +1918,12 @@ const CAN_REDO_COMMAND = createCommand('CAN_REDO_COMMAND');
1827
1918
  const CAN_UNDO_COMMAND = createCommand('CAN_UNDO_COMMAND');
1828
1919
  const FOCUS_COMMAND = createCommand('FOCUS_COMMAND');
1829
1920
  const BLUR_COMMAND = createCommand('BLUR_COMMAND');
1921
+ /**
1922
+ * @deprecated in v0.31.0, use KEY_DOWN_COMMAND and check for modifiers
1923
+ * directly.
1924
+ *
1925
+ * Dispatched after any KeyboardEvent when modifiers are pressed
1926
+ */
1830
1927
  const KEY_MODIFIER_COMMAND = createCommand('KEY_MODIFIER_COMMAND');
1831
1928
 
1832
1929
  const PASS_THROUGH_COMMAND = Object.freeze({});
@@ -2520,20 +2617,13 @@ function onKeyDown(event, editor) {
2520
2617
  if (editor.isComposing()) {
2521
2618
  return;
2522
2619
  }
2523
- const {
2524
- key,
2525
- shiftKey,
2526
- ctrlKey,
2527
- metaKey,
2528
- altKey
2529
- } = event;
2530
2620
  if (dispatchCommand(editor, KEY_DOWN_COMMAND, event)) {
2531
2621
  return;
2532
2622
  }
2533
- if (key == null) {
2623
+ if (event.key == null) {
2534
2624
  return;
2535
2625
  }
2536
- if (isSafariEndingComposition && isBackspace(lastKeyCode)) {
2626
+ if (isSafariEndingComposition && isBackspace(event)) {
2537
2627
  updateEditorSync(editor, () => {
2538
2628
  $onCompositionEndImpl(editor, safariEndCompositionEventData);
2539
2629
  });
@@ -2541,96 +2631,95 @@ function onKeyDown(event, editor) {
2541
2631
  safariEndCompositionEventData = '';
2542
2632
  return;
2543
2633
  }
2544
- if (isMoveForward(key, ctrlKey, altKey, metaKey)) {
2634
+ if (isMoveForward(event)) {
2545
2635
  dispatchCommand(editor, KEY_ARROW_RIGHT_COMMAND, event);
2546
- } else if (isMoveToEnd(key, ctrlKey, shiftKey, altKey, metaKey)) {
2636
+ } else if (isMoveToEnd(event)) {
2547
2637
  dispatchCommand(editor, MOVE_TO_END, event);
2548
- } else if (isMoveBackward(key, ctrlKey, altKey, metaKey)) {
2638
+ } else if (isMoveBackward(event)) {
2549
2639
  dispatchCommand(editor, KEY_ARROW_LEFT_COMMAND, event);
2550
- } else if (isMoveToStart(key, ctrlKey, shiftKey, altKey, metaKey)) {
2640
+ } else if (isMoveToStart(event)) {
2551
2641
  dispatchCommand(editor, MOVE_TO_START, event);
2552
- } else if (isMoveUp(key, ctrlKey, metaKey)) {
2642
+ } else if (isMoveUp(event)) {
2553
2643
  dispatchCommand(editor, KEY_ARROW_UP_COMMAND, event);
2554
- } else if (isMoveDown(key, ctrlKey, metaKey)) {
2644
+ } else if (isMoveDown(event)) {
2555
2645
  dispatchCommand(editor, KEY_ARROW_DOWN_COMMAND, event);
2556
- } else if (isLineBreak(key, shiftKey)) {
2646
+ } else if (isLineBreak(event)) {
2557
2647
  isInsertLineBreak = true;
2558
2648
  dispatchCommand(editor, KEY_ENTER_COMMAND, event);
2559
- } else if (isSpace(key)) {
2649
+ } else if (isSpace(event)) {
2560
2650
  dispatchCommand(editor, KEY_SPACE_COMMAND, event);
2561
- } else if (isOpenLineBreak(key, ctrlKey)) {
2651
+ } else if (isOpenLineBreak(event)) {
2562
2652
  event.preventDefault();
2563
2653
  isInsertLineBreak = true;
2564
2654
  dispatchCommand(editor, INSERT_LINE_BREAK_COMMAND, true);
2565
- } else if (isParagraph(key, shiftKey)) {
2655
+ } else if (isParagraph(event)) {
2566
2656
  isInsertLineBreak = false;
2567
2657
  dispatchCommand(editor, KEY_ENTER_COMMAND, event);
2568
- } else if (isDeleteBackward(key, altKey, metaKey, ctrlKey)) {
2569
- if (isBackspace(key)) {
2658
+ } else if (isDeleteBackward(event)) {
2659
+ if (isBackspace(event)) {
2570
2660
  dispatchCommand(editor, KEY_BACKSPACE_COMMAND, event);
2571
2661
  } else {
2572
2662
  event.preventDefault();
2573
2663
  dispatchCommand(editor, DELETE_CHARACTER_COMMAND, true);
2574
2664
  }
2575
- } else if (isEscape(key)) {
2665
+ } else if (isEscape(event)) {
2576
2666
  dispatchCommand(editor, KEY_ESCAPE_COMMAND, event);
2577
- } else if (isDeleteForward(key, ctrlKey, shiftKey, altKey, metaKey)) {
2578
- if (isDelete(key)) {
2667
+ } else if (isDeleteForward(event)) {
2668
+ if (isDelete(event)) {
2579
2669
  dispatchCommand(editor, KEY_DELETE_COMMAND, event);
2580
2670
  } else {
2581
2671
  event.preventDefault();
2582
2672
  dispatchCommand(editor, DELETE_CHARACTER_COMMAND, false);
2583
2673
  }
2584
- } else if (isDeleteWordBackward(key, altKey, ctrlKey)) {
2674
+ } else if (isDeleteWordBackward(event)) {
2585
2675
  event.preventDefault();
2586
2676
  dispatchCommand(editor, DELETE_WORD_COMMAND, true);
2587
- } else if (isDeleteWordForward(key, altKey, ctrlKey)) {
2677
+ } else if (isDeleteWordForward(event)) {
2588
2678
  event.preventDefault();
2589
2679
  dispatchCommand(editor, DELETE_WORD_COMMAND, false);
2590
- } else if (isDeleteLineBackward(key, metaKey)) {
2680
+ } else if (isDeleteLineBackward(event)) {
2591
2681
  event.preventDefault();
2592
2682
  dispatchCommand(editor, DELETE_LINE_COMMAND, true);
2593
- } else if (isDeleteLineForward(key, metaKey, ctrlKey)) {
2683
+ } else if (isDeleteLineForward(event)) {
2594
2684
  event.preventDefault();
2595
2685
  dispatchCommand(editor, DELETE_LINE_COMMAND, false);
2596
- } else if (isBold(key, altKey, metaKey, ctrlKey)) {
2686
+ } else if (isBold(event)) {
2597
2687
  event.preventDefault();
2598
2688
  dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'bold');
2599
- } else if (isUnderline(key, altKey, metaKey, ctrlKey)) {
2689
+ } else if (isUnderline(event)) {
2600
2690
  event.preventDefault();
2601
2691
  dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'underline');
2602
- } else if (isItalic(key, altKey, metaKey, ctrlKey)) {
2692
+ } else if (isItalic(event)) {
2603
2693
  event.preventDefault();
2604
2694
  dispatchCommand(editor, FORMAT_TEXT_COMMAND, 'italic');
2605
- } else if (isTab(key, altKey, ctrlKey, metaKey)) {
2695
+ } else if (isTab(event)) {
2606
2696
  dispatchCommand(editor, KEY_TAB_COMMAND, event);
2607
- } else if (isUndo(key, shiftKey, metaKey, ctrlKey)) {
2697
+ } else if (isUndo(event)) {
2608
2698
  event.preventDefault();
2609
2699
  dispatchCommand(editor, UNDO_COMMAND, undefined);
2610
- } else if (isRedo(key, shiftKey, metaKey, ctrlKey)) {
2700
+ } else if (isRedo(event)) {
2611
2701
  event.preventDefault();
2612
2702
  dispatchCommand(editor, REDO_COMMAND, undefined);
2613
2703
  } else {
2614
2704
  const prevSelection = editor._editorState._selection;
2615
2705
  if (prevSelection !== null && !$isRangeSelection(prevSelection)) {
2616
2706
  // Only RangeSelection can use the native cut/copy/select all
2617
- if (isCopy(key, shiftKey, metaKey, ctrlKey)) {
2707
+ if (isCopy(event)) {
2618
2708
  event.preventDefault();
2619
2709
  dispatchCommand(editor, COPY_COMMAND, event);
2620
- } else if (isCut(key, shiftKey, metaKey, ctrlKey)) {
2710
+ } else if (isCut(event)) {
2621
2711
  event.preventDefault();
2622
2712
  dispatchCommand(editor, CUT_COMMAND, event);
2623
- } else if (isSelectAll(key, metaKey, ctrlKey)) {
2713
+ } else if (isSelectAll(event)) {
2624
2714
  event.preventDefault();
2625
2715
  dispatchCommand(editor, SELECT_ALL_COMMAND, event);
2626
2716
  }
2627
- // FF does it well (no need to override behavior)
2628
- } else if (!IS_FIREFOX && isSelectAll(key, metaKey, ctrlKey)) {
2717
+ } else if (!IS_FIREFOX && isSelectAll(event)) {
2629
2718
  event.preventDefault();
2630
2719
  dispatchCommand(editor, SELECT_ALL_COMMAND, event);
2631
2720
  }
2632
2721
  }
2633
- if (isModifier(ctrlKey, shiftKey, altKey, metaKey)) {
2722
+ if (isModifier(event)) {
2634
2723
  dispatchCommand(editor, KEY_MODIFIER_COMMAND, event);
2635
2724
  }
2636
2725
  }
@@ -10355,7 +10444,7 @@ class LexicalEditor {
10355
10444
  };
10356
10445
  }
10357
10446
  }
10358
- LexicalEditor.version = "0.30.1-nightly.20250415.0+dev.cjs";
10447
+ LexicalEditor.version = "0.30.1-nightly.20250417.0+dev.cjs";
10359
10448
 
10360
10449
  let keyCounter = 1;
10361
10450
  function resetRandomKey() {
@@ -10917,150 +11006,184 @@ function $shouldInsertTextAfterOrBeforeTextNode(selection, node) {
10917
11006
  return false;
10918
11007
  }
10919
11008
  }
10920
- function isTab(key, altKey, ctrlKey, metaKey) {
10921
- return key === 'Tab' && !altKey && !ctrlKey && !metaKey;
11009
+
11010
+ /**
11011
+ * A KeyboardEvent or structurally similar object with a string `key` as well
11012
+ * as `altKey`, `ctrlKey`, `metaKey`, and `shiftKey` boolean properties.
11013
+ */
11014
+
11015
+ /**
11016
+ * A record of keyboard modifiers that must be enabled.
11017
+ * If the value is `'any'` then the modifier key's state is ignored.
11018
+ * If the value is `true` then the modifier key must be pressed.
11019
+ * If the value is `false` or the property is omitted then the modifier key must
11020
+ * not be pressed.
11021
+ */
11022
+
11023
+ function matchModifier(event, mask, prop) {
11024
+ const expected = mask[prop] || false;
11025
+ return expected === 'any' || expected === event[prop];
11026
+ }
11027
+
11028
+ /**
11029
+ * Match a KeyboardEvent with its expected modifier state
11030
+ *
11031
+ * @param event A KeyboardEvent, or structurally similar object
11032
+ * @param mask An object specifying the expected state of the modifiers
11033
+ * @returns true if the event matches
11034
+ */
11035
+ function isModifierMatch(event, mask) {
11036
+ return matchModifier(event, mask, 'altKey') && matchModifier(event, mask, 'ctrlKey') && matchModifier(event, mask, 'shiftKey') && matchModifier(event, mask, 'metaKey');
11037
+ }
11038
+
11039
+ /**
11040
+ * Match a KeyboardEvent with its expected state
11041
+ *
11042
+ * @param event A KeyboardEvent, or structurally similar object
11043
+ * @param expectedKey The string to compare with event.key (case insensitive)
11044
+ * @param mask An object specifying the expected state of the modifiers
11045
+ * @returns true if the event matches
11046
+ */
11047
+ function isExactShortcutMatch(event, expectedKey, mask) {
11048
+ return isModifierMatch(event, mask) && event.key.toLowerCase() === expectedKey.toLowerCase();
11049
+ }
11050
+ const CONTROL_OR_META = {
11051
+ ctrlKey: !IS_APPLE,
11052
+ metaKey: IS_APPLE
11053
+ };
11054
+ const CONTROL_OR_ALT = {
11055
+ altKey: IS_APPLE,
11056
+ ctrlKey: !IS_APPLE
11057
+ };
11058
+ function isTab(event) {
11059
+ return isExactShortcutMatch(event, 'Tab', {
11060
+ shiftKey: 'any'
11061
+ });
10922
11062
  }
10923
- function isBold(key, altKey, metaKey, ctrlKey) {
10924
- return key.toLowerCase() === 'b' && !altKey && controlOrMeta(metaKey, ctrlKey);
11063
+ function isBold(event) {
11064
+ return isExactShortcutMatch(event, 'b', CONTROL_OR_META);
10925
11065
  }
10926
- function isItalic(key, altKey, metaKey, ctrlKey) {
10927
- return key.toLowerCase() === 'i' && !altKey && controlOrMeta(metaKey, ctrlKey);
11066
+ function isItalic(event) {
11067
+ return isExactShortcutMatch(event, 'i', CONTROL_OR_META);
10928
11068
  }
10929
- function isUnderline(key, altKey, metaKey, ctrlKey) {
10930
- return key.toLowerCase() === 'u' && !altKey && controlOrMeta(metaKey, ctrlKey);
11069
+ function isUnderline(event) {
11070
+ return isExactShortcutMatch(event, 'u', CONTROL_OR_META);
10931
11071
  }
10932
- function isParagraph(key, shiftKey) {
10933
- return isReturn(key) && !shiftKey;
11072
+ function isParagraph(event) {
11073
+ return isExactShortcutMatch(event, 'Enter', {});
10934
11074
  }
10935
- function isLineBreak(key, shiftKey) {
10936
- return isReturn(key) && shiftKey;
11075
+ function isLineBreak(event) {
11076
+ return isExactShortcutMatch(event, 'Enter', {
11077
+ shiftKey: true
11078
+ });
10937
11079
  }
10938
11080
 
10939
11081
  // Inserts a new line after the selection
10940
11082
 
10941
- function isOpenLineBreak(key, ctrlKey) {
11083
+ function isOpenLineBreak(event) {
10942
11084
  // 79 = KeyO
10943
- return IS_APPLE && ctrlKey && key.toLowerCase() === 'o';
10944
- }
10945
- function isDeleteWordBackward(key, altKey, ctrlKey) {
10946
- return isBackspace(key) && (IS_APPLE ? altKey : ctrlKey);
11085
+ return IS_APPLE && isExactShortcutMatch(event, 'o', {
11086
+ ctrlKey: true
11087
+ });
10947
11088
  }
10948
- function isDeleteWordForward(key, altKey, ctrlKey) {
10949
- return isDelete(key) && (IS_APPLE ? altKey : ctrlKey);
11089
+ function isDeleteWordBackward(event) {
11090
+ return isExactShortcutMatch(event, 'Backspace', CONTROL_OR_ALT);
10950
11091
  }
10951
- function isDeleteLineBackward(key, metaKey) {
10952
- return IS_APPLE && metaKey && isBackspace(key);
11092
+ function isDeleteWordForward(event) {
11093
+ return isExactShortcutMatch(event, 'Delete', CONTROL_OR_ALT);
10953
11094
  }
10954
- function isDeleteLineForward(key, metaKey, ctrlKey) {
10955
- return IS_APPLE && (metaKey && isDelete(key) || ctrlKey && key.toLowerCase() === 'k');
11095
+ function isDeleteLineBackward(event) {
11096
+ return IS_APPLE && isExactShortcutMatch(event, 'Backspace', {
11097
+ metaKey: true
11098
+ });
10956
11099
  }
10957
- function isDeleteBackward(key, altKey, metaKey, ctrlKey) {
10958
- if (IS_APPLE) {
10959
- if (altKey || metaKey) {
10960
- return false;
10961
- }
10962
- return isBackspace(key) || key.toLowerCase() === 'h' && ctrlKey;
10963
- }
10964
- if (ctrlKey || altKey || metaKey) {
10965
- return false;
10966
- }
10967
- return isBackspace(key);
11100
+ function isDeleteLineForward(event) {
11101
+ return IS_APPLE && (isExactShortcutMatch(event, 'Delete', {
11102
+ metaKey: true
11103
+ }) || isExactShortcutMatch(event, 'k', {
11104
+ ctrlKey: true
11105
+ }));
11106
+ }
11107
+ function isDeleteBackward(event) {
11108
+ return isExactShortcutMatch(event, 'Backspace', {
11109
+ shiftKey: 'any'
11110
+ }) || IS_APPLE && isExactShortcutMatch(event, 'h', {
11111
+ ctrlKey: true
11112
+ });
10968
11113
  }
10969
- function isDeleteForward(key, ctrlKey, shiftKey, altKey, metaKey) {
10970
- if (IS_APPLE) {
10971
- if (shiftKey || altKey || metaKey) {
10972
- return false;
10973
- }
10974
- return isDelete(key) || key.toLowerCase() === 'd' && ctrlKey;
10975
- }
10976
- if (ctrlKey || altKey || metaKey) {
10977
- return false;
10978
- }
10979
- return isDelete(key);
11114
+ function isDeleteForward(event) {
11115
+ return isExactShortcutMatch(event, 'Delete', {}) || IS_APPLE && isExactShortcutMatch(event, 'd', {
11116
+ ctrlKey: true
11117
+ });
10980
11118
  }
10981
- function isUndo(key, shiftKey, metaKey, ctrlKey) {
10982
- return key.toLowerCase() === 'z' && !shiftKey && controlOrMeta(metaKey, ctrlKey);
11119
+ function isUndo(event) {
11120
+ return isExactShortcutMatch(event, 'z', CONTROL_OR_META);
10983
11121
  }
10984
- function isRedo(key, shiftKey, metaKey, ctrlKey) {
11122
+ function isRedo(event) {
10985
11123
  if (IS_APPLE) {
10986
- return key.toLowerCase() === 'z' && metaKey && shiftKey;
10987
- }
10988
- return key.toLowerCase() === 'y' && ctrlKey || key.toLowerCase() === 'z' && ctrlKey && shiftKey;
10989
- }
10990
- function isCopy(key, shiftKey, metaKey, ctrlKey) {
10991
- if (shiftKey) {
10992
- return false;
10993
- }
10994
- if (key.toLowerCase() === 'c') {
10995
- return IS_APPLE ? metaKey : ctrlKey;
10996
- }
10997
- return false;
10998
- }
10999
- function isCut(key, shiftKey, metaKey, ctrlKey) {
11000
- if (shiftKey) {
11001
- return false;
11002
- }
11003
- if (key.toLowerCase() === 'x') {
11004
- return IS_APPLE ? metaKey : ctrlKey;
11124
+ return isExactShortcutMatch(event, 'z', {
11125
+ metaKey: true,
11126
+ shiftKey: true
11127
+ });
11005
11128
  }
11006
- return false;
11007
- }
11008
- function isArrowLeft(key) {
11009
- return key === 'ArrowLeft';
11010
- }
11011
- function isArrowRight(key) {
11012
- return key === 'ArrowRight';
11013
- }
11014
- function isArrowUp(key) {
11015
- return key === 'ArrowUp';
11016
- }
11017
- function isArrowDown(key) {
11018
- return key === 'ArrowDown';
11129
+ return isExactShortcutMatch(event, 'y', {
11130
+ ctrlKey: true
11131
+ }) || isExactShortcutMatch(event, 'z', {
11132
+ ctrlKey: true,
11133
+ shiftKey: true
11134
+ });
11019
11135
  }
11020
- function isMoveBackward(key, ctrlKey, altKey, metaKey) {
11021
- return isArrowLeft(key) && !ctrlKey && !metaKey && !altKey;
11136
+ function isCopy(event) {
11137
+ return isExactShortcutMatch(event, 'c', CONTROL_OR_META);
11022
11138
  }
11023
- function isMoveToStart(key, ctrlKey, shiftKey, altKey, metaKey) {
11024
- return isArrowLeft(key) && !altKey && !shiftKey && (ctrlKey || metaKey);
11139
+ function isCut(event) {
11140
+ return isExactShortcutMatch(event, 'x', CONTROL_OR_META);
11025
11141
  }
11026
- function isMoveForward(key, ctrlKey, altKey, metaKey) {
11027
- return isArrowRight(key) && !ctrlKey && !metaKey && !altKey;
11142
+ function isMoveBackward(event) {
11143
+ return isExactShortcutMatch(event, 'ArrowLeft', {
11144
+ shiftKey: 'any'
11145
+ });
11028
11146
  }
11029
- function isMoveToEnd(key, ctrlKey, shiftKey, altKey, metaKey) {
11030
- return isArrowRight(key) && !altKey && !shiftKey && (ctrlKey || metaKey);
11147
+ function isMoveToStart(event) {
11148
+ return isExactShortcutMatch(event, 'ArrowLeft', CONTROL_OR_META);
11031
11149
  }
11032
- function isMoveUp(key, ctrlKey, metaKey) {
11033
- return isArrowUp(key) && !ctrlKey && !metaKey;
11150
+ function isMoveForward(event) {
11151
+ return isExactShortcutMatch(event, 'ArrowRight', {
11152
+ shiftKey: 'any'
11153
+ });
11034
11154
  }
11035
- function isMoveDown(key, ctrlKey, metaKey) {
11036
- return isArrowDown(key) && !ctrlKey && !metaKey;
11155
+ function isMoveToEnd(event) {
11156
+ return isExactShortcutMatch(event, 'ArrowRight', CONTROL_OR_META);
11037
11157
  }
11038
- function isModifier(ctrlKey, shiftKey, altKey, metaKey) {
11039
- return ctrlKey || shiftKey || altKey || metaKey;
11158
+ function isMoveUp(event) {
11159
+ return isExactShortcutMatch(event, 'ArrowUp', {
11160
+ altKey: 'any',
11161
+ shiftKey: 'any'
11162
+ });
11040
11163
  }
11041
- function isSpace(key) {
11042
- return key === ' ';
11164
+ function isMoveDown(event) {
11165
+ return isExactShortcutMatch(event, 'ArrowDown', {
11166
+ altKey: 'any',
11167
+ shiftKey: 'any'
11168
+ });
11043
11169
  }
11044
- function controlOrMeta(metaKey, ctrlKey) {
11045
- if (IS_APPLE) {
11046
- return metaKey;
11047
- }
11048
- return ctrlKey;
11170
+ function isModifier(event) {
11171
+ return event.ctrlKey || event.shiftKey || event.altKey || event.metaKey;
11049
11172
  }
11050
- function isReturn(key) {
11051
- return key === 'Enter';
11173
+ function isSpace(event) {
11174
+ return event.key === ' ';
11052
11175
  }
11053
- function isBackspace(key) {
11054
- return key === 'Backspace';
11176
+ function isBackspace(event) {
11177
+ return event.key === 'Backspace';
11055
11178
  }
11056
- function isEscape(key) {
11057
- return key === 'Escape';
11179
+ function isEscape(event) {
11180
+ return event.key === 'Escape';
11058
11181
  }
11059
- function isDelete(key) {
11060
- return key === 'Delete';
11182
+ function isDelete(event) {
11183
+ return event.key === 'Delete';
11061
11184
  }
11062
- function isSelectAll(key, metaKey, ctrlKey) {
11063
- return key.toLowerCase() === 'a' && controlOrMeta(metaKey, ctrlKey);
11185
+ function isSelectAll(event) {
11186
+ return isExactShortcutMatch(event, 'a', CONTROL_OR_META);
11064
11187
  }
11065
11188
  function $selectAll(selection) {
11066
11189
  const root = $getRoot();
@@ -13240,10 +13363,12 @@ exports.isDOMNode = isDOMNode;
13240
13363
  exports.isDOMTextNode = isDOMTextNode;
13241
13364
  exports.isDOMUnmanaged = isDOMUnmanaged;
13242
13365
  exports.isDocumentFragment = isDocumentFragment;
13366
+ exports.isExactShortcutMatch = isExactShortcutMatch;
13243
13367
  exports.isHTMLAnchorElement = isHTMLAnchorElement;
13244
13368
  exports.isHTMLElement = isHTMLElement;
13245
13369
  exports.isInlineDomNode = isInlineDomNode;
13246
13370
  exports.isLexicalEditor = isLexicalEditor;
13371
+ exports.isModifierMatch = isModifierMatch;
13247
13372
  exports.isSelectionCapturedInDecoratorInput = isSelectionCapturedInDecoratorInput;
13248
13373
  exports.isSelectionWithinEditor = isSelectionWithinEditor;
13249
13374
  exports.makeStepwiseIterator = makeStepwiseIterator;