141661e355
On Chat the chord now toggles a centred dialog (bottom sheet on a phone) with an autofocused filter over the open chats in list order; Ctrl+N/Down and Ctrl+P/Up move the wrapping selection, Enter opens the chat as Ctrl+Tab does (pane reused, composer focused), Esc or the chord closes it. From other destinations the chord still jumps to Chat. Ctrl+N/Ctrl+P are handled so the web page prevents their defaults (Ctrl+P no longer prints); a browser tab keeps Ctrl+N reserved, documented in the help and notes/chat-quick-switch.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
50 lines
1.8 KiB
Dart
50 lines
1.8 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
/// The chat quick switcher's keys, read while its field has the keyboard:
|
|
/// Ctrl+N and Down step the selection forward ([onStep] with 1), Ctrl+P and
|
|
/// Up back (-1), and Enter chooses it ([onChoose]). Control rather than Cmd
|
|
/// on Apple platforms too, as in Search and Emacs-style lists.
|
|
///
|
|
/// The chords are reported handled, also with nothing to select, so a
|
|
/// browser does not run its own default (Ctrl+P prints). A browser tab may
|
|
/// still keep Ctrl+N for itself (a new window) before the page sees it; Up
|
|
/// and Down always work, and an installed app window or the terminal's
|
|
/// "Capture browser keys" full screen passes Ctrl+N through.
|
|
KeyEventResult chatQuickSwitchKey(
|
|
KeyEvent event,
|
|
HardwareKeyboard keyboard, {
|
|
required ValueChanged<int> onStep,
|
|
required VoidCallback onChoose,
|
|
}) {
|
|
if (event is! KeyDownEvent && event is! KeyRepeatEvent) {
|
|
return KeyEventResult.ignored;
|
|
}
|
|
if (keyboard.isAltPressed || keyboard.isMetaPressed) {
|
|
return KeyEventResult.ignored;
|
|
}
|
|
final key = event.logicalKey;
|
|
final control = keyboard.isControlPressed;
|
|
final shift = keyboard.isShiftPressed;
|
|
final step = switch (key) {
|
|
LogicalKeyboardKey.keyN when control && !shift => 1,
|
|
LogicalKeyboardKey.keyP when control && !shift => -1,
|
|
LogicalKeyboardKey.arrowDown when !control && !shift => 1,
|
|
LogicalKeyboardKey.arrowUp when !control && !shift => -1,
|
|
_ => 0,
|
|
};
|
|
if (step != 0) {
|
|
onStep(step);
|
|
return KeyEventResult.handled;
|
|
}
|
|
if (event is KeyDownEvent &&
|
|
!control &&
|
|
!shift &&
|
|
(key == LogicalKeyboardKey.enter ||
|
|
key == LogicalKeyboardKey.numpadEnter)) {
|
|
onChoose();
|
|
return KeyEventResult.handled;
|
|
}
|
|
return KeyEventResult.ignored;
|
|
}
|