From bbd079c052d23a77844e26b8a1bf085c8613a2f5 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Thu, 19 Jun 2025 22:06:23 +0200 Subject: [PATCH] Fix terminal keyboard event handling to allow browser shortcuts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The terminal component was aggressively preventing default on ALL keyboard events, blocking important browser shortcuts like F12 (DevTools), Ctrl+C/Ctrl+V (copy/paste), and Ctrl+F (find). Updated the keyboard handler to: - Allow F12 and Ctrl+Shift+I/Cmd+Alt+I for DevTools - Allow common browser shortcuts like Ctrl+A, Ctrl+F, Ctrl+R, etc. - Allow Alt+Tab and Cmd+Tab for window switching - Only preventDefault on keys that are actually handled by the terminal This preserves terminal functionality while restoring essential browser shortcuts. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- web/src/client/components/session-view.ts | 41 ++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/web/src/client/components/session-view.ts b/web/src/client/components/session-view.ts index b0e23e68..8bd19bf8 100644 --- a/web/src/client/components/session-view.ts +++ b/web/src/client/components/session-view.ts @@ -40,6 +40,45 @@ export class SessionView extends LitElement { private keyboardHandler = (e: KeyboardEvent) => { if (!this.session) return; + // Allow important browser shortcuts to pass through + const isMacOS = navigator.platform.toLowerCase().includes('mac'); + + // Allow F12 and Ctrl+Shift+I (DevTools) + if ( + e.key === 'F12' || + (!isMacOS && e.ctrlKey && e.shiftKey && e.key === 'I') || + (isMacOS && e.metaKey && e.altKey && e.key === 'I') + ) { + return; + } + + // Allow Ctrl+A (select all), Ctrl+F (find), Ctrl+R (refresh), etc. + if ( + !isMacOS && + e.ctrlKey && + !e.shiftKey && + ['a', 'f', 'r', 'l', 't', 'w', 'n'].includes(e.key.toLowerCase()) + ) { + return; + } + + // Allow Cmd+A, Cmd+F, Cmd+R, etc. on macOS + if ( + isMacOS && + e.metaKey && + !e.shiftKey && + !e.altKey && + ['a', 'f', 'r', 'l', 't', 'w', 'n'].includes(e.key.toLowerCase()) + ) { + return; + } + + // Allow Alt+Tab, Cmd+Tab (window switching) + if ((e.altKey || e.metaKey) && e.key === 'Tab') { + return; + } + + // Only prevent default for keys we're actually going to handle e.preventDefault(); e.stopPropagation(); @@ -450,7 +489,7 @@ export class SessionView extends LitElement { const response = await fetch(`/api/sessions/${this.session.id}/resize`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ width: cols, height: rows }), + body: JSON.stringify({ cols: cols, rows: rows }), }); if (response.ok) {