| ... | @@ -9,6 +9,7 @@ import { type ServerProviderSkill } from "@t3tools/contracts"; | ... | @@ -9,6 +9,7 @@ import { type ServerProviderSkill } from "@t3tools/contracts"; |
| 9 | import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger"; | 9 | import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger"; |
| 10 | import { | 10 | import { |
| 11 | $applyNodeReplacement, | 11 | $applyNodeReplacement, |
| | 12 | $createRangeSelectionFromDom, |
| 12 | $createRangeSelection, | 13 | $createRangeSelection, |
| 13 | $getSelection, | 14 | $getSelection, |
| 14 | $setSelection, | 15 | $setSelection, |
| ... | @@ -23,6 +24,7 @@ import { | ... | @@ -23,6 +24,7 @@ import { |
| 23 | KEY_ARROW_LEFT_COMMAND, | 24 | KEY_ARROW_LEFT_COMMAND, |
| 24 | KEY_ARROW_RIGHT_COMMAND, | 25 | KEY_ARROW_RIGHT_COMMAND, |
| 25 | KEY_ARROW_UP_COMMAND, | 26 | KEY_ARROW_UP_COMMAND, |
| | 27 | KEY_DOWN_COMMAND, |
| 26 | KEY_ENTER_COMMAND, | 28 | KEY_ENTER_COMMAND, |
| 27 | KEY_TAB_COMMAND, | 29 | KEY_TAB_COMMAND, |
| 28 | COMMAND_PRIORITY_HIGH, | 30 | COMMAND_PRIORITY_HIGH, |
| ... | @@ -63,7 +65,7 @@ import { | ... | @@ -63,7 +65,7 @@ import { |
| 63 | INLINE_TERMINAL_CONTEXT_PLACEHOLDER, | 65 | INLINE_TERMINAL_CONTEXT_PLACEHOLDER, |
| 64 | type TerminalContextDraft, | 66 | type TerminalContextDraft, |
| 65 | } from "~/lib/terminalContext"; | 67 | } from "~/lib/terminalContext"; |
| 66 | import { cn } from "~/lib/utils"; | 68 | import { cn, isMacPlatform } from "~/lib/utils"; |
| 67 | import { basenameOfPath } from "~/pierre-icons"; | 69 | import { basenameOfPath } from "~/pierre-icons"; |
| 68 | import { | 70 | import { |
| 69 | COMPOSER_INLINE_CHIP_ICON_CLASS_NAME, | 71 | COMPOSER_INLINE_CHIP_ICON_CLASS_NAME, |
| ... | @@ -1023,6 +1025,53 @@ function ComposerInlineTokenArrowPlugin() { | ... | @@ -1023,6 +1025,53 @@ function ComposerInlineTokenArrowPlugin() { |
| 1023 | return null; | 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 | function ComposerInlineTokenSelectionNormalizePlugin() { | 1075 | function ComposerInlineTokenSelectionNormalizePlugin() { |
| 1027 | const [editor] = useLexicalComposerContext(); | 1076 | const [editor] = useLexicalComposerContext(); |
| 1028 | | 1077 | |
| ... | @@ -1647,6 +1696,7 @@ function ComposerPromptEditorInner({ | ... | @@ -1647,6 +1696,7 @@ function ComposerPromptEditorInner({ |
| 1647 | <OnChangePlugin onChange={handleEditorChange} /> | 1696 | <OnChangePlugin onChange={handleEditorChange} /> |
| 1648 | <ComposerCommandKeyPlugin {...(onCommandKeyDown ? { onCommandKeyDown } : {})} /> | 1697 | <ComposerCommandKeyPlugin {...(onCommandKeyDown ? { onCommandKeyDown } : {})} /> |
| 1649 | <ComposerSurroundSelectionPlugin terminalContexts={terminalContexts} skills={skills} /> | 1698 | <ComposerSurroundSelectionPlugin terminalContexts={terminalContexts} skills={skills} /> |
| | 1699 | <ComposerHomeEndKeyPlugin /> |
| 1650 | <ComposerInlineTokenArrowPlugin /> | 1700 | <ComposerInlineTokenArrowPlugin /> |
| 1651 | <ComposerInlineTokenSelectionNormalizePlugin /> | 1701 | <ComposerInlineTokenSelectionNormalizePlugin /> |
| 1652 | <ComposerInlineTokenBackspacePlugin /> | 1702 | <ComposerInlineTokenBackspacePlugin /> |