Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(desktop/terminal): ⌥⌫ and ⌘⌫ did nothing in a pane

reinSPQR11ac14ae1a25
diff --git a/desktop/CLAUDE.md b/desktop/CLAUDE.md
index 814212625..1923ba409 100644
--- a/desktop/CLAUDE.md
+++ b/desktop/CLAUDE.md
@@ -474,11 +474,15 @@ from `node_status` pushes — distinct from our own socket status, pending offli
▸ Keyboard shortcuts, group cards reflowed across the pane, plus the recessed "the terminal keeps"
card built from `kTerminalOwnedKeys`). Same rows behind both, so they cannot disagree; keycaps come
from `shortcuts/key_cap.dart`. Every shortcut is ⌘-based — Ctrl belongs to the shell/tmux, ⌥ is a
- Meta prefix for the pty (⌥⏎ only — `MetaEnterInputHandler` in
- `lib/terminal/terminal_input.dart` turns it into `ESC` + Return so the engine's prompt breaks the
- line instead of submitting; ⌥ stays the compose key everywhere else, and the composer answers the
- same chord by writing the newline itself), and ⌘C/⌘V/⌘A are owned by xterm — with one pinned
- exception, `⌃⇥`/`⌃⇧⇥` for the panes, which the terminal is made to let past.
+ Meta prefix for the pty (⌥⏎ and ⌥⌫ only — `AltAsMetaInputHandler` in
+ `lib/terminal/terminal_input.dart` turns them into `ESC` + Return and `ESC` + `\x7f`, so the
+ engine's prompt breaks the line instead of submitting and kills the word behind the cursor
+ instead of hearing nothing; ⌥ stays the compose key everywhere else), and ⌘C/⌘V/⌘A are owned by
+ xterm — with two pinned exceptions: `⌃⇥`/`⌃⇧⇥` for the panes, which the terminal is made to let
+ past, and ⌘⌫, which `TerminalPanel._onTerminalKey` takes back off the app and sends to the pty as
+ `^U` because a ⌘ chord never reaches xterm's input handler at all. The composer answers all four
+ line-editing chords too: it writes ⌥⏎'s newline itself, binds `^W`/`^U`, and lets Flutter's own
+ macOS text-editing shortcuts serve ⌥⌫ and ⌘⌫.
- `lib/flash/` flashes the ESP32-S3 dial through the CLI runner; `SerialPortLease` pauses daemon
supervision while the port is held so `harness start` cannot steal it mid-write.
- `lib/update/desktop_updater.dart` self-updates from the GCS manifest (sha256-verified, strictly
diff --git a/desktop/lib/shortcuts/app_shortcuts.dart b/desktop/lib/shortcuts/app_shortcuts.dart
index fe2a8e211..c846d875a 100644
--- a/desktop/lib/shortcuts/app_shortcuts.dart
+++ b/desktop/lib/shortcuts/app_shortcuts.dart
@@ -550,6 +550,10 @@ const List<TerminalKey> kTerminalOwnedKeys = [
TerminalKey(['⌘', 'A'], 'Select all'),
TerminalKey(['esc'], 'Interrupt the engine'),
TerminalKey(['⌥', '⏎'], "Newline in the engine's prompt"),
+ // Kept as short as the rows around them: the deck's narrowest card is 280px, where a label much
+ // past thirty characters takes a second line to itself.
+ TerminalKey(['⌥', '⌫'], 'Delete the previous word'),
+ TerminalKey(['⌘', '⌫'], "Delete to the line's start"),
TerminalKey(['⌃', 'C'], 'Cancel / interrupt in the agent'),
];
diff --git a/desktop/lib/terminal/terminal_input.dart b/desktop/lib/terminal/terminal_input.dart
index 088fa9c99..113609243 100644
--- a/desktop/lib/terminal/terminal_input.dart
+++ b/desktop/lib/terminal/terminal_input.dart
@@ -1,41 +1,53 @@
import 'package:xterm/xterm.dart';
-/// Makes ⌥⏎ a newline inside the engine's prompt instead of a submit.
+/// Makes ⌥ the Meta key for the two chords an engine's prompt reads as line editing: ⌥⏎ breaks the
+/// line instead of submitting it, and ⌥⌫ kills the word behind the caret instead of doing nothing.
///
/// Claude Code, Codex and every other Ink/readline prompt read Meta+Enter — `ESC` followed by the
-/// ordinary Return bytes — as "add a line, do not send this turn yet". A real terminal produces
-/// that only when it is configured to treat ⌥ as Meta (iTerm's "Esc+", Terminal.app's "Use Option
-/// as Meta Key"); xterm.dart has no such setting, and its [AltInputHandler] deliberately does
-/// nothing on macOS so ⌥ stays the compose key for `å`/`ø`/`¬`. So ⌥⏎ fell through to the keytab,
-/// which matches on `Return` alone and answers `\r` — the submit. The key the shortcuts sheet
-/// promises (`kTerminalOwnedKeys`) sent the turn instead of breaking the line.
+/// ordinary Return bytes — as "add a line, do not send this turn yet", and Meta+Backspace — `ESC`
+/// followed by `\x7f` — as "delete the word behind me". A real terminal produces those only when it
+/// is configured to treat ⌥ as Meta (iTerm's "Esc+", Terminal.app's "Use Option as Meta Key");
+/// xterm.dart has no such setting, and its [AltInputHandler] deliberately does nothing on macOS so
+/// ⌥ stays the compose key for `å`/`ø`/`¬`. So ⌥⏎ fell through to the keytab, which matches on
+/// `Return` alone and answers `\r` — the submit. ⌥⌫ never even reached the keytab: macOS hands
+/// Backspace to the native text input client, which answers `deleteBackward:` and has no idea what
+/// ⌥ adds (see patch 2 in `third_party/xterm/README.autonomous.md`). Both keys the shortcuts sheet
+/// promises (`kTerminalOwnedKeys`) did the wrong thing, or nothing at all.
///
-/// ⌥ is Meta for THIS ONE KEY, not for the keyboard: Enter carries no character to compose, so
-/// prefixing it costs nothing that ⌥-as-compose needs, and the rest of the alphabet is untouched.
+/// ⌥ is Meta for THESE KEYS, not for the keyboard: neither carries a character to compose, so
+/// prefixing them costs nothing that ⌥-as-compose needs, and the rest of the alphabet is untouched.
///
-/// The base bytes are asked of [_inner] rather than written out here, because Return is not always
-/// `\r`: under LNM (`lineFeedMode`) the keytab answers `\r\n`, and a caller may pass a keytab of
-/// its own. Alt and Shift are cleared for that question — Alt so the keytab does not see the very
-/// modifier being translated, Shift so ⌥⇧⏎ yields a prefixed Return rather than a prefixed `\EOM`,
-/// which no prompt would recognise.
-class MetaEnterInputHandler implements TerminalInputHandler {
- const MetaEnterInputHandler(this._inner);
+/// The base bytes are asked of [_inner] rather than written out here, because neither key has one
+/// fixed answer: under LNM (`lineFeedMode`) the keytab answers Return with `\r\n` rather than
+/// `\r`, and a caller may pass a keytab of its own. Alt and Shift are cleared for that question — Alt so the keytab does not see the very
+/// modifier being translated (it has a rule of its own for ⌥⌫, `\x17`, which this replaces with the
+/// word-boundary kill a Mac field does), Shift so ⌥⇧⏎ yields a prefixed Return rather than a
+/// prefixed `\EOM`, which no prompt would recognise.
+class AltAsMetaInputHandler implements TerminalInputHandler {
+ const AltAsMetaInputHandler(this._inner);
final TerminalInputHandler _inner;
+ /// The keys ⌥ prefixes. Enter and Backspace only — see the note above about the compose key.
+ static const _metaKeys = {
+ TerminalKey.enter,
+ TerminalKey.numpadEnter,
+ TerminalKey.backspace,
+ };
+
@override
String? call(TerminalKeyboardEvent event) {
- final isEnter =
- event.key == TerminalKey.enter || event.key == TerminalKey.numpadEnter;
- // Ctrl+Alt+Enter is left alone: that chord belongs to whatever is running, not to this.
- if (!isEnter || !event.alt || event.ctrl) return _inner(event);
+ // ⌃⌥ is left alone: that chord belongs to whatever is running, not to this.
+ if (!event.alt || event.ctrl || !_metaKeys.contains(event.key)) {
+ return _inner(event);
+ }
final base = _inner(event.copyWith(alt: false, shift: false));
if (base == null) return null;
return '\x1b$base';
}
}
-/// The handler every pane's [Terminal] is built with — xterm's default behaviour, plus ⌥⏎.
-const TerminalInputHandler harnessInputHandler = MetaEnterInputHandler(
+/// The handler every pane's [Terminal] is built with — xterm's default behaviour, plus ⌥⏎ and ⌥⌫.
+const TerminalInputHandler harnessInputHandler = AltAsMetaInputHandler(
defaultInputHandler,
);
diff --git a/desktop/lib/terminal/terminal_session.dart b/desktop/lib/terminal/terminal_session.dart
index 834a6d052..a42af01c9 100644
--- a/desktop/lib/terminal/terminal_session.dart
+++ b/desktop/lib/terminal/terminal_session.dart
@@ -778,8 +778,9 @@ class TerminalSession extends ChangeNotifier {
final result = Terminal(
maxLines: 10000,
platform: TerminalTargetPlatform.macos,
- // ⌥⏎ has to become a Meta-prefixed Return before it reaches the pty, or the engine's prompt
- // reads it as the submit it is byte-identical to. See [MetaEnterInputHandler].
+ // ⌥⏎ and ⌥⌫ have to become Meta-prefixed before they reach the pty, or the engine's prompt
+ // reads the first as the submit it is byte-identical to and never hears the second at all.
+ // See [AltAsMetaInputHandler].
inputHandler: harnessInputHandler,
// The remote pane owns its grid and redraws after resize. Reflowing TUI
// rows locally both changes their geometry and exercises an xterm.dart
diff --git a/desktop/lib/widgets/terminal_panel.dart b/desktop/lib/widgets/terminal_panel.dart
index 8ac1c3a88..af1735427 100644
--- a/desktop/lib/widgets/terminal_panel.dart
+++ b/desktop/lib/widgets/terminal_panel.dart
@@ -934,12 +934,53 @@ class _TerminalPanelState extends State<TerminalPanel>
widget.session.terminal.keyInput(TerminalKey.keyV, ctrl: true);
}
- /// ⌘V (Ctrl+V off Apple) — taken from xterm so the fallthrough above applies.
+ /// ⌘⌫ — kill back to the start of the line, the way a macOS text field does it.
+ ///
+ /// The pty has no Command key. What a prompt understands is readline's ^U (`\x15`), and it means
+ /// the same thing: verified against a live Claude Code and Codex, it clears back to the start of
+ /// the CURRENT line and leaves the lines composed above it standing — which is exactly what ⌘⌫
+ /// does in a Mac field. Asked of the keytab as `^U` rather than written as a byte so a terminal
+ /// carrying its own handler still answers with whatever ^U means to it.
+ ///
+ /// Taken HERE, in the pane's own hook, and not in the input handler with ⌥⌫: a ⌘ chord never
+ /// reaches `keyInput` at all. xterm hands every one of them back to the app untouched (patch 3 in
+ /// `third_party/xterm/README.autonomous.md`) — and `TerminalKeyboardEvent` has no `meta` field to
+ /// answer it with even if it did. Nothing in `app_shortcuts.dart` claims ⌘⌫ either, so the chord
+ /// went up the focus chain and off the end of it, doing nothing.
+ ///
+ /// Apple only. Elsewhere ⌘ is Super, where killing a line is not what it means, and the app's own
+ /// Super chords have to keep reaching the app.
+ KeyEventResult _onDeleteToLineStart() {
+ final keyboard = HardwareKeyboard.instance;
+ final apple =
+ defaultTargetPlatform == TargetPlatform.macOS ||
+ defaultTargetPlatform == TargetPlatform.iOS;
+ if (!apple || !keyboard.isMetaPressed) return KeyEventResult.ignored;
+ // ⌃ and ⌥ each carry a kill of their own to the pty (^U and Meta+⌫); a chord mixing them with
+ // ⌘ is nobody's idea of this one, so it is left for the shell to make sense of.
+ if (keyboard.isControlPressed || keyboard.isAltPressed) {
+ return KeyEventResult.ignored;
+ }
+ if (widget.readOnly || !widget.session.acceptsInput) {
+ return KeyEventResult.ignored;
+ }
+ widget.session.terminal.keyInput(TerminalKey.keyU, ctrl: true);
+ return KeyEventResult.handled;
+ }
+
+ /// ⌘V (Ctrl+V off Apple) — taken from xterm so the fallthrough above applies. ⌘⌫ joins it here,
+ /// for the reason spelled out on [_onDeleteToLineStart].
///
/// xterm binds paste itself, but only ever to its text-only action. `onKeyEvent`
/// is the one hook that runs BEFORE its shortcut map (terminal_view.dart), so
/// this is where the binding has to be replaced rather than added.
KeyEventResult _onTerminalKey(FocusNode node, KeyEvent event) {
+ // A held ⌘⌫ repeats, the way a held Backspace does — unlike ⌘V, where a second paste is never
+ // what the finger that stayed down meant.
+ if ((event is KeyDownEvent || event is KeyRepeatEvent) &&
+ event.logicalKey == LogicalKeyboardKey.backspace) {
+ return _onDeleteToLineStart();
+ }
if (event is! KeyDownEvent) return KeyEventResult.ignored;
if (event.logicalKey != LogicalKeyboardKey.keyV) {
return KeyEventResult.ignored;
diff --git a/desktop/test/terminal_composer_test.dart b/desktop/test/terminal_composer_test.dart
index 73b58b1fb..c05069f5e 100644
--- a/desktop/test/terminal_composer_test.dart
+++ b/desktop/test/terminal_composer_test.dart
@@ -1,5 +1,6 @@
import 'dart:math' as math;
+import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -413,6 +414,76 @@ void main() {
app.dispose();
});
+ /// ⌥⌫ and ⌘⌫ are the pane's word-kill and line-kill (`kTerminalOwnedKeys`), and the composer is
+ /// the same prompt wearing a Flutter field — so the two have to agree. Here they come from
+ /// Flutter's own macOS text-editing shortcuts rather than from anything this app writes, which is
+ /// exactly why they are pinned: nothing in the composer would notice if that changed.
+ testWidgets('Option+Backspace kills the word behind the caret', (
+ tester,
+ ) async {
+ debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
+ final outbound = <String>[];
+ final app = _notifier(local: false);
+ final session = await _liveSession(outbound);
+ await tester.pumpWidget(_host(app, session));
+ await tester.pump();
+
+ await tester.tap(find.byType(TextField));
+ await tester.pump();
+ await tester.enterText(find.byType(TextField), 'deploy the service');
+ await tester.pump();
+
+ await tester.sendKeyDownEvent(
+ LogicalKeyboardKey.altLeft,
+ platform: 'macos',
+ );
+ await tester.sendKeyEvent(LogicalKeyboardKey.backspace, platform: 'macos');
+ await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft, platform: 'macos');
+ await tester.pump();
+
+ expect(
+ tester.widget<TextField>(find.byType(TextField)).controller?.text,
+ 'deploy the ',
+ );
+ expect(outbound, isEmpty, reason: 'editing a line is not sending it');
+ debugDefaultTargetPlatformOverride = null;
+ session.dispose();
+ app.dispose();
+ });
+
+ testWidgets('Cmd+Backspace clears back to the start of the line', (
+ tester,
+ ) async {
+ debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
+ final outbound = <String>[];
+ final app = _notifier(local: false);
+ final session = await _liveSession(outbound);
+ await tester.pumpWidget(_host(app, session));
+ await tester.pump();
+
+ await tester.tap(find.byType(TextField));
+ await tester.pump();
+ await tester.enterText(find.byType(TextField), 'deploy the service');
+ await tester.pump();
+
+ await tester.sendKeyDownEvent(
+ LogicalKeyboardKey.metaLeft,
+ platform: 'macos',
+ );
+ await tester.sendKeyEvent(LogicalKeyboardKey.backspace, platform: 'macos');
+ await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft, platform: 'macos');
+ await tester.pump();
+
+ expect(
+ tester.widget<TextField>(find.byType(TextField)).controller?.text,
+ '',
+ );
+ expect(outbound, isEmpty);
+ debugDefaultTargetPlatformOverride = null;
+ session.dispose();
+ app.dispose();
+ });
+
testWidgets('Ctrl+U clears everything before the cursor', (tester) async {
final app = _notifier(local: false);
final session = await _liveSession([]);
diff --git a/desktop/test/terminal_input_test.dart b/desktop/test/terminal_input_test.dart
index 72011cd3f..ca8d7d684 100644
--- a/desktop/test/terminal_input_test.dart
+++ b/desktop/test/terminal_input_test.dart
@@ -1,5 +1,6 @@
import 'dart:convert';
+import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -160,6 +161,51 @@ void main() {
expect(out, ['\r'], reason: 'the plain Return the keytab would have sent');
});
+ test('⌥⌫ reaches the engine as Meta + DEL, the word-kill a prompt reads', () {
+ final out = <String>[];
+ final terminal = _pane()..onOutput = out.add;
+
+ terminal.keyInput(TerminalKey.backspace, alt: true);
+
+ expect(out, ['\x1b\x7f']);
+ });
+
+ test('a plain ⌫ still erases one character', () {
+ final out = <String>[];
+ final terminal = _pane()..onOutput = out.add;
+
+ terminal.keyInput(TerminalKey.backspace);
+
+ expect(out, ['\x7f']);
+ });
+
+ test('⌃⌫ keeps the ^H the keytab gives it', () {
+ final out = <String>[];
+ final terminal = _pane()..onOutput = out.add;
+
+ terminal.keyInput(TerminalKey.backspace, ctrl: true);
+
+ expect(out, ['\b']);
+ });
+
+ test('⌃⌥⌫ is left to whatever is running', () {
+ final out = <String>[];
+ final terminal = _pane()..onOutput = out.add;
+
+ terminal.keyInput(TerminalKey.backspace, alt: true, ctrl: true);
+
+ expect(out, ['\x17'], reason: "the keytab's own ⌥⌫ rule, untranslated");
+ });
+
+ test('⇧⌥⌫ kills the word rather than inventing a chord', () {
+ final out = <String>[];
+ final terminal = _pane()..onOutput = out.add;
+
+ terminal.keyInput(TerminalKey.backspace, alt: true, shift: true);
+
+ expect(out, ['\x1b\x7f']);
+ });
+
test('⌥ stays the compose key for every other letter', () {
final out = <String>[];
final terminal = _pane()..onOutput = out.add;
@@ -238,6 +284,132 @@ void main() {
app.dispose();
});
+ testWidgets('⌥⌫ leaves a live pane as ESC + DEL', (tester) async {
+ // Told it is on a Mac, `TerminalView` hands Backspace to the native text input client — the
+ // very rule ⌥⌫ has to be excluded from. Without this override the test runs the Linux path,
+ // where the key reaches `keyInput` no matter what, and proves nothing about the bug.
+ debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
+ final wire = <TerminalBinaryFrame>[];
+ final app = _localNotifier();
+ final session = await _liveSession(wire);
+ await tester.pumpWidget(_host(app, session));
+ await tester.pump();
+
+ // macOS hands a bare Backspace to the native text input client, which answers `deleteBackward:`
+ // — a bargain that only holds for the bare key. ⌥⌫ arrives as `deleteWordBackward:`, which
+ // nothing answers, so the pane has to keep this one for itself.
+ await tester.sendKeyDownEvent(
+ LogicalKeyboardKey.altLeft,
+ platform: 'macos',
+ );
+ await tester.sendKeyEvent(
+ LogicalKeyboardKey.backspace,
+ character: '\b',
+ platform: 'macos',
+ );
+ await tester.sendKeyUpEvent(LogicalKeyboardKey.altLeft, platform: 'macos');
+ await tester.pump(const Duration(milliseconds: 30));
+
+ expect(_typed(wire), '\x1b\x7f');
+ debugDefaultTargetPlatformOverride = null;
+ session.dispose();
+ app.dispose();
+ });
+
+ testWidgets('⌘⌫ leaves a live pane as ^U, the kill to the line start', (
+ tester,
+ ) async {
+ // ⌘⌫ is Apple's chord, and [TerminalPanel] asks the platform before taking it.
+ debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
+ final wire = <TerminalBinaryFrame>[];
+ final app = _localNotifier();
+ final session = await _liveSession(wire);
+ await tester.pumpWidget(_host(app, session));
+ await tester.pump();
+
+ await tester.sendKeyDownEvent(
+ LogicalKeyboardKey.metaLeft,
+ platform: 'macos',
+ );
+ await tester.sendKeyEvent(
+ LogicalKeyboardKey.backspace,
+ character: '\b',
+ platform: 'macos',
+ );
+ await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft, platform: 'macos');
+ await tester.pump(const Duration(milliseconds: 30));
+
+ expect(_typed(wire), '\x15');
+ debugDefaultTargetPlatformOverride = null;
+ session.dispose();
+ app.dispose();
+ });
+
+ testWidgets('a held ⌘⌫ keeps killing lines', (tester) async {
+ // ⌘⌫ is Apple's chord, and [TerminalPanel] asks the platform before taking it.
+ debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
+ final wire = <TerminalBinaryFrame>[];
+ final app = _localNotifier();
+ final session = await _liveSession(wire);
+ await tester.pumpWidget(_host(app, session));
+ await tester.pump();
+
+ await tester.sendKeyDownEvent(
+ LogicalKeyboardKey.metaLeft,
+ platform: 'macos',
+ );
+ await tester.sendKeyDownEvent(
+ LogicalKeyboardKey.backspace,
+ platform: 'macos',
+ );
+ await tester.sendKeyRepeatEvent(
+ LogicalKeyboardKey.backspace,
+ platform: 'macos',
+ );
+ await tester.sendKeyUpEvent(
+ LogicalKeyboardKey.backspace,
+ platform: 'macos',
+ );
+ await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft, platform: 'macos');
+ await tester.pump(const Duration(milliseconds: 30));
+
+ expect(_typed(wire), '\x15\x15');
+ debugDefaultTargetPlatformOverride = null;
+ session.dispose();
+ app.dispose();
+ });
+
+ testWidgets('⌃⌘⌫ is nobody\'s idea of either kill', (tester) async {
+ // ⌘⌫ is Apple's chord, and [TerminalPanel] asks the platform before taking it.
+ debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
+ final wire = <TerminalBinaryFrame>[];
+ final app = _localNotifier();
+ final session = await _liveSession(wire);
+ await tester.pumpWidget(_host(app, session));
+ await tester.pump();
+
+ await tester.sendKeyDownEvent(
+ LogicalKeyboardKey.controlLeft,
+ platform: 'macos',
+ );
+ await tester.sendKeyDownEvent(
+ LogicalKeyboardKey.metaLeft,
+ platform: 'macos',
+ );
+ await tester.sendKeyEvent(LogicalKeyboardKey.backspace, platform: 'macos');
+ await tester.sendKeyUpEvent(LogicalKeyboardKey.metaLeft, platform: 'macos');
+ await tester.sendKeyUpEvent(
+ LogicalKeyboardKey.controlLeft,
+ platform: 'macos',
+ );
+ await tester.pump(const Duration(milliseconds: 30));
+
+ expect(_typed(wire), isEmpty, reason: 'a ⌘ chord goes back to the app');
+ debugDefaultTargetPlatformOverride = null;
+ session.dispose();
+ app.dispose();
+ });
+
testWidgets('⌥ + a letter is still composed, not sent as Meta', (
tester,
) async {
diff --git a/desktop/third_party/xterm/README.autonomous.md b/desktop/third_party/xterm/README.autonomous.md
index 307897586..060d200d3 100644
--- a/desktop/third_party/xterm/README.autonomous.md
+++ b/desktop/third_party/xterm/README.autonomous.md
@@ -73,8 +73,14 @@ it if one is dropped.
such channel method and names `GDK_KEY_BackSpace` explicitly to ignore it —
correct for an `EditableText`, wrong for the bare `TextInputClient` here —
so upstream's unconditional version dropped the key entirely on Linux and no
- byte reached the pty. Regression: the macOS/Linux pair in
- `test/terminal_view_interaction_test.dart`.
+ byte reached the pty. ⌥⌫ is excluded from the hand-off for the mirror-image
+ reason: AppKit answers it with `deleteWordBackward:`, a selector
+ `CustomTextEdit` does not implement, so the chord reached neither the
+ platform nor the pty and deleted nothing at all. It falls through to
+ `keyInput`, where `AltAsMetaInputHandler` makes it `ESC` + `\x7f`.
+ Regression: the macOS/Linux pair in
+ `test/terminal_view_interaction_test.dart`, and the ⌥⌫ pane tests in
+ `test/terminal_input_test.dart`.
3. **A Meta chord is left for the app on every platform, not just Apple**
(`lib/src/terminal_view.dart`). Every shortcut in
diff --git a/desktop/third_party/xterm/lib/src/terminal_view.dart b/desktop/third_party/xterm/lib/src/terminal_view.dart
index 2269071c6..c78430571 100644
--- a/desktop/third_party/xterm/lib/src/terminal_view.dart
+++ b/desktop/third_party/xterm/lib/src/terminal_view.dart
@@ -540,13 +540,22 @@ class TerminalViewState extends State<TerminalView> {
// the keytab turns it into ^? (\x7f). Composition is not at risk either
// way — while an IME is composing, CustomTextEdit._onKeyEvent never calls
// this method.
+ //
+ // ⌥⌫ IS NOT THAT KEY. AppKit turns it into `deleteWordBackward:`, which
+ // CustomTextEdit does not answer — it takes `deleteBackward*` and nothing
+ // else — so handing it over dropped it on the floor and no byte reached
+ // the pty: the chord did nothing whatsoever. No IME needs it either; the
+ // internal deletes they make are plain Backspaces. It belongs to keyInput
+ // below, where ⌥ becomes the Meta prefix a prompt reads as "kill the word
+ // behind me" (see AltAsMetaInputHandler in lib/terminal/terminal_input.dart).
final nativeClientOwnsBackspace =
defaultTargetPlatform == TargetPlatform.macOS ||
defaultTargetPlatform == TargetPlatform.iOS;
if (key == TerminalKey.backspace &&
nativeClientOwnsBackspace &&
!widget.hardwareKeyboardOnly &&
- !reservesTerminalKey) {
+ !reservesTerminalKey &&
+ !HardwareKeyboard.instance.isAltPressed) {
return KeyEventResult.skipRemainingHandlers;
}