Merge branch 'bar-padding-alt-keys'

This commit is contained in:
2026-11-10 19:18:46 +00:00
8 changed files with 111 additions and 42 deletions
@@ -16,10 +16,15 @@ ButtonStyle chatBarTextButtonStyle(
foregroundColor: foregroundColor:
ChatBarTintScope.foregroundOf(context) ?? ChatBarTintScope.foregroundOf(context) ??
Theme.of(context).colorScheme.onSurfaceVariant, 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), 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 /// Cupertino: [content] (a [CupertinoButton]'s child) in the label colour
/// instead of the button's tint. /// instead of the button's tint.
Widget chatBarCupertinoContent(BuildContext context, Widget content) { Widget chatBarCupertinoContent(BuildContext context, Widget content) {
@@ -151,7 +151,7 @@ class _ChatEffortControlState extends State<ChatEffortControl> {
child: ExcludeSemantics( child: ExcludeSemantics(
child: CupertinoButton( child: CupertinoButton(
key: key, key: key,
padding: const EdgeInsets.symmetric(horizontal: 8), padding: chatBarButtonPadding,
onPressed: _openSheet, onPressed: _openSheet,
child: chatBarCupertinoContent(context, content), child: chatBarCupertinoContent(context, content),
), ),
@@ -126,7 +126,7 @@ class _ChatModeControlState extends State<ChatModeControl> {
child: ExcludeSemantics( child: ExcludeSemantics(
child: CupertinoButton( child: CupertinoButton(
key: key, key: key,
padding: EdgeInsets.zero, padding: chatBarButtonPadding,
onPressed: _open, onPressed: _open,
child: chatBarCupertinoContent(context, content), child: chatBarCupertinoContent(context, content),
), ),
@@ -139,7 +139,7 @@ class _ChatModelControlState extends State<ChatModelControl> {
child: ExcludeSemantics( child: ExcludeSemantics(
child: CupertinoButton( child: CupertinoButton(
key: key, key: key,
padding: EdgeInsets.zero, padding: chatBarButtonPadding,
onPressed: _open, onPressed: _open,
child: chatBarCupertinoContent(context, content), child: chatBarCupertinoContent(context, content),
), ),
@@ -155,19 +155,14 @@ class _ControlIsland extends StatelessWidget {
final List<Widget> children; final List<Widget> children;
final double gap; 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 @override
Widget build(BuildContext context) => Padding( Widget build(BuildContext context) => Row(
padding: EdgeInsets.symmetric(horizontal: gap * 1.5), mainAxisSize: MainAxisSize.min,
child: Row( children: [
mainAxisSize: MainAxisSize.min, for (final (index, child) in children.indexed) ...[
children: [ if (index > 0) SizedBox(width: gap),
for (final (index, child) in children.indexed) ...[ Flexible(child: child),
if (index > 0) SizedBox(width: gap),
Flexible(child: child),
],
], ],
), ],
); );
} }
@@ -3,12 +3,14 @@ import 'package:flutter/services.dart';
import '../../../ui/input/keyboard_owner.dart'; import '../../../ui/input/keyboard_owner.dart';
/// Whether [event] shows or hides the floating chat: Ctrl+Y, and Cmd+Y on /// Whether [event] shows or hides the floating chats: Alt+Y (Option+Y),
/// Apple platforms. It is a global key handler like the terminal's toggle, /// Ctrl+Y, and Cmd+Y on Apple platforms, matching the terminal's Alt+T. It is
/// so it works while a composer or the terminal has the keyboard; a plain Y /// a global key handler like the terminal's toggle, so it works while a
/// (or Shift+Y, Alt+Y) always types. On Apple platforms Ctrl+Y inside a /// composer or the terminal has the keyboard; a plain Y (or Shift+Y) always
/// terminal is left to the shell (yank), since Cmd+Y is there; elsewhere /// types. Alt+Y is always the chord, as Alt+T is for the terminal. On Apple
/// Ctrl+Y is the chord, so it takes priority over the shell's yank. /// 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 /// A held chord's repeats match too (and are swallowed); only its first
/// press toggles. /// press toggles.
@@ -17,14 +19,16 @@ bool chatFloatShortcut(
HardwareKeyboard keyboard, { HardwareKeyboard keyboard, {
TargetPlatform? platform, TargetPlatform? platform,
}) { }) {
if (event is KeyUpEvent || final alt = keyboard.isAltPressed;
event.logicalKey != LogicalKeyboardKey.keyY || // Option+Y types a symbol (¥) on a Mac, so with Alt the key is also
keyboard.isShiftPressed || // matched by its position.
keyboard.isAltPressed) { final y =
return false; event.logicalKey == LogicalKeyboardKey.keyY ||
} alt && event.physicalKey == PhysicalKeyboardKey.keyY;
if (event is KeyUpEvent || !y || keyboard.isShiftPressed) return false;
final control = keyboard.isControlPressed; final control = keyboard.isControlPressed;
final meta = keyboard.isMetaPressed; final meta = keyboard.isMetaPressed;
if (alt) return !control && !meta;
if (control == meta) return false; if (control == meta) return false;
if (!_apple(platform ?? defaultTargetPlatform)) return control; if (!_apple(platform ?? defaultTargetPlatform)) return control;
return meta || !primaryFocusIsTypingSurface(); return meta || !primaryFocusIsTypingSurface();
@@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.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_view.dart';
import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart'; import 'package:pipelines_app/features/chat/conversation/chat_thread_header.dart';
import 'package:pipelines_app/features/chat/conversation/chat_sidebar_controls.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; tester.getTopRight(find.byKey(Key(left))).dx;
expect(gap('header-control-1', 'header-control-2'), 8); expect(gap('header-control-1', 'header-control-2'), 8);
// The model/mode island keeps its text 12 px off its pill's ends. expect(gap('header-control-2', 'header-action-1'), 8);
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-action-1', 'header-action-2'), 8); expect(gap('header-action-1', 'header-action-2'), 8);
expect( expect(
tester.getTopLeft(find.byKey(segmentedMoreKey).first).dx - tester.getTopLeft(find.byKey(segmentedMoreKey).first).dx -
@@ -396,4 +384,23 @@ void main() {
); );
expect(tester.takeException(), isNull); 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);
});
} }
@@ -225,4 +225,62 @@ void main() {
await _chord(tester, LogicalKeyboardKey.controlLeft); await _chord(tester, LogicalKeyboardKey.controlLeft);
expect(h.controller.floatShown, isTrue); 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<LogicalKeyboardKey> pressed;
@override
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
} }