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";
99import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
1010import {
1111 $applyNodeReplacement,
12 $createRangeSelectionFromDom,
1213 $createRangeSelection,
1314 $getSelection,
1415 $setSelection,
......@@ -23,6 +24,7 @@ import {
2324 KEY_ARROW_LEFT_COMMAND,
2425 KEY_ARROW_RIGHT_COMMAND,
2526 KEY_ARROW_UP_COMMAND,
27 KEY_DOWN_COMMAND,
2628 KEY_ENTER_COMMAND,
2729 KEY_TAB_COMMAND,
2830 COMMAND_PRIORITY_HIGH,
......@@ -63,7 +65,7 @@ import {
6365 INLINE_TERMINAL_CONTEXT_PLACEHOLDER,
6466 type TerminalContextDraft,
6567} from "~/lib/terminalContext";
66import { cn } from "~/lib/utils";
68import { cn, isMacPlatform } from "~/lib/utils";
6769import { basenameOfPath } from "~/pierre-icons";
6870import {
6971 COMPOSER_INLINE_CHIP_ICON_CLASS_NAME,
......@@ -1023,6 +1025,53 @@ function ComposerInlineTokenArrowPlugin() {
10231025 return null;
10241026}
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
10261075function ComposerInlineTokenSelectionNormalizePlugin() {
10271076 const [editor] = useLexicalComposerContext();
10281077
......@@ -1647,6 +1696,7 @@ function ComposerPromptEditorInner({
16471696 <OnChangePlugin onChange={handleEditorChange} />
16481697 <ComposerCommandKeyPlugin {...(onCommandKeyDown ? { onCommandKeyDown } : {})} />
16491698 <ComposerSurroundSelectionPlugin terminalContexts={terminalContexts} skills={skills} />
1699 <ComposerHomeEndKeyPlugin />
16501700 <ComposerInlineTokenArrowPlugin />
16511701 <ComposerInlineTokenSelectionNormalizePlugin />
16521702 <ComposerInlineTokenBackspacePlugin />