From 96bfd8e888774ee1315b096a76ba19c0f8cffe4b Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 10 Jul 2026 17:23:23 -0500 Subject: [PATCH] refac --- .../src/lib/components/GroupTabBar.svelte | 15 ++++++------ .../lib/components/Settings/Keyboard.svelte | 2 ++ cptr/frontend/src/lib/i18n/locales/de.json | 2 ++ cptr/frontend/src/lib/i18n/locales/en.json | 2 ++ cptr/frontend/src/lib/i18n/locales/es.json | 2 ++ cptr/frontend/src/lib/i18n/locales/fr.json | 2 ++ cptr/frontend/src/lib/i18n/locales/ja.json | 2 ++ cptr/frontend/src/lib/i18n/locales/ko.json | 2 ++ cptr/frontend/src/lib/i18n/locales/pt-BR.json | 2 ++ cptr/frontend/src/lib/i18n/locales/ru.json | 2 ++ cptr/frontend/src/lib/i18n/locales/zh-CN.json | 2 ++ cptr/frontend/src/lib/i18n/locales/zh-TW.json | 2 ++ cptr/frontend/src/lib/stores/keybindings.ts | 8 +++++++ cptr/utils/browser/viewer.py | 24 +++++++++++++++++++ 14 files changed, 61 insertions(+), 8 deletions(-) diff --git a/cptr/frontend/src/lib/components/GroupTabBar.svelte b/cptr/frontend/src/lib/components/GroupTabBar.svelte index f64fe49..432b3a8 100644 --- a/cptr/frontend/src/lib/components/GroupTabBar.svelte +++ b/cptr/frontend/src/lib/components/GroupTabBar.svelte @@ -33,11 +33,11 @@ import { TAB_DRAG_MIME } from '$lib/constants'; interface Props { - group: EditorGroup; - canClose?: boolean; - isPrimary?: boolean; - onTabDragOver?: () => void; -} + group: EditorGroup; + canClose?: boolean; + isPrimary?: boolean; + onTabDragOver?: () => void; + } let { group, canClose = false, isPrimary = false, onTabDragOver }: Props = $props(); @@ -199,6 +199,7 @@ { label: $t('bar.newBrowser'), icon: 'browser', + shortcut: formatChord($keybindings.newBrowser), onclick: () => openBrowserTab(group.id) }, ...($voiceMemosEnabled @@ -308,9 +309,7 @@
= { newFile: 'New File', newTerminal: 'New Terminal', newChat: 'New Chat', + newBrowser: 'New Browser', closeTab: 'Close Tab', nextTab: 'Next Tab', prevTab: 'Previous Tab', @@ -67,6 +70,7 @@ export const DEFAULT_KEYBINDINGS: Record = { newFile: 'Cmd+N', newTerminal: 'Ctrl+`', newChat: 'Cmd+Shift+O', + newBrowser: 'Cmd+Shift+B', closeTab: 'Cmd+W', nextTab: 'Cmd+Shift+]', prevTab: 'Cmd+Shift+[', @@ -254,6 +258,10 @@ export function executeAction( openChatTab(); return true; + case 'newBrowser': + void openBrowserTab(); + return true; + case 'closeTab': { const group = get(activeGroup); if (!group) return false; diff --git a/cptr/utils/browser/viewer.py b/cptr/utils/browser/viewer.py index 4e7a601..bbb3c4d 100644 --- a/cptr/utils/browser/viewer.py +++ b/cptr/utils/browser/viewer.py @@ -45,6 +45,25 @@ def _target_key( return target, f"{target}{side}", virtual_key +def _editing_commands(key: str, modifiers: int, primary: bool) -> list[str]: + if not primary or modifiers & 1: + return [] + key = key.lower() + if key == "z": + return ["Redo" if modifiers & 8 else "Undo"] + if key == "y": + return ["Redo"] + command = { + "a": "SelectAll", + "b": "ToggleBold", + "c": "Copy", + "i": "ToggleItalic", + "u": "ToggleUnderline", + "x": "Cut", + }.get(key) + return [command] if command else [] + + def browser_name(path: str) -> str: name = Path(path).name.lower() if "brave" in name: @@ -617,6 +636,11 @@ class ChromeViewerManager: "isKeypad": bool(data.get("is_keypad", False)), "windowsVirtualKeyCode": virtual_key, } + commands = _editing_commands( + key, int(data.get("modifiers", 0)), bool(data.get("primary_modifier", False)) + ) + if event == "keyDown" and commands: + params["commands"] = commands await viewer.target_cdp.send( "Input.dispatchKeyEvent", params,