Skip to content

Commit b72f5cc

Browse files
authored
feat: Clicking anywhere in chat pane should focus chat box (#630)
1 parent 98a99a7 commit b72f5cc

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

apps/twig/src/renderer/features/sessions/components/SessionView.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,13 +284,34 @@ export function SessionView({
284284
editorRef.current?.focus();
285285
}, []);
286286

287+
// Click anywhere in chat pane to focus editor (except interactive elements)
288+
const handlePaneClick = useCallback((e: React.MouseEvent) => {
289+
const target = e.target as HTMLElement;
290+
291+
// Check if click was on or inside an interactive element
292+
const interactiveSelector =
293+
'button, a, input, textarea, select, [role="button"], [role="link"], [contenteditable="true"], [data-interactive]';
294+
if (target.closest(interactiveSelector)) {
295+
return;
296+
}
297+
298+
// Don't focus if user is selecting text
299+
const selection = window.getSelection();
300+
if (selection && selection.toString().length > 0) {
301+
return;
302+
}
303+
304+
editorRef.current?.focus();
305+
}, []);
306+
287307
return (
288308
<ContextMenu.Root>
289309
<ContextMenu.Trigger>
290310
<Flex
291311
direction="column"
292312
height="100%"
293313
className="relative bg-gray-1"
314+
onClick={handlePaneClick}
294315
onDragEnter={handleDragEnter}
295316
onDragLeave={handleDragLeave}
296317
onDragOver={handleDragOver}

0 commit comments

Comments
 (0)