From c7e57973a0d33e0fc921c437a0ad54495ddd5269 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 5 Nov 2026 13:59:38 +0000 Subject: [PATCH] Support Command conversation shortcuts in Mac browsers --- app/lib/shell/adaptive_shell.dart | 5 +- app/lib/shell/shell_list_shortcuts.dart | 25 ++++++---- .../mac-browser-conversation-shortcuts.md | 10 ++++ .../chat/chat_list_shortcuts_test.dart | 38 +++++++++++++++ app/test/shell/list_shortcuts_test.dart | 45 ++++++++++++++++++ app/tool/install_web_build.py | 47 +++++++++++++++++++ 6 files changed, 161 insertions(+), 9 deletions(-) create mode 100644 app/notes/mac-browser-conversation-shortcuts.md create mode 100644 app/tool/install_web_build.py diff --git a/app/lib/shell/adaptive_shell.dart b/app/lib/shell/adaptive_shell.dart index 426ddf0c..86a5bef5 100644 --- a/app/lib/shell/adaptive_shell.dart +++ b/app/lib/shell/adaptive_shell.dart @@ -279,7 +279,10 @@ class _AdaptiveShellState extends State { /// Ctrl+1…Ctrl+9 open the Nth item of the open tab's list the same way, in /// the list's on-screen order; a page (Settings) has no list. bool _handleDestinationKeyEvent(KeyEvent event) { - final listIndex = shellListShortcutIndex(event, HardwareKeyboard.instance); + final listIndex = shellListShortcutIndex( + event, + HardwareKeyboard.instance, + ); if (listIndex != null) { if (!shellTabDestinations.contains(_selected)) return false; return _bar.lists.open(_selected, listIndex); diff --git a/app/lib/shell/shell_list_shortcuts.dart b/app/lib/shell/shell_list_shortcuts.dart index 680f29c5..49fc21e0 100644 --- a/app/lib/shell/shell_list_shortcuts.dart +++ b/app/lib/shell/shell_list_shortcuts.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter/widgets.dart'; @@ -5,7 +6,8 @@ import 'destination.dart'; import 'shell_bar.dart'; /// Opens the Nth item of a tab's list: what each tab's list screen published -/// for Ctrl+1…Ctrl+9. One opener per tab; the latest mounted list wins. +/// for Ctrl+1…Ctrl+9 (also Command on macOS). One opener per tab; +/// the latest mounted list wins. class ShellListShortcuts { final Map _openers = {}; @@ -25,15 +27,22 @@ class ShellListShortcuts { } } -/// The 0-based list index a Ctrl+1…Ctrl+9 key event names, or null for any -/// other event. Shift, Alt and Meta must be up, so system and browser chords -/// built on the digits are left alone. -int? shellListShortcutIndex(KeyEvent event, HardwareKeyboard keyboard) { +/// The 0-based list index named by Ctrl+1…9, or Command+1…9 on macOS. +/// Extra modifiers and non-digit events pass through. +int? shellListShortcutIndex( + KeyEvent event, + HardwareKeyboard keyboard, { + TargetPlatform? platform, +}) { + final control = keyboard.isControlPressed && !keyboard.isMetaPressed; + final command = + (platform ?? defaultTargetPlatform) == TargetPlatform.macOS && + keyboard.isMetaPressed && + !keyboard.isControlPressed; if (event is! KeyDownEvent || - !keyboard.isControlPressed || + !(control || command) || keyboard.isShiftPressed || - keyboard.isAltPressed || - keyboard.isMetaPressed) { + keyboard.isAltPressed) { return null; } final index = _digits.indexOf(event.logicalKey); diff --git a/app/notes/mac-browser-conversation-shortcuts.md b/app/notes/mac-browser-conversation-shortcuts.md new file mode 100644 index 00000000..8036ed60 --- /dev/null +++ b/app/notes/mac-browser-conversation-shortcuts.md @@ -0,0 +1,10 @@ +# Mac browser conversation shortcuts + +Command+1…9 now uses the same shell list opener as Ctrl+1…9 on macOS. It uses +the actual host platform, independently of the Material web theme. Extra +modifiers pass through. Focused shortcut tests pass (13); focused analysis and +web release build pass. The installed web bundle was published and its served +main.dart.js hash matched the candidate. No server restart was required. + +`tool/install_web_build.py` installs an already-built `build/web-next` into the +local installation root, keeps a rollback, and preserves download directories. diff --git a/app/test/features/chat/chat_list_shortcuts_test.dart b/app/test/features/chat/chat_list_shortcuts_test.dart index 98216155..b741873e 100644 --- a/app/test/features/chat/chat_list_shortcuts_test.dart +++ b/app/test/features/chat/chat_list_shortcuts_test.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/core/api_gateway.dart'; @@ -136,6 +137,43 @@ void main() { await tester.pumpWidget(const SizedBox.shrink()); }); + testWidgets('macOS Command+number opens and focuses the Nth conversation', ( + tester, + ) async { + debugDefaultTargetPlatformOverride = TargetPlatform.macOS; + addTearDown(() => debugDefaultTargetPlatformOverride = null); + await _pumpShell( + tester, + const Size(1280, 800), + // Browser presentation stays Material while shortcuts use the real OS. + platform: TargetPlatform.android, + ); + Future command(LogicalKeyboardKey digit) async { + await tester.sendKeyDownEvent(LogicalKeyboardKey.metaLeft); + await tester.sendKeyEvent(digit); + await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft); + await tester.pumpAndSettle(); + } + + await command(LogicalKeyboardKey.digit1); + expect(_thread('a'), findsOneWidget); + expect(_composerFocused(tester, 'a'), isTrue); + tester.testTextInput.enterText('keep this draft'); + await tester.pump(); + await command(LogicalKeyboardKey.digit3); + expect(_thread('r'), findsOneWidget); + expect(_composerFocused(tester, 'r'), isTrue); + await command(LogicalKeyboardKey.digit9); + expect(_thread('r'), findsOneWidget); + await command(LogicalKeyboardKey.digit1); + expect(_composerText(tester, 'a'), 'keep this draft'); + await _ctrl(tester, LogicalKeyboardKey.digit2); + expect(_thread('z'), findsOneWidget); + expect(_composerFocused(tester, 'z'), isTrue); + await tester.pumpWidget(const SizedBox.shrink()); + debugDefaultTargetPlatformOverride = null; + }); + testWidgets('Ctrl+N puts the keyboard in the opened chat\'s composer', ( tester, ) async { diff --git a/app/test/shell/list_shortcuts_test.dart b/app/test/shell/list_shortcuts_test.dart index e2f6072f..954665a3 100644 --- a/app/test/shell/list_shortcuts_test.dart +++ b/app/test/shell/list_shortcuts_test.dart @@ -6,6 +6,51 @@ import 'package:pipelines_app/shell/destination.dart'; import 'package:pipelines_app/shell/shell_list_shortcuts.dart'; void main() { + for (final platform in [TargetPlatform.macOS, TargetPlatform.windows]) { + testWidgets('Command digits and extra modifiers on $platform', ( + tester, + ) async { + final results = []; + bool handler(KeyEvent event) { + if (event is KeyDownEvent && + event.logicalKey == LogicalKeyboardKey.digit2) { + results.add( + shellListShortcutIndex( + event, + HardwareKeyboard.instance, + platform: platform, + ), + ); + } + return false; + } + + HardwareKeyboard.instance.addHandler(handler); + addTearDown(() => HardwareKeyboard.instance.removeHandler(handler)); + Future press(List modifiers) async { + for (final key in modifiers) { + await tester.sendKeyDownEvent(key); + } + await tester.sendKeyEvent(LogicalKeyboardKey.digit2); + for (final key in modifiers.reversed) { + await tester.sendKeyUpEvent(key); + } + } + + await press([LogicalKeyboardKey.metaLeft]); + await press([LogicalKeyboardKey.metaRight]); + await press([LogicalKeyboardKey.controlLeft]); + await press([LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.shiftLeft]); + await press([LogicalKeyboardKey.metaLeft, LogicalKeyboardKey.altLeft]); + await press([ + LogicalKeyboardKey.metaLeft, + LogicalKeyboardKey.controlLeft, + ]); + final commandIndex = platform == TargetPlatform.macOS ? 1 : null; + expect(results, [commandIndex, commandIndex, 1, null, null, null]); + }); + } + testWidgets('Ctrl+1…9 reach only the open tab\'s list; other chords pass', ( tester, ) async { diff --git a/app/tool/install_web_build.py b/app/tool/install_web_build.py new file mode 100644 index 00000000..92d5ebb6 --- /dev/null +++ b/app/tool/install_web_build.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +"""Publish the already-built web bundle to the local Pipelines installation.""" +import hashlib +import json +from pathlib import Path +import shutil +import sys +import time + + +def main(): + source = Path(__file__).resolve().parents[1] / "build/web-next" + if not all((source / name).is_file() for name in + ("index.html", "main.dart.js", "flutter_bootstrap.js")): + raise ValueError("No complete web build at app/build/web-next") + manifest = Path.home() / ".local/share/pipelines/pipelines-install.json" + target = Path(json.loads(manifest.read_text())["web"]["root"]) + if not target.is_dir(): + raise ValueError(f"Installed web directory is missing: {target}") + stamp = str(time.time_ns()) + staging = target.with_name(target.name + ".next-" + stamp) + rollback = target.with_name(target.name + ".before-web-update-" + stamp) + try: + shutil.copytree(source, staging) + # Preserve downloads when an older installation stores them in the root. + for name in ("updates", "downloads"): + if (target / name).is_dir() and not (staging / name).exists(): + shutil.copytree(target / name, staging / name) + target.rename(rollback) + try: + staging.rename(target) + except OSError: + rollback.rename(target) + raise + finally: + if staging.exists(): + shutil.rmtree(staging) + digest = hashlib.sha256((target / "main.dart.js").read_bytes()).hexdigest() + print(f"Published: {target}\nRollback: {rollback}\nJS SHA256: {digest}") + print("Reload Pipelines in your browser. No server restart is needed.") + + +if __name__ == "__main__": + try: + main() + except (ValueError, OSError, KeyError) as error: + sys.exit(str(error))