From 182fd9bb62837847f2112546edb6c9f9d6119ab4 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Tue, 10 Nov 2026 19:18:46 +0000 Subject: [PATCH] Pad chat bar text buttons 12 px and add Alt+Y for floating chats Model, mode and thinking buttons carry 12 px horizontal padding, replacing the pill inset from 440995e3. Alt+Y (Option+Y by key position) toggles the floating chats, like Alt+T for the terminal. --- .../conversation/chat_bar_control_style.dart | 7 ++- .../conversation/chat_effort_control.dart | 2 +- .../chat/conversation/chat_mode_control.dart | 2 +- .../chat/conversation/chat_model_control.dart | 2 +- .../chat/conversation/chat_thread_header.dart | 19 +++--- .../chat/workspace/chat_float_shortcut.dart | 28 +++++---- .../conversation/chat_thread_header_test.dart | 35 ++++++----- .../workspace/chat_float_shortcut_test.dart | 58 +++++++++++++++++++ 8 files changed, 111 insertions(+), 42 deletions(-) diff --git a/app/lib/features/chat/conversation/chat_bar_control_style.dart b/app/lib/features/chat/conversation/chat_bar_control_style.dart index ca00650a..bc681626 100644 --- a/app/lib/features/chat/conversation/chat_bar_control_style.dart +++ b/app/lib/features/chat/conversation/chat_bar_control_style.dart @@ -16,10 +16,15 @@ ButtonStyle chatBarTextButtonStyle( foregroundColor: ChatBarTintScope.foregroundOf(context) ?? Theme.of(context).colorScheme.onSurfaceVariant, - padding: compact ? null : EdgeInsets.zero, + // The same 12 px each side as an icon button's glyph inside its 48 px + // target, so text sits off its hover/press shape as it does top and bottom. + padding: compact ? null : chatBarButtonPadding, minimumSize: compact ? null : const Size.square(kMinInteractiveDimension), ); +/// Horizontal padding inside the bar's text buttons (model, mode). +const EdgeInsets chatBarButtonPadding = EdgeInsets.symmetric(horizontal: 12); + /// Cupertino: [content] (a [CupertinoButton]'s child) in the label colour /// instead of the button's tint. Widget chatBarCupertinoContent(BuildContext context, Widget content) { diff --git a/app/lib/features/chat/conversation/chat_effort_control.dart b/app/lib/features/chat/conversation/chat_effort_control.dart index 08cecfc8..de429570 100644 --- a/app/lib/features/chat/conversation/chat_effort_control.dart +++ b/app/lib/features/chat/conversation/chat_effort_control.dart @@ -151,7 +151,7 @@ class _ChatEffortControlState extends State { child: ExcludeSemantics( child: CupertinoButton( key: key, - padding: const EdgeInsets.symmetric(horizontal: 8), + padding: chatBarButtonPadding, onPressed: _openSheet, child: chatBarCupertinoContent(context, content), ), diff --git a/app/lib/features/chat/conversation/chat_mode_control.dart b/app/lib/features/chat/conversation/chat_mode_control.dart index 6c87bdaa..efd82725 100644 --- a/app/lib/features/chat/conversation/chat_mode_control.dart +++ b/app/lib/features/chat/conversation/chat_mode_control.dart @@ -126,7 +126,7 @@ class _ChatModeControlState extends State { child: ExcludeSemantics( child: CupertinoButton( key: key, - padding: EdgeInsets.zero, + padding: chatBarButtonPadding, onPressed: _open, child: chatBarCupertinoContent(context, content), ), diff --git a/app/lib/features/chat/conversation/chat_model_control.dart b/app/lib/features/chat/conversation/chat_model_control.dart index 5f7d1915..af00a81d 100644 --- a/app/lib/features/chat/conversation/chat_model_control.dart +++ b/app/lib/features/chat/conversation/chat_model_control.dart @@ -139,7 +139,7 @@ class _ChatModelControlState extends State { child: ExcludeSemantics( child: CupertinoButton( key: key, - padding: EdgeInsets.zero, + padding: chatBarButtonPadding, onPressed: _open, child: chatBarCupertinoContent(context, content), ), diff --git a/app/lib/features/chat/conversation/chat_thread_header.dart b/app/lib/features/chat/conversation/chat_thread_header.dart index 68f2aadf..709c9396 100644 --- a/app/lib/features/chat/conversation/chat_thread_header.dart +++ b/app/lib/features/chat/conversation/chat_thread_header.dart @@ -155,19 +155,14 @@ class _ControlIsland extends StatelessWidget { final List children; final double gap; - // With a gap (desktop) the buttons carry no horizontal padding of their - // own, so the island keeps the text off its pill's rounded ends. @override - Widget build(BuildContext context) => Padding( - padding: EdgeInsets.symmetric(horizontal: gap * 1.5), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - for (final (index, child) in children.indexed) ...[ - if (index > 0) SizedBox(width: gap), - Flexible(child: child), - ], + Widget build(BuildContext context) => Row( + mainAxisSize: MainAxisSize.min, + children: [ + for (final (index, child) in children.indexed) ...[ + if (index > 0) SizedBox(width: gap), + Flexible(child: child), ], - ), + ], ); } diff --git a/app/lib/features/chat/workspace/chat_float_shortcut.dart b/app/lib/features/chat/workspace/chat_float_shortcut.dart index aec2738d..19ec4f17 100644 --- a/app/lib/features/chat/workspace/chat_float_shortcut.dart +++ b/app/lib/features/chat/workspace/chat_float_shortcut.dart @@ -3,12 +3,14 @@ import 'package:flutter/services.dart'; import '../../../ui/input/keyboard_owner.dart'; -/// Whether [event] shows or hides the floating chat: Ctrl+Y, and Cmd+Y on -/// Apple platforms. It is a global key handler like the terminal's toggle, -/// so it works while a composer or the terminal has the keyboard; a plain Y -/// (or Shift+Y, Alt+Y) always types. On Apple platforms Ctrl+Y inside a -/// terminal is left to the shell (yank), since Cmd+Y is there; elsewhere -/// Ctrl+Y is the chord, so it takes priority over the shell's yank. +/// Whether [event] shows or hides the floating chats: Alt+Y (Option+Y), +/// Ctrl+Y, and Cmd+Y on Apple platforms, matching the terminal's Alt+T. It is +/// a global key handler like the terminal's toggle, so it works while a +/// composer or the terminal has the keyboard; a plain Y (or Shift+Y) always +/// types. Alt+Y is always the chord, as Alt+T is for the terminal. On Apple +/// platforms Ctrl+Y inside a terminal is left to the shell (yank), since Cmd+Y +/// is there; elsewhere Ctrl+Y is the chord, so it takes priority over the +/// shell's yank. /// /// A held chord's repeats match too (and are swallowed); only its first /// press toggles. @@ -17,14 +19,16 @@ bool chatFloatShortcut( HardwareKeyboard keyboard, { TargetPlatform? platform, }) { - if (event is KeyUpEvent || - event.logicalKey != LogicalKeyboardKey.keyY || - keyboard.isShiftPressed || - keyboard.isAltPressed) { - return false; - } + final alt = keyboard.isAltPressed; + // Option+Y types a symbol (¥) on a Mac, so with Alt the key is also + // matched by its position. + final y = + event.logicalKey == LogicalKeyboardKey.keyY || + alt && event.physicalKey == PhysicalKeyboardKey.keyY; + if (event is KeyUpEvent || !y || keyboard.isShiftPressed) return false; final control = keyboard.isControlPressed; final meta = keyboard.isMetaPressed; + if (alt) return !control && !meta; if (control == meta) return false; if (!_apple(platform ?? defaultTargetPlatform)) return control; return meta || !primaryFocusIsTypingSurface(); diff --git a/app/test/features/chat/conversation/chat_thread_header_test.dart b/app/test/features/chat/conversation/chat_thread_header_test.dart index a6526100..adf9966a 100644 --- a/app/test/features/chat/conversation/chat_thread_header_test.dart +++ b/app/test/features/chat/conversation/chat_thread_header_test.dart @@ -1,6 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_bar_control_style.dart'; import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart'; import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart'; import 'package:pipelines_app/features/chat/conversation/chat_sidebar_controls.dart'; @@ -80,20 +81,7 @@ void main() { tester.getTopRight(find.byKey(Key(left))).dx; expect(gap('header-control-1', 'header-control-2'), 8); - // The model/mode island keeps its text 12 px off its pill's ends. - final island = tester.getRect( - find.byKey(const Key('chat-model-permission-island')), - ); - expect( - tester.getTopLeft(find.byKey(const Key('header-control-1'))).dx - - island.left, - 12, - ); - expect( - island.right - - tester.getTopRight(find.byKey(const Key('header-control-2'))).dx, - 12, - ); + expect(gap('header-control-2', 'header-action-1'), 8); expect(gap('header-action-1', 'header-action-2'), 8); expect( tester.getTopLeft(find.byKey(segmentedMoreKey).first).dx - @@ -396,4 +384,23 @@ void main() { ); expect(tester.takeException(), isNull); }); + + testWidgets('wide bar text buttons keep their text off the shape ends', ( + tester, + ) async { + late ButtonStyle wide; + await tester.pumpWidget( + MaterialApp( + home: Builder( + builder: (context) { + wide = chatBarTextButtonStyle(context); + return const SizedBox(); + }, + ), + ), + ); + expect(wide.padding?.resolve({}), chatBarButtonPadding); + expect(chatBarButtonPadding.left, 12); + expect(chatBarButtonPadding.right, 12); + }); } diff --git a/app/test/features/chat/workspace/chat_float_shortcut_test.dart b/app/test/features/chat/workspace/chat_float_shortcut_test.dart index cd48312d..1864350b 100644 --- a/app/test/features/chat/workspace/chat_float_shortcut_test.dart +++ b/app/test/features/chat/workspace/chat_float_shortcut_test.dart @@ -225,4 +225,62 @@ void main() { await _chord(tester, LogicalKeyboardKey.controlLeft); expect(h.controller.floatShown, isTrue); }); + + testWidgets('Alt+Y floats, hides and shows like Ctrl+Y, also from a ' + 'terminal', (tester) async { + final h = await pump(tester); + tester.state<_PaneState>(_pane('b')).focus.requestFocus(); + await tester.pump(); + await _chord(tester, LogicalKeyboardKey.altLeft); + expect(h.controller.floatingPanes.firstOrNull?.sessionId, 'b'); + expect(h.controller.floatShown, isTrue); + h.typing.requestFocus(); + await tester.pump(); + h.typed.clear(); + await _chord(tester, LogicalKeyboardKey.altLeft); + expect(h.controller.floatShown, isFalse); + expect(h.typed, isEmpty); + }); + + test('Option+Y matches by key position; extra modifiers do not', () { + // On a Mac, Option+Y produces ¥: the logical key is not Y. + const yen = KeyDownEvent( + physicalKey: PhysicalKeyboardKey.keyY, + logicalKey: LogicalKeyboardKey(0x00a5), + character: '¥', + timeStamp: Duration.zero, + ); + final keyboard = _FakeKeyboard({LogicalKeyboardKey.altLeft}); + expect( + chatFloatShortcut(yen, keyboard, platform: TargetPlatform.macOS), + isTrue, + ); + const y = KeyDownEvent( + physicalKey: PhysicalKeyboardKey.keyY, + logicalKey: LogicalKeyboardKey.keyY, + timeStamp: Duration.zero, + ); + for (final extra in [ + LogicalKeyboardKey.controlLeft, + LogicalKeyboardKey.metaLeft, + LogicalKeyboardKey.shiftLeft, + ]) { + expect( + chatFloatShortcut( + y, + _FakeKeyboard({LogicalKeyboardKey.altLeft, extra}), + ), + isFalse, + reason: '$extra', + ); + } + expect(chatFloatShortcut(y, _FakeKeyboard({})), isFalse); + }); +} + +class _FakeKeyboard extends HardwareKeyboard { + _FakeKeyboard(this.pressed); + final Set pressed; + @override + bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key); }