Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/keybinds.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ When documentation shows `Ctrl`, it means:

| Action | Shortcut |
| ---------------------- | ------------- |
| Focus chat input | `a` or `i` |
| Send message | `Enter` |
| New line in message | `Shift+Enter` |
| Jump to bottom of chat | `Shift+G` |
Expand Down
55 changes: 48 additions & 7 deletions src/components/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
type SlashSuggestion,
} from "@/utils/slashCommands/suggestions";
import { TooltipWrapper, Tooltip, HelpIndicator } from "./Tooltip";
import { matchesKeybind, formatKeybind, KEYBINDS } from "@/utils/ui/keybinds";
import { matchesKeybind, formatKeybind, KEYBINDS, isEditableElement } from "@/utils/ui/keybinds";
import { defaultModel } from "@/utils/ai/models";
import { ModelSelector, type ModelSelectorRef } from "./ModelSelector";
import { useModelLRU } from "@/hooks/useModelLRU";
Expand Down Expand Up @@ -332,6 +332,47 @@ export const ChatInput: React.FC<ChatInputProps> = ({
const [mode, setMode] = useMode();
const { recentModels } = useModelLRU();

const focusMessageInput = useCallback(() => {
const element = inputRef.current;
if (!element || element.disabled) {
return;
}

element.focus();

requestAnimationFrame(() => {
const cursor = element.value.length;
element.selectionStart = cursor;
element.selectionEnd = cursor;
element.style.height = "auto";
element.style.height = Math.min(element.scrollHeight, 200) + "px";
});
}, []);

useEffect(() => {
const handleGlobalKeyDown = (event: KeyboardEvent) => {
if (isEditableElement(event.target)) {
return;
}

if (matchesKeybind(event, KEYBINDS.FOCUS_INPUT_I)) {
event.preventDefault();
focusMessageInput();
return;
}

if (matchesKeybind(event, KEYBINDS.FOCUS_INPUT_A)) {
event.preventDefault();
focusMessageInput();
}
};

window.addEventListener("keydown", handleGlobalKeyDown);
return () => {
window.removeEventListener("keydown", handleGlobalKeyDown);
};
}, [focusMessageInput]);

// When entering editing mode, populate input with message content
useEffect(() => {
if (editingMessage) {
Expand Down Expand Up @@ -593,19 +634,19 @@ export const ChatInput: React.FC<ChatInputProps> = ({

// Handle cancel/escape
if (matchesKeybind(e, KEYBINDS.CANCEL)) {
const isFocused = document.activeElement === inputRef.current;
e.preventDefault();

// Priority 1: Cancel editing if in edit mode
if (editingMessage && onCancelEdit) {
onCancelEdit();
return;
} else if (canInterrupt) {
// Priority 2: Interrupt streaming if active
void window.api.workspace.sendMessage(workspaceId, "");
}

// Priority 2: Interrupt streaming if active
if (canInterrupt) {
// Send empty message to trigger interrupt
void window.api.workspace.sendMessage(workspaceId, "");
return;
if (isFocused) {
inputRef.current?.blur();
}

return;
Expand Down
6 changes: 6 additions & 0 deletions src/utils/ui/keybinds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ export const KEYBINDS = {
/** Cancel current action / Close modal / Interrupt streaming */
CANCEL: { key: "Escape" },

/** Focus chat input */
FOCUS_INPUT_I: { key: "i" },

/** Focus chat input (alternate) */
FOCUS_INPUT_A: { key: "a" },

/** Create new workspace for current project */
NEW_WORKSPACE: { key: "n", ctrl: true },

Expand Down