Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
Keep Console Cmd+A select-all inside the focused field (CHOO-4120)
Simon Flack61dad800db2c
diff --git a/console/apps/switch-console-desktop/src/main/app/menu.ts b/console/apps/switch-console-desktop/src/main/app/menu.tsindex 0e9221c57..e03cc19cf 100644--- a/console/apps/switch-console-desktop/src/main/app/menu.ts+++ b/console/apps/switch-console-desktop/src/main/app/menu.ts@@ -1,4 +1,4 @@-import { app, clipboard, Menu, shell } from 'electron';+import { app, clipboard, Menu, shell, webContents } from 'electron';import { events } from '@main/lib/events';import { PRODUCT_NAME } from '@shared/app-identity';import {@@ -6,6 +6,7 @@ import {menuOpenSettingsChannel,menuQuitRequestedChannel,menuRedoChannel,+ menuSelectAllChannel,menuUndoChannel,} from '@shared/events/appEvents';import {@@ -24,6 +25,21 @@ function copyVersionInfo(): void {clipboard.writeText(lines.join('\n'));}+/**+ * Edit > Select All. In the app's own window the renderer decides, so it acts+ * only inside the focused text field rather than selecting the whole window+ * (CHOO-4120). Embedded web pages keep Chromium's select-all.+ */+function selectAll(): void {+ const focused = webContents.getFocusedWebContents();+ const win = getMainWindow();+ if (win && !win.isDestroyed() && (!focused || focused === win.webContents)) {+ events.emit(menuSelectAllChannel, undefined);+ return;+ }+ focused?.selectAll();+}+function requestQuit(): void {const win = getMainWindow();if (!win || win.webContents.isLoading()) {@@ -125,7 +141,7 @@ export function setupApplicationMenu(): void {{ role: 'paste' as const },...(isMac ? [{ role: 'pasteAndMatchStyle' as const }] : []),{ role: 'delete' as const },- { role: 'selectAll' as const },+ { label: 'Select All', accelerator: 'CmdOrCtrl+A', click: selectAll },],},// View menudiff --git a/console/apps/switch-console-desktop/src/renderer/lib/select-all.ts b/console/apps/switch-console-desktop/src/renderer/lib/select-all.tsnew file mode 100644index 000000000..2212d534a--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/lib/select-all.ts@@ -0,0 +1,71 @@+import { events } from '@renderer/lib/ipc';+import { menuSelectAllChannel } from '@shared/events/appEvents';++/** Input types whose value is text the user can select. */+const TEXT_INPUT_TYPES = new Set(['text', 'search', 'url', 'tel', 'email', 'password', 'number']);++/**+ * Whether select-all has something of its own to act on in `el`: a text input,+ * a textarea or a contenteditable region. Everywhere else, select-all would+ * select every piece of text in the window, as on a web page (CHOO-4120).+ */+export function isSelectAllTarget(el: Element | null): boolean {+ if (!el) return false;+ if (el instanceof HTMLTextAreaElement) return true;+ if (el instanceof HTMLInputElement) return TEXT_INPUT_TYPES.has(el.type);+ return el instanceof HTMLElement && el.isContentEditable;+}++function isSelectAllShortcut(event: KeyboardEvent): boolean {+ // Match the character, not the physical key: on AZERTY the KeyA position types Q,+ // and claiming it would swallow Ctrl/Cmd+Q (Quit).+ return (+ (event.metaKey || event.ctrlKey) &&+ !event.altKey &&+ !event.shiftKey &&+ event.key.toLowerCase() === 'a'+ );+}++/**+ * Select all inside the focused field, and do nothing when focus is elsewhere.+ * Returns whether anything was selected.+ */+export function selectAllInFocusedField(doc: Document = document): boolean {+ const el = doc.activeElement;+ if (!isSelectAllTarget(el)) return false;+ if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {+ el.select();+ } else {+ // Inside a contenteditable host this selects that host's contents only.+ doc.execCommand('selectAll');+ }+ return true;+}++/**+ * Make Cmd+A / Ctrl+A behave like a desktop app: select-all acts only inside+ * the focused text field.+ *+ * Two paths reach a select-all. Chromium's own Ctrl+A (Windows, Linux) selects+ * the whole page when focus is not in a field, so the keydown is claimed there.+ * The Edit menu's Select All (Cmd+A on macOS, or a click on the menu item) is+ * forwarded here by the main process instead of running Chromium's page-wide+ * select-all.+ */+export function wireSelectAll(+ win: Window = window,+ onMenuSelectAll: (cb: () => void) => () => void = (cb) => events.on(menuSelectAllChannel, cb)+): () => void {+ const onKeyDown = (event: KeyboardEvent) => {+ if (!isSelectAllShortcut(event)) return;+ if (isSelectAllTarget(win.document.activeElement)) return;+ event.preventDefault();+ };+ win.addEventListener('keydown', onKeyDown, true);+ const unlisten = onMenuSelectAll(() => selectAllInFocusedField(win.document));+ return () => {+ win.removeEventListener('keydown', onKeyDown, true);+ unlisten();+ };+}diff --git a/console/apps/switch-console-desktop/src/renderer/main.tsx b/console/apps/switch-console-desktop/src/renderer/main.tsxindex 3b236206a..d0eff9e01 100644--- a/console/apps/switch-console-desktop/src/renderer/main.tsx+++ b/console/apps/switch-console-desktop/src/renderer/main.tsx@@ -12,6 +12,7 @@ import {import { wireExternalLinkRequests } from '@renderer/lib/external-link-requests';import { rpc } from '@renderer/lib/ipc';import { wireMouseNavigation } from '@renderer/lib/layout/mouse-navigation';+import { wireSelectAll } from '@renderer/lib/select-all';import { viewStateCache } from '@renderer/lib/stores/view-state-cache';import { log } from '@renderer/utils/logger';import { initSoundPlayer } from '@renderer/utils/soundPlayer';@@ -51,6 +52,7 @@ async function bootstrap() {setupAppCommandProvider();setupViewCommandProvider(views as unknown as ViewCommandProviders);wireMouseNavigation();+ wireSelectAll();if (sidebarResult) {appState.sidebar.restoreSnapshot(sidebarResult as Partial<SidebarSnapshot>);} else {diff --git a/console/apps/switch-console-desktop/src/renderer/tests/browser/select-all-guard.test.tsx b/console/apps/switch-console-desktop/src/renderer/tests/browser/select-all-guard.test.tsxnew file mode 100644index 000000000..0d0892fdb--- /dev/null+++ b/console/apps/switch-console-desktop/src/renderer/tests/browser/select-all-guard.test.tsx@@ -0,0 +1,114 @@+/**+ * Cmd+A / Ctrl+A selects inside the focused text field only, never the whole+ * window as on a web page (CHOO-4120).+ */+import { afterEach, beforeEach, expect, it } from 'vitest';+import { userEvent } from 'vitest/browser';+import { wireSelectAll } from '@renderer/lib/select-all';++let container: HTMLDivElement;+let unwire: () => void;+let menuSelectAll: () => void;++// App chrome only: Chromium's page-wide select-all is what this guards against.+const CHROME = '<p>Some app chrome text</p><button type="button">Click</button>';+const FIELDS = `+ <input type="text" value="input text" />+ <textarea>textarea text</textarea>+ <div contenteditable="true">editable text</div>`;++function mount(html: string): void {+ container.innerHTML = html;+}++beforeEach(() => {+ container = document.createElement('div');+ document.body.appendChild(container);+ unwire = wireSelectAll(window, (cb) => {+ menuSelectAll = cb;+ return () => {};+ });+});++afterEach(() => {+ unwire();+ container.remove();+ window.getSelection()?.removeAllRanges();+});++const selectedText = () => window.getSelection()?.toString() ?? '';+const pressSelectAll = () => userEvent.keyboard('{Control>}a{/Control}');++it('Ctrl+A on a focused button selects nothing', async () => {+ mount(CHROME);+ container.querySelector('button')!.focus();+ await pressSelectAll();+ expect(selectedText()).toBe('');+});++it('Ctrl+A with nothing focused selects nothing', async () => {+ mount(CHROME);+ (document.activeElement as HTMLElement | null)?.blur();+ await pressSelectAll();+ expect(selectedText()).toBe('');+});++it('Ctrl+A in a text input selects only its value', async () => {+ mount(CHROME + FIELDS);+ const input = container.querySelector('input')!;+ input.focus();+ await pressSelectAll();+ expect([input.selectionStart, input.selectionEnd]).toEqual([0, input.value.length]);+});++it('Ctrl+A in a textarea selects only its value', async () => {+ mount(CHROME + FIELDS);+ const textarea = container.querySelector('textarea')!;+ textarea.focus();+ await pressSelectAll();+ expect([textarea.selectionStart, textarea.selectionEnd]).toEqual([0, textarea.value.length]);+});++it('Ctrl+A in a contenteditable selects only its text', async () => {+ mount(CHROME + FIELDS);+ (container.querySelector('[contenteditable]') as HTMLElement).focus();+ await pressSelectAll();+ expect(selectedText()).toBe('editable text');+});++it('Ctrl+Q on AZERTY (physical KeyA) is left alone so Quit still works', () => {+ mount(CHROME);+ const button = container.querySelector('button')!;+ button.focus();+ const event = new KeyboardEvent('keydown', {+ key: 'q',+ code: 'KeyA',+ ctrlKey: true,+ bubbles: true,+ cancelable: true,+ });+ button.dispatchEvent(event);+ expect(event.defaultPrevented).toBe(false);+});++it('menu Select All on a focused button selects nothing', () => {+ mount(CHROME);+ container.querySelector('button')!.focus();+ menuSelectAll();+ expect(selectedText()).toBe('');+});++it('menu Select All in a text input selects only its value', () => {+ mount(CHROME + FIELDS);+ const input = container.querySelector('input')!;+ input.focus();+ menuSelectAll();+ expect([input.selectionStart, input.selectionEnd]).toEqual([0, input.value.length]);+});++it('menu Select All in a contenteditable selects only its text', () => {+ mount(CHROME + FIELDS);+ (container.querySelector('[contenteditable]') as HTMLElement).focus();+ menuSelectAll();+ expect(selectedText()).toBe('editable text');+});diff --git a/console/apps/switch-console-desktop/src/shared/events/appEvents.ts b/console/apps/switch-console-desktop/src/shared/events/appEvents.tsindex e87c577ed..1ec97b40e 100644--- a/console/apps/switch-console-desktop/src/shared/events/appEvents.ts+++ b/console/apps/switch-console-desktop/src/shared/events/appEvents.ts@@ -13,6 +13,8 @@ export const menuOpenSettingsChannel = defineEvent<void>('menu:open-settings');export const menuCheckForUpdatesChannel = defineEvent<void>('menu:check-for-updates');export const menuUndoChannel = defineEvent<void>('menu:undo');export const menuRedoChannel = defineEvent<void>('menu:redo');+/** Edit > Select All in the main window; the renderer selects inside the focused field only. */+export const menuSelectAllChannel = defineEvent<void>('menu:select-all');export const menuQuitRequestedChannel = defineEvent<void>('menu:quit-requested');export const externalLinkOpenRequestedChannel = defineEvent<{ url: string }>(