Keep keys typed in a terminal out of app shortcuts
Terminals are marked as typing surfaces. While one has focus, the chat's "/ jumps to the composer", the Search tab's Escape, Ctrl+/, Ctrl+1…9 and Ctrl+Shift+arrow pane moves leave the key to the terminal, like they do for text fields.
This commit is contained in:
@@ -43,9 +43,7 @@ mixin _ChatScreenKeys on State<ChatScreen>, _ChatScreenWorkspace {
|
||||
@override
|
||||
bool _toggleRecentChat() {
|
||||
final current = _workspace.activePane?.sessionId;
|
||||
final previous = _recentSessions
|
||||
.where((id) => id != current)
|
||||
.firstOrNull;
|
||||
final previous = _recentSessions.where((id) => id != current).firstOrNull;
|
||||
if (previous == null) return false;
|
||||
_open(_rowFor(previous) ?? {'id': previous}, focusComposer: true);
|
||||
return true;
|
||||
@@ -87,10 +85,7 @@ mixin _ChatScreenKeys on State<ChatScreen>, _ChatScreenWorkspace {
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Whether an editable text control holds focus, wherever it is.
|
||||
bool _textFieldHasFocus() {
|
||||
final context = FocusManager.instance.primaryFocus?.context;
|
||||
final editable = context?.findAncestorWidgetOfExactType<EditableText>();
|
||||
return editable != null && !editable.readOnly;
|
||||
}
|
||||
/// Whether something that takes typing holds focus, wherever it is: an
|
||||
/// editable text field or a terminal.
|
||||
bool _textFieldHasFocus() => primaryFocusTakesTyping();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/widgets.dart';
|
||||
import '../../../ui/input/keyboard_owner.dart';
|
||||
|
||||
/// Flutter shares a single web editing element across fields. DOM identity
|
||||
/// alone cannot tell a chat composer from search, rename or another editor.
|
||||
@@ -21,6 +22,7 @@ abstract final class ChatComposerPasteFocus {
|
||||
return false;
|
||||
}
|
||||
if (_inputs.any((focus) => focus.hasFocus)) return true;
|
||||
if (primaryFocusIsTypingSurface()) return true;
|
||||
final context = primary.context;
|
||||
if (context == null) return false;
|
||||
var editable = context.widget is EditableText;
|
||||
|
||||
@@ -46,6 +46,7 @@ import 'ui/sessions/chat_color_palette.dart';
|
||||
import 'ui/sessions/chat_sessions_body.dart';
|
||||
import 'ui/sessions/chat_sessions_controller.dart';
|
||||
import 'ui/sessions/chat_sessions_screen.dart';
|
||||
import '../../ui/input/keyboard_owner.dart';
|
||||
|
||||
part 'chat_screen_keys.dart';
|
||||
part 'chat_screen_workspace.dart';
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'chat_shell_metrics.dart';
|
||||
import 'chat_shell_terminal_links.dart';
|
||||
import 'chat_shell_terminal_session.dart';
|
||||
import 'chat_shell_terminal_theme.dart';
|
||||
import '../../../ui/input/keyboard_owner.dart';
|
||||
|
||||
/// Whether the soft keyboard is the main way to type here, so the key
|
||||
/// toolbar offers a text field: the terminal itself takes hardware keys only.
|
||||
@@ -104,23 +105,26 @@ class _ChatShellTerminalViewState extends State<ChatShellTerminalView> {
|
||||
Widget view = Semantics(
|
||||
identifier: 'chat-shell-terminal',
|
||||
label: live ? 'Terminal, type to send input' : 'Terminal output',
|
||||
child: TerminalView(
|
||||
session.terminal,
|
||||
controller: _controller,
|
||||
focusNode: _focus,
|
||||
autofocus: widget.autofocus && live,
|
||||
autoResize: widget.autoResize,
|
||||
theme: chatShellTerminalTheme(context, widget.cupertino),
|
||||
textStyle: style,
|
||||
padding: padding,
|
||||
readOnly: !live,
|
||||
// Keys go straight to the process as key events (a focused text
|
||||
// input would stay closed on the web); touch typing goes through the
|
||||
// key toolbar's field instead.
|
||||
hardwareKeyboardOnly: true,
|
||||
shortcuts: chatShellTerminalShortcuts(),
|
||||
cursorType: TerminalCursorType.block,
|
||||
onTapUp: _tapped,
|
||||
// App-wide shortcuts leave typing in the terminal alone.
|
||||
child: TypingSurface(
|
||||
child: TerminalView(
|
||||
session.terminal,
|
||||
controller: _controller,
|
||||
focusNode: _focus,
|
||||
autofocus: widget.autofocus && live,
|
||||
autoResize: widget.autoResize,
|
||||
theme: chatShellTerminalTheme(context, widget.cupertino),
|
||||
textStyle: style,
|
||||
padding: padding,
|
||||
readOnly: !live,
|
||||
// Keys go straight to the process as key events (a focused text
|
||||
// input would stay closed on the web); touch typing goes through the
|
||||
// key toolbar's field instead.
|
||||
hardwareKeyboardOnly: true,
|
||||
shortcuts: chatShellTerminalShortcuts(),
|
||||
cursorType: TerminalCursorType.block,
|
||||
onTapUp: _tapped,
|
||||
),
|
||||
),
|
||||
);
|
||||
// The emulator would otherwise inset itself by the window's safe area.
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'chat_mobile_panes.dart';
|
||||
import 'chat_pane_switch_motion.dart';
|
||||
import 'chat_pane_backdrop.dart';
|
||||
import 'chat_workspace_surface.dart';
|
||||
import '../../../ui/input/keyboard_owner.dart';
|
||||
|
||||
export 'chat_workspace_controller.dart';
|
||||
export 'chat_workspace_geometry.dart' show ChatPaneDirection;
|
||||
@@ -122,7 +123,8 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
if (!widget.shortcutsEnabled ||
|
||||
widget.controller.paneCount <= 1 ||
|
||||
!_focus.hasFocus ||
|
||||
event is! KeyDownEvent) {
|
||||
event is! KeyDownEvent ||
|
||||
primaryFocusIsTypingSurface()) {
|
||||
return false;
|
||||
}
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
|
||||
Reference in New Issue
Block a user