Merge branch 'bar-padding-alt-keys'
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -151,7 +151,7 @@ class _ChatEffortControlState extends State<ChatEffortControl> {
|
||||
child: ExcludeSemantics(
|
||||
child: CupertinoButton(
|
||||
key: key,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
padding: chatBarButtonPadding,
|
||||
onPressed: _openSheet,
|
||||
child: chatBarCupertinoContent(context, content),
|
||||
),
|
||||
|
||||
@@ -126,7 +126,7 @@ class _ChatModeControlState extends State<ChatModeControl> {
|
||||
child: ExcludeSemantics(
|
||||
child: CupertinoButton(
|
||||
key: key,
|
||||
padding: EdgeInsets.zero,
|
||||
padding: chatBarButtonPadding,
|
||||
onPressed: _open,
|
||||
child: chatBarCupertinoContent(context, content),
|
||||
),
|
||||
|
||||
@@ -139,7 +139,7 @@ class _ChatModelControlState extends State<ChatModelControl> {
|
||||
child: ExcludeSemantics(
|
||||
child: CupertinoButton(
|
||||
key: key,
|
||||
padding: EdgeInsets.zero,
|
||||
padding: chatBarButtonPadding,
|
||||
onPressed: _open,
|
||||
child: chatBarCupertinoContent(context, content),
|
||||
),
|
||||
|
||||
@@ -155,19 +155,14 @@ class _ControlIsland extends StatelessWidget {
|
||||
final List<Widget> 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),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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<LogicalKeyboardKey> pressed;
|
||||
@override
|
||||
bool isLogicalKeyPressed(LogicalKeyboardKey key) => pressed.contains(key);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user