authorgravatar for 46866023+GuilhermeVieiraDev@users.noreply.github.comGuilherme Vieira <46866023+GuilhermeVieiraDev@users.noreply.github.com> 2026-07-18 12:23:57+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2026-07-18 13:23:57+02:00
logb859a575d19cc0ff060b11a94a0f8aa92cb38c3f
tree64c00667ab84a1365d6b2336270a43de0a8863e2
parente63403fe9259b67f8beccdbf8117671ffefaf48f
signature Signed by PGP key B5690EEEBB952194

fix(web): handle macOS Home and End in composer (#2508)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

1 files changed, 51 insertions(+), 1 deletions(-)

apps/web/src/components/ComposerPromptEditor.tsx+51-1
...@@ -9,6 +9,7 @@ import { type ServerProviderSkill } from "@t3tools/contracts";...@@ -9,6 +9,7 @@ import { type ServerProviderSkill } from "@t3tools/contracts";
9import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";9import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
10import {10import {
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";
66import { cn } from "~/lib/utils";68import { cn, isMacPlatform } from "~/lib/utils";
67import { basenameOfPath } from "~/pierre-icons";69import { basenameOfPath } from "~/pierre-icons";
68import {70import {
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}
10251027
1028function 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
1026function ComposerInlineTokenSelectionNormalizePlugin() {1075function ComposerInlineTokenSelectionNormalizePlugin() {
1027 const [editor] = useLexicalComposerContext();1076 const [editor] = useLexicalComposerContext();
10281077
...@@ -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 />