| ... | ... | @@ -9,6 +9,7 @@ import { type ServerProviderSkill } from "@t3tools/contracts"; |
| 9 | 9 | import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger"; |
| 10 | 10 | import { |
| 11 | 11 | $applyNodeReplacement, |
| 12 | $createRangeSelectionFromDom, |
| 12 | 13 | $createRangeSelection, |
| 13 | 14 | $getSelection, |
| 14 | 15 | $setSelection, |
| ... | ... | @@ -23,6 +24,7 @@ import { |
| 23 | 24 | KEY_ARROW_LEFT_COMMAND, |
| 24 | 25 | KEY_ARROW_RIGHT_COMMAND, |
| 25 | 26 | KEY_ARROW_UP_COMMAND, |
| 27 | KEY_DOWN_COMMAND, |
| 26 | 28 | KEY_ENTER_COMMAND, |
| 27 | 29 | KEY_TAB_COMMAND, |
| 28 | 30 | COMMAND_PRIORITY_HIGH, |
| ... | ... | @@ -63,7 +65,7 @@ import { |
| 63 | 65 | INLINE_TERMINAL_CONTEXT_PLACEHOLDER, |
| 64 | 66 | type TerminalContextDraft, |
| 65 | 67 | } from "~/lib/terminalContext"; |
| 66 | | import { cn } from "~/lib/utils"; |
| 68 | import { cn, isMacPlatform } from "~/lib/utils"; |
| 67 | 69 | import { basenameOfPath } from "~/pierre-icons"; |
| 68 | 70 | import { |
| 69 | 71 | COMPOSER_INLINE_CHIP_ICON_CLASS_NAME, |
| ... | ... | @@ -1023,6 +1025,53 @@ function ComposerInlineTokenArrowPlugin() { |
| 1023 | 1025 | return null; |
| 1024 | 1026 | } |
| 1025 | 1027 | |
| 1028 | function ComposerHomeEndKeyPlugin() { |
| 1029 | const [editor] = useLexicalComposerContext(); |
| 1030 | |
| 1031 | useEffect(() => { |
| 1032 | return editor.registerCommand( |
| 1033 | KEY_DOWN_COMMAND, |
| 1034 | (event) => { |
| 1035 | if (!isMacPlatform(navigator.platform)) { |
| 1036 | return false; |
| 1037 | } |
| 1038 | if (event.key !== "Home" && event.key !== "End") { |
| 1039 | return false; |
| 1040 | } |
| 1041 | if (event.altKey || event.metaKey || event.ctrlKey || event.isComposing) { |
| 1042 | return false; |
| 1043 | } |
| 1044 | |
| 1045 | const rootElement = editor.getRootElement(); |
| 1046 | const selection = window.getSelection(); |
| 1047 | const anchorNode = selection?.anchorNode; |
| 1048 | if (!rootElement || !selection || !anchorNode || !rootElement.contains(anchorNode)) { |
| 1049 | return false; |
| 1050 | } |
| 1051 | if (selection.rangeCount === 0 || typeof selection.modify !== "function") { |
| 1052 | return false; |
| 1053 | } |
| 1054 | |
| 1055 | event.preventDefault(); |
| 1056 | event.stopPropagation(); |
| 1057 | |
| 1058 | selection.modify( |
| 1059 | event.shiftKey ? "extend" : "move", |
| 1060 | event.key === "Home" ? "backward" : "forward", |
| 1061 | "lineboundary", |
| 1062 | ); |
| 1063 | editor.update(() => { |
| 1064 | $setSelection($createRangeSelectionFromDom(selection, editor)); |
| 1065 | }); |
| 1066 | return true; |
| 1067 | }, |
| 1068 | COMMAND_PRIORITY_HIGH, |
| 1069 | ); |
| 1070 | }, [editor]); |
| 1071 | |
| 1072 | return null; |
| 1073 | } |
| 1074 | |
| 1026 | 1075 | function ComposerInlineTokenSelectionNormalizePlugin() { |
| 1027 | 1076 | const [editor] = useLexicalComposerContext(); |
| 1028 | 1077 | |
| ... | ... | @@ -1647,6 +1696,7 @@ function ComposerPromptEditorInner({ |
| 1647 | 1696 | <OnChangePlugin onChange={handleEditorChange} /> |
| 1648 | 1697 | <ComposerCommandKeyPlugin {...(onCommandKeyDown ? { onCommandKeyDown } : {})} /> |
| 1649 | 1698 | <ComposerSurroundSelectionPlugin terminalContexts={terminalContexts} skills={skills} /> |
| 1699 | <ComposerHomeEndKeyPlugin /> |
| 1650 | 1700 | <ComposerInlineTokenArrowPlugin /> |
| 1651 | 1701 | <ComposerInlineTokenSelectionNormalizePlugin /> |
| 1652 | 1702 | <ComposerInlineTokenBackspacePlugin /> |