Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

Address review on Console select-all (CHOO-4120)

Simon Flackb11467f82c9e
diff --git a/console/apps/switch-console-desktop/src/main/app/menu.ts b/console/apps/switch-console-desktop/src/main/app/menu.ts
index e03cc19cf..3583f8d0d 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, webContents } from 'electron';
+import { app, clipboard, Menu, shell } from 'electron';
import { events } from '@main/lib/events';
import { PRODUCT_NAME } from '@shared/app-identity';
import {
@@ -6,7 +6,6 @@ import {
menuOpenSettingsChannel,
menuQuitRequestedChannel,
menuRedoChannel,
- menuSelectAllChannel,
menuUndoChannel,
} from '@shared/events/appEvents';
import {
@@ -14,6 +13,7 @@ import {
SWITCH_CONSOLE_ISSUES_NEW_URL,
SWITCH_CONSOLE_RELEASES_URL,
} from '@shared/urls';
+import { selectAll } from './select-all';
import { getMainWindow } from './window';
function copyVersionInfo(): void {
@@ -25,21 +25,6 @@ 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()) {
diff --git a/console/apps/switch-console-desktop/src/main/app/select-all.test.ts b/console/apps/switch-console-desktop/src/main/app/select-all.test.ts
new file mode 100644
index 000000000..2e7f29e6c
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/main/app/select-all.test.ts
@@ -0,0 +1,73 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { menuSelectAllChannel } from '@shared/events/appEvents';
+
+const mocks = vi.hoisted(() => ({
+ getFocusedWebContents: vi.fn(),
+ getMainWindow: vi.fn(),
+ emit: vi.fn(),
+}));
+
+vi.mock('electron', () => ({
+ webContents: { getFocusedWebContents: mocks.getFocusedWebContents },
+}));
+vi.mock('@main/app/window', () => ({ getMainWindow: mocks.getMainWindow }));
+vi.mock('@main/lib/events', () => ({ events: { emit: mocks.emit } }));
+
+const { selectAll } = await import('./select-all');
+
+function fakeContents(destroyed = false) {
+ return { selectAll: vi.fn(), isDestroyed: () => destroyed };
+}
+
+function fakeWindow(destroyed = false) {
+ return { isDestroyed: () => destroyed, webContents: fakeContents(destroyed) };
+}
+
+describe('Edit > Select All routing (CHOO-4120)', () => {
+ beforeEach(() => {
+ vi.clearAllMocks();
+ });
+
+ it('forwards to the renderer when the main window is focused', () => {
+ const win = fakeWindow();
+ mocks.getMainWindow.mockReturnValue(win);
+ mocks.getFocusedWebContents.mockReturnValue(win.webContents);
+ selectAll();
+ expect(mocks.emit).toHaveBeenCalledWith(menuSelectAllChannel, undefined);
+ expect(win.webContents.selectAll).not.toHaveBeenCalled();
+ });
+
+ it('forwards to the renderer when nothing is focused', () => {
+ mocks.getMainWindow.mockReturnValue(fakeWindow());
+ mocks.getFocusedWebContents.mockReturnValue(null);
+ selectAll();
+ expect(mocks.emit).toHaveBeenCalledWith(menuSelectAllChannel, undefined);
+ });
+
+ it('lets other web contents (DevTools, the room webview) select all natively', () => {
+ const win = fakeWindow();
+ const other = fakeContents();
+ mocks.getMainWindow.mockReturnValue(win);
+ mocks.getFocusedWebContents.mockReturnValue(other);
+ selectAll();
+ expect(other.selectAll).toHaveBeenCalledOnce();
+ expect(win.webContents.selectAll).not.toHaveBeenCalled();
+ expect(mocks.emit).not.toHaveBeenCalled();
+ });
+
+ it('does nothing when the main window is destroyed', () => {
+ const win = fakeWindow(true);
+ mocks.getMainWindow.mockReturnValue(win);
+ mocks.getFocusedWebContents.mockReturnValue(null);
+ selectAll();
+ expect(mocks.emit).not.toHaveBeenCalled();
+ expect(win.webContents.selectAll).not.toHaveBeenCalled();
+ });
+
+ it('does nothing when there is no main window and nothing focused', () => {
+ mocks.getMainWindow.mockReturnValue(null);
+ mocks.getFocusedWebContents.mockReturnValue(null);
+ selectAll();
+ expect(mocks.emit).not.toHaveBeenCalled();
+ });
+});
diff --git a/console/apps/switch-console-desktop/src/main/app/select-all.ts b/console/apps/switch-console-desktop/src/main/app/select-all.ts
new file mode 100644
index 000000000..b92d4873e
--- /dev/null
+++ b/console/apps/switch-console-desktop/src/main/app/select-all.ts
@@ -0,0 +1,21 @@
+import { webContents } from 'electron';
+import { getMainWindow } from '@main/app/window';
+import { events } from '@main/lib/events';
+import { menuSelectAllChannel } from '@shared/events/appEvents';
+
+/**
+ * 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). Other web contents (DevTools, the embedded room) keep
+ * Chromium's select-all.
+ */
+export function selectAll(): void {
+ const focused = webContents.getFocusedWebContents();
+ const win = getMainWindow();
+ const mainContents = win && !win.isDestroyed() ? win.webContents : null;
+ if (mainContents && (!focused || focused === mainContents)) {
+ events.emit(menuSelectAllChannel, undefined);
+ return;
+ }
+ if (focused && !focused.isDestroyed()) focused.selectAll();
+}
diff --git a/console/apps/switch-console-desktop/src/renderer/lib/select-all.ts b/console/apps/switch-console-desktop/src/renderer/lib/select-all.ts
index 2212d534a..18c2c7f4d 100644
--- a/console/apps/switch-console-desktop/src/renderer/lib/select-all.ts
+++ b/console/apps/switch-console-desktop/src/renderer/lib/select-all.ts
@@ -16,15 +16,20 @@ export function isSelectAllTarget(el: Element | null): boolean {
return el instanceof HTMLElement && el.isContentEditable;
}
+/** Monaco handles Cmd/Ctrl+A itself; selecting its hidden textarea would desync it. */
+function isInMonaco(el: Element | null): boolean {
+ return el?.closest('.monaco-editor') != null;
+}
+
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'
- );
+ if (!(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey) return false;
+ const key = event.key.toLowerCase();
+ if (key === 'a') return true;
+ // Chromium's own Ctrl+A goes by the physical key, so on Cyrillic, Greek,
+ // Hebrew or Arabic layouts (physical A types ф, α, ...) claim KeyA too. Only
+ // when the typed key is not a Latin letter: on AZERTY the KeyA position types
+ // Q, and claiming it would swallow Ctrl/Cmd+Q (Quit).
+ return event.code === 'KeyA' && !/^[a-z]$/.test(key);
}
/**
@@ -33,7 +38,7 @@ function isSelectAllShortcut(event: KeyboardEvent): boolean {
*/
export function selectAllInFocusedField(doc: Document = document): boolean {
const el = doc.activeElement;
- if (!isSelectAllTarget(el)) return false;
+ if (!isSelectAllTarget(el) || isInMonaco(el)) return false;
if (el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement) {
el.select();
} 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.tsx
index 0d0892fdb..4cd447af5 100644
--- 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.tsx
@@ -91,6 +91,41 @@ it('Ctrl+Q on AZERTY (physical KeyA) is left alone so Quit still works', () => {
expect(event.defaultPrevented).toBe(false);
});
+function ctrlKeyDown(target: Element, key: string, code: string): KeyboardEvent {
+ const event = new KeyboardEvent('keydown', {
+ key,
+ code,
+ ctrlKey: true,
+ bubbles: true,
+ cancelable: true,
+ });
+ target.dispatchEvent(event);
+ return event;
+}
+
+it('Ctrl+A on a Cyrillic layout (physical KeyA types ф) is claimed on a button', () => {
+ mount(CHROME);
+ const button = container.querySelector('button')!;
+ button.focus();
+ expect(ctrlKeyDown(button, 'ф', 'KeyA').defaultPrevented).toBe(true);
+});
+
+it('Ctrl+A on a Cyrillic layout is left to a focused text field', () => {
+ mount(CHROME + FIELDS);
+ const input = container.querySelector('input')!;
+ input.focus();
+ expect(ctrlKeyDown(input, 'ф', 'KeyA').defaultPrevented).toBe(false);
+});
+
+it('menu Select All leaves Monaco alone', () => {
+ mount('<div class="monaco-editor"><textarea>monaco hidden input</textarea></div>');
+ const textarea = container.querySelector('textarea')!;
+ textarea.focus();
+ textarea.setSelectionRange(3, 3);
+ menuSelectAll();
+ expect([textarea.selectionStart, textarea.selectionEnd]).toEqual([3, 3]);
+});
+
it('menu Select All on a focused button selects nothing', () => {
mount(CHROME);
container.querySelector('button')!.focus();