Terminal: xterm key encoding, no live reflow on resize, Alt+T/Ctrl+T reach the shell
- Live terminals no longer reflow (xterm.dart 4.0.0 left the cursor on the wrong row); narrowing cuts and erases cells past the width, rows scroll into scrollback keeping the cursor row; finished output still reflows. - App-side key encoding before xterm.dart's defaults: Alt as Meta (ESC + the typed character), Ctrl symbol table, xterm modifier parameter for arrows/Home/End/PgUp/PgDn/Ins/Del/F-keys, DECCKM and DECKPAM, Alt+BS. - Settings > Appearance > Terminal: Use Option as Meta key (Macs, on). - Inside a focused terminal only Cmd+T and Ctrl+` toggle it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import 'package:xterm/xterm.dart';
|
||||
import '../conversation/chat_composer_paste_focus.dart';
|
||||
import '../ui/transcript/chat_link_launcher.dart';
|
||||
import 'chat_shell_metrics.dart';
|
||||
import 'chat_shell_terminal_key_input.dart';
|
||||
import 'chat_shell_terminal_links.dart';
|
||||
import 'chat_shell_terminal_session.dart';
|
||||
import 'chat_shell_terminal_theme.dart';
|
||||
@@ -94,6 +95,9 @@ class _ChatShellTerminalViewState extends State<ChatShellTerminalView> {
|
||||
final TerminalController _controller = TerminalController();
|
||||
final FocusNode _focus = FocusNode(debugLabel: 'chat-shell-terminal');
|
||||
final FocusNode _outputFocus = FocusNode(debugLabel: 'chat-shell-output');
|
||||
final ScrollController _scroll = ScrollController();
|
||||
final Map<ShortcutActivator, Intent> _shortcuts =
|
||||
chatShellTerminalShortcuts();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -109,6 +113,7 @@ class _ChatShellTerminalViewState extends State<ChatShellTerminalView> {
|
||||
_controller.dispose();
|
||||
_focus.dispose();
|
||||
_outputFocus.dispose();
|
||||
_scroll.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -123,11 +128,30 @@ class _ChatShellTerminalViewState extends State<ChatShellTerminalView> {
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Ctrl-C with a selection copies; anything else is the terminal's.
|
||||
KeyEventResult _key(FocusNode node, KeyEvent event) =>
|
||||
chatShellCopyKey(event, HardwareKeyboard.instance) && _copySelection()
|
||||
? KeyEventResult.handled
|
||||
: KeyEventResult.ignored;
|
||||
/// Ctrl-C with a selection copies; the terminal's own shortcuts (copy,
|
||||
/// paste) are left to it; any other key xterm encodes differently from
|
||||
/// xterm.dart (Alt as Meta, Ctrl symbols, modified special keys) is sent
|
||||
/// here with its real character. The rest is the emulator's.
|
||||
KeyEventResult _key(FocusNode node, KeyEvent event) {
|
||||
final keyboard = HardwareKeyboard.instance;
|
||||
if (chatShellCopyKey(event, keyboard) && _copySelection()) {
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
if (_shortcuts.keys.any((key) => key.accepts(event, keyboard))) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
final session = widget.session;
|
||||
final bytes = chatShellKeyEventBytes(
|
||||
event,
|
||||
keyboard,
|
||||
session.terminal,
|
||||
optionAsMeta: session.optionAsMeta(),
|
||||
);
|
||||
if (bytes == null) return KeyEventResult.ignored;
|
||||
session.terminal.textInput(bytes);
|
||||
if (_scroll.hasClients) _scroll.jumpTo(_scroll.position.maxScrollExtent);
|
||||
return KeyEventResult.handled;
|
||||
}
|
||||
|
||||
/// A finished run's output takes no keys of its own, so the copy keys are
|
||||
/// answered here while it has the keyboard.
|
||||
@@ -163,6 +187,7 @@ class _ChatShellTerminalViewState extends State<ChatShellTerminalView> {
|
||||
child: TerminalView(
|
||||
session.terminal,
|
||||
controller: _controller,
|
||||
scrollController: _scroll,
|
||||
focusNode: _focus,
|
||||
autofocus: widget.autofocus && live,
|
||||
autoResize: widget.autoResize,
|
||||
@@ -177,7 +202,7 @@ class _ChatShellTerminalViewState extends State<ChatShellTerminalView> {
|
||||
hardwareKeyboardOnly: !chatShellTouchFirst(),
|
||||
// No autocorrect or suggestions rewriting what is sent to a shell.
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
shortcuts: chatShellTerminalShortcuts(),
|
||||
shortcuts: _shortcuts,
|
||||
cursorType: TerminalCursorType.block,
|
||||
onTapUp: _tapped,
|
||||
onKeyEvent: _key,
|
||||
|
||||
Reference in New Issue
Block a user