7dc054763b
Route Ctrl+Tab and Ctrl+Shift+Tab between visible floating chat windows while preserving tiled-pane and terminal tab behavior. Add regression coverage and document the shortcut semantics.
40 lines
1.4 KiB
Dart
40 lines
1.4 KiB
Dart
import 'package:flutter/services.dart';
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import '../../../shell/windows/window_entry.dart';
|
|
import '../../../shell/windows/window_scope.dart';
|
|
|
|
/// The step Ctrl+Tab (1) or Ctrl+Shift+Tab (-1) moves between floating chat
|
|
/// windows, or null for any other key. Command+Tab stays with the system.
|
|
int? chatWindowTabStep(KeyEvent event, HardwareKeyboard keyboard) {
|
|
if (event is! KeyDownEvent ||
|
|
event.logicalKey != LogicalKeyboardKey.tab ||
|
|
!keyboard.isControlPressed ||
|
|
keyboard.isMetaPressed ||
|
|
keyboard.isAltPressed) {
|
|
return null;
|
|
}
|
|
return keyboard.isShiftPressed ? -1 : 1;
|
|
}
|
|
|
|
/// The window [step] away from the window [currentId] in [visible] (bottom
|
|
/// to top), wrapping around. Null when [currentId] is not listed or there is
|
|
/// no other window to move to.
|
|
WindowEntry? chatWindowAfter(
|
|
List<WindowEntry> visible,
|
|
String currentId,
|
|
int step,
|
|
) {
|
|
final at = visible.indexWhere((w) => w.id == currentId);
|
|
if (at < 0 || visible.length < 2) return null;
|
|
return visible[(at + step) % visible.length];
|
|
}
|
|
|
|
/// The floating window whose content holds the keyboard, if one does. Read
|
|
/// from the focused node's ancestors, so it needs no reference to the host.
|
|
WindowScope? keyboardWindow() {
|
|
final context = FocusManager.instance.primaryFocus?.context;
|
|
if (context == null) return null;
|
|
return context.findAncestorWidgetOfExactType<WindowScope>();
|
|
}
|