Skip to content

Commit d40e4b6

Browse files
committed
feat: add ⌘L shortcut to focus message input with hint
Show a muted "⌘L to focus" hint in the top-right of the message input when unfocused and empty on web. Registers Cmd+L (Mac) / Ctrl+L (non-Mac) bindings for the existing message-input.focus action.
1 parent 8f04e65 commit d40e4b6

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

packages/app/src/components/message-input.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
4242
import { Shortcut } from "@/components/ui/shortcut";
4343
import { useWebElementScrollbar } from "@/components/use-web-scrollbar";
4444
import { useShortcutKeys } from "@/hooks/use-shortcut-keys";
45+
import { formatShortcut } from "@/utils/format-shortcut";
46+
import { getShortcutOs } from "@/utils/shortcut-platform";
4547
import type { MessageInputKeyboardActionKind } from "@/keyboard/actions";
4648
import {
4749
markScrollInvestigationEvent,
@@ -233,7 +235,9 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(funct
233235
const voiceMuteToggleKeys = useShortcutKeys("voice-mute-toggle");
234236
const dictationToggleKeys = useShortcutKeys("dictation-toggle");
235237
const queueKeys = useShortcutKeys("message-input-queue");
238+
const focusInputKeys = useShortcutKeys("focus-message-input");
236239
const [inputHeight, setInputHeight] = useState(MIN_INPUT_HEIGHT);
240+
const [isInputFocused, setIsInputFocused] = useState(false);
237241
const rootRef = useRef<View | null>(null);
238242
const inputWrapperRef = useRef<View | null>(null);
239243
const textInputRef = useRef<TextInput | (TextInput & { getNativeRef?: () => unknown }) | null>(
@@ -997,10 +1001,12 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(funct
9971001
accessibilityLabel="Message agent..."
9981002
onFocus={() => {
9991003
isInputFocusedRef.current = true;
1004+
setIsInputFocused(true);
10001005
onFocusChange?.(true);
10011006
}}
10021007
onBlur={() => {
10031008
isInputFocusedRef.current = false;
1009+
setIsInputFocused(false);
10041010
onFocusChange?.(false);
10051011
}}
10061012
style={[
@@ -1025,6 +1031,11 @@ export const MessageInput = forwardRef<MessageInputRef, MessageInputProps>(funct
10251031
autoFocus={isWeb && autoFocus}
10261032
/>
10271033
{inputScrollbar}
1034+
{isWeb && !isInputFocused && !value && focusInputKeys ? (
1035+
<Text style={styles.focusHintText} pointerEvents="none">
1036+
{formatShortcut(focusInputKeys[0], getShortcutOs())} to focus
1037+
</Text>
1038+
) : null}
10281039
</View>
10291040

10301041
{/* Button row */}
@@ -1270,6 +1281,14 @@ const styles = StyleSheet.create(((theme: any) => ({
12701281
textInputScrollWrapper: {
12711282
position: "relative",
12721283
},
1284+
focusHintText: {
1285+
position: "absolute",
1286+
top: 0,
1287+
right: 0,
1288+
fontSize: theme.fontSize.xs,
1289+
color: theme.colors.foregroundMuted,
1290+
opacity: 0.5,
1291+
},
12731292
textInput: {
12741293
width: "100%",
12751294
color: theme.colors.foreground,

packages/app/src/keyboard/keyboard-shortcuts.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,32 @@ const SHORTCUT_BINDINGS: readonly ShortcutBinding[] = [
791791
},
792792

793793
// --- Message input ---
794+
{
795+
id: "message-input-focus-cmd-l-mac",
796+
action: "message-input.action",
797+
combo: "Cmd+L",
798+
when: { mac: true, commandCenter: false },
799+
payload: { type: "message-input", kind: "focus" },
800+
help: {
801+
id: "focus-message-input",
802+
section: "agent-input",
803+
label: "Focus message input",
804+
keys: ["mod", "L"],
805+
},
806+
},
807+
{
808+
id: "message-input-focus-ctrl-l-non-mac",
809+
action: "message-input.action",
810+
combo: "Ctrl+L",
811+
when: { mac: false, commandCenter: false, terminal: false },
812+
payload: { type: "message-input", kind: "focus" },
813+
help: {
814+
id: "focus-message-input",
815+
section: "agent-input",
816+
label: "Focus message input",
817+
keys: ["mod", "L"],
818+
},
819+
},
794820
{
795821
id: "message-input-voice-toggle-cmd-shift-d-mac",
796822
action: "message-input.action",

0 commit comments

Comments
 (0)