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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(desktop): keep alternate-screen scrolling reaching the program
goku6aee22971c94
diff --git a/desktop/test/terminal_alt_buffer_scroll_test.dart b/desktop/test/terminal_alt_buffer_scroll_test.dartnew file mode 100644index 000000000..8e6e81150--- /dev/null+++ b/desktop/test/terminal_alt_buffer_scroll_test.dart@@ -0,0 +1,180 @@+import 'package:flutter/gestures.dart';+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:xterm/xterm.dart';++const _viewHeight = 300.0;++/// Mounts a view the way Harness does (`resizeBuffer: false`, so the local grid+/// is whatever the remote screen is) and returns the terminal and what it sent.+Future<(Terminal, List<String>)> _mount(+ WidgetTester tester,+ ScrollController controller,+) async {+ final output = <String>[];+ final terminal = Terminal(maxLines: 1000, reflowEnabled: false)+ ..onOutput = output.add;+ await tester.pumpWidget(+ MaterialApp(+ home: Scaffold(+ body: SizedBox(+ width: 600,+ height: _viewHeight,+ child: TerminalView(+ terminal,+ resizeBuffer: false,+ scrollController: controller,+ ),+ ),+ ),+ ),+ );+ await tester.pump();+ return (terminal, output);+}++/// A full-screen TUI whose grid is taller than the pane showing it — the remote+/// pane has not taken the size this view reported, or another client keeps it+/// larger. The alternate screen then has a few pixels of local scroll extent.+Future<void> _tuiTallerThanPane(WidgetTester tester, Terminal terminal) async {+ final lineHeight = tester+ .state<TerminalViewState>(find.byType(TerminalView))+ .renderTerminal+ .lineHeight;+ terminal.resize(60, (_viewHeight / lineHeight).floor() + 2);+ // Alternate screen, with SGR mouse reports on — tmux with `mouse on`.+ terminal.write('\x1b[?1049h\x1b[?1000h\x1b[?1006h');+ await tester.pump();+ await tester.pump();+}++Future<void> _trackpadUp(WidgetTester tester) async {+ final center = tester.getCenter(find.byType(TerminalView));+ final pad = TestPointer(1, PointerDeviceKind.trackpad);+ await tester.sendEventToBinding(pad.panZoomStart(center));+ await tester.sendEventToBinding(+ pad.panZoomUpdate(center, pan: const Offset(0, 120)),+ );+ await tester.sendEventToBinding(pad.panZoomEnd());+ await tester.pump(const Duration(milliseconds: 400));+}++const _wheelUpReport = '\x1b[<64;';++void main() {+ testWidgets(+ 'trackpad scrolling reaches a full-screen program whose grid is taller than the pane',+ (tester) async {+ final controller = ScrollController();+ addTearDown(controller.dispose);+ final (terminal, output) = await _mount(tester, controller);+ await _tuiTallerThanPane(tester, terminal);+ expect(controller.position.maxScrollExtent, greaterThan(0));++ await _trackpadUp(tester);++ expect(output.join(), contains(_wheelUpReport));+ },+ );++ testWidgets(+ 'a mouse-wheel tick reaches a full-screen program whose grid is taller than the pane',+ (tester) async {+ final controller = ScrollController();+ addTearDown(controller.dispose);+ final (terminal, output) = await _mount(tester, controller);+ await _tuiTallerThanPane(tester, terminal);+ expect(controller.position.maxScrollExtent, greaterThan(0));++ final mouse = TestPointer(2, PointerDeviceKind.mouse);+ final center = tester.getCenter(find.byType(TerminalView));+ await tester.sendEventToBinding(mouse.hover(center));+ await tester.sendEventToBinding(mouse.scroll(const Offset(0, -60)));+ await tester.pump(const Duration(milliseconds: 400));++ expect(output.join(), contains(_wheelUpReport));+ },+ );++ // Only the alternate screen hands scrolling to the program: in the normal+ // screen the gesture reads local history, as it always has.+ testWidgets('in the normal screen the same gesture still scrolls history', (+ tester,+ ) async {+ final controller = ScrollController();+ addTearDown(controller.dispose);+ final (terminal, output) = await _mount(tester, controller);+ terminal.write(List.generate(200, (i) => 'line $i').join('\r\n'));+ await tester.pump();+ await tester.pump();+ final bottom = controller.position.maxScrollExtent;+ expect(bottom, greaterThan(0));+ expect(controller.position.pixels, bottom);++ await _trackpadUp(tester);++ expect(controller.position.pixels, lessThan(bottom));+ expect(output.join(), isNot(contains(_wheelUpReport)));+ });++ // Scrollable swaps in a new ScrollPosition whenever its dependencies change —+ // a reparent is enough, and the pane grid reparents terminals as its layout+ // moves. The scroll view moved the wrong listener onto the new position, so+ // after two or three scrolls every later one reached nothing.+ testWidgets(+ 'scrolling still reaches the program after the view is reparented',+ (tester) async {+ final output = <String>[];+ final terminal = Terminal(maxLines: 1000, reflowEnabled: false)+ ..onOutput = output.add;+ final viewKey = GlobalKey();+ Future<void> pump({required bool padded}) {+ final view = TerminalView(terminal, key: viewKey, resizeBuffer: false);+ return tester.pumpWidget(+ MaterialApp(+ home: Scaffold(+ body: SizedBox(+ width: 600,+ height: _viewHeight,+ child: padded+ ? Padding(padding: EdgeInsets.zero, child: view)+ : Center(child: view),+ ),+ ),+ ),+ );+ }++ // The alternate screen's own scroll view is the outermost Scrollable.+ ScrollPosition altScrollPosition() => tester+ .stateList<ScrollableState>(find.byType(Scrollable))+ .first+ .position;++ Future<void> wheelUp() async {+ final mouse = TestPointer(4, PointerDeviceKind.mouse);+ await tester.sendEventToBinding(+ mouse.hover(tester.getCenter(find.byType(TerminalView))),+ );+ await tester.sendEventToBinding(mouse.scroll(const Offset(0, -60)));+ await tester.pump(const Duration(milliseconds: 400));+ }++ await pump(padded: true);+ terminal.write('\x1b[?1049h\x1b[?1000h\x1b[?1006h');+ await tester.pump();+ await tester.pump();+ await wheelUp();+ expect(output.join(), contains(_wheelUpReport));+ output.clear();+ final before = altScrollPosition();++ await pump(padded: false);+ await tester.pump();+ expect(altScrollPosition(), isNot(same(before)));++ await wheelUp();+ expect(output.join(), contains(_wheelUpReport));+ },+ );+}diff --git a/desktop/third_party/xterm/README.autonomous.md b/desktop/third_party/xterm/README.autonomous.mdindex 5912e9a02..307897586 100644--- a/desktop/third_party/xterm/README.autonomous.md+++ b/desktop/third_party/xterm/README.autonomous.md@@ -36,6 +36,29 @@ fix and the regression in `test/terminal_session_test.dart` passes against it.Ordinary clicks and drag selection keep their existing behavior. Regressions:`test/terminal_link_gesture_test.dart`, `test/terminal_panel_links_test.dart`.+- **Alternate-screen scrolling reaches the program even when its grid is taller+ than the pane** (`lib/src/ui/scroll_handler.dart`). With `resizeBuffer: false`+ the local grid is the remote one, so a remote screen that has not taken this+ pane's size yet — or that another client keeps larger — leaves the alternate+ screen a few pixels of local scroll extent. The buffer's `Scrollable` sits+ inside `TerminalScrollGestureHandler`, and a Scrollable with somewhere to go+ wins the trackpad pan and the wheel signal, so the TUI received nothing and+ the pane could not be scrolled. While the alternate screen is up that+ Scrollable now takes no user scrolling; programmatic tail alignment is+ unaffected, and the normal screen still scrolls local history. Regressions:+ `test/terminal_alt_buffer_scroll_test.dart`.++- **The alternate screen's scroll view keeps listening after its position is+ replaced** (`lib/src/ui/infinite_scroll_view.dart`). `attach` listens to the+ `ScrollPosition` with `_onScroll`, but the `position` setter moved+ `markNeedsLayout` instead. `Scrollable` replaces its position whenever its+ dependencies change — the pane grid reparenting a terminal is enough — so+ `_onScroll` stayed on the discarded position and every later wheel or+ trackpad scroll reached nothing: a Claude Code pane scrolled two or three+ times and then stopped for good, with no error anywhere. The setter now moves+ `_onScroll`. Regression: the reparent test in+ `test/terminal_alt_buffer_scroll_test.dart`.+Each of these has to survive an upstream bump — the tests named are what catchit if one is dropped.diff --git a/desktop/third_party/xterm/lib/src/ui/infinite_scroll_view.dart b/desktop/third_party/xterm/lib/src/ui/infinite_scroll_view.dartindex 9640a3cac..08345e1e3 100644--- a/desktop/third_party/xterm/lib/src/ui/infinite_scroll_view.dart+++ b/desktop/third_party/xterm/lib/src/ui/infinite_scroll_view.dart@@ -76,9 +76,12 @@ class _RenderInfiniteScrollView extends RenderShiftedBox {ViewportOffset _position;set position(ViewportOffset value) {if (_position == value) return;- if (attached) _position.removeListener(markNeedsLayout);+ // Move the listener attach() installed. Scrollable replaces its position+ // whenever its dependencies change (a reparent is enough); leaving+ // _onScroll on the discarded one silently stopped every later scroll.+ if (attached) _position.removeListener(_onScroll);_position = value;- if (attached) _position.addListener(markNeedsLayout);+ if (attached) _position.addListener(_onScroll);markNeedsLayout();}diff --git a/desktop/third_party/xterm/lib/src/ui/scroll_handler.dart b/desktop/third_party/xterm/lib/src/ui/scroll_handler.dartindex ad6f0a565..c77406f3a 100644--- a/desktop/third_party/xterm/lib/src/ui/scroll_handler.dart+++ b/desktop/third_party/xterm/lib/src/ui/scroll_handler.dart@@ -141,7 +141,18 @@ class _TerminalScrollGestureHandlerState},child: InfiniteScrollView(onScroll: _onScroll,- child: widget.child,+ // The alternate screen has no history to read, but the buffer's own+ // Scrollable can still have extent here: a remote grid taller than the+ // pane (`resizeBuffer: false`). A Scrollable with somewhere to go wins+ // the trackpad pan and the wheel signal from this view, so the program+ // received nothing. It takes no user scrolling while the alternate+ // screen is up; programmatic tail alignment is unaffected.+ child: ScrollConfiguration(+ behavior: ScrollConfiguration.of(+ context,+ ).copyWith(physics: const NeverScrollableScrollPhysics()),+ child: widget.child,+ ),),);}