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.

Allow pane splits to grow beyond the viewport (#171)

Deeee52ab10cfdc
diff --git a/desktop/design/review/pane-split-seven.png b/desktop/design/review/pane-split-seven.png
new file mode 100644
index 000000000..d4cb30f6a
Binary files /dev/null and b/desktop/design/review/pane-split-seven.png differ
diff --git a/desktop/design/review/pane-split-six.png b/desktop/design/review/pane-split-six.png
new file mode 100644
index 000000000..84db3aa85
Binary files /dev/null and b/desktop/design/review/pane-split-six.png differ
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 204826c0a..0c175b126 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -7885,7 +7885,7 @@ class AppNotifier extends ChangeNotifier {
/// not as a step.
void focusPaneVertically(int delta) {
final to = _neighbour(dx: 0, dy: delta) ?? _wrapVertically(delta);
- if (to != null) focusPane(panes[to].id);
+ if (to != null) focusPane(panes[to].id, reveal: true);
}
/// The tile at the far end of this column — ⌘j off the bottom row, ⌘k off the
@@ -7948,12 +7948,12 @@ class AppNotifier extends ChangeNotifier {
if (railFocused) {
if (panes.isEmpty) return;
unfocusRail();
- focusPane(delta < 0 ? panes.last.id : panes.first.id);
+ focusPane(delta < 0 ? panes.last.id : panes.first.id, reveal: true);
return;
}
final to = _neighbour(dx: delta, dy: 0);
if (to != null) {
- focusPane(panes[to].id);
+ focusPane(panes[to].id, reveal: true);
return;
}
if (hasNavigationRail) focusRail();
@@ -7963,7 +7963,7 @@ class AppNotifier extends ChangeNotifier {
// would simply do nothing at the edge, which is the exact behaviour the ring
// exists to remove.
if (!railFocused && panes.isNotEmpty) {
- focusPane(delta < 0 ? panes.last.id : panes.first.id);
+ focusPane(delta < 0 ? panes.last.id : panes.first.id, reveal: true);
}
}
@@ -8043,7 +8043,7 @@ class AppNotifier extends ChangeNotifier {
_previousPaneId = null;
return;
}
- focusPane(back);
+ focusPane(back, reveal: true);
}
/// ⌘⏎ — one pane filling the grid, and back.
@@ -8072,7 +8072,7 @@ class AppNotifier extends ChangeNotifier {
/// show it — a key meant only to look, rearranging the desk.
void focusPaneByIndex(int index) {
if (index < 0 || index >= panes.length) return;
- focusPane(panes[index].id);
+ focusPane(panes[index].id, reveal: true);
}
/// Walk the focus one tile — ⌘← / ⌘→, and ⌘[ / ⌘].
@@ -8084,7 +8084,7 @@ class AppNotifier extends ChangeNotifier {
if (panes.length < 2) return;
final at = panes.indexWhere((pane) => pane.id == focusedPaneId);
final next = at < 0 ? 0 : (at + delta + panes.length) % panes.length;
- focusPane(panes[next].id);
+ focusPane(panes[next].id, reveal: true);
}
/// Move the focused pane one slot, for the keyboard twin of the drag.
diff --git a/desktop/lib/state/pane_arrangement.dart b/desktop/lib/state/pane_arrangement.dart
index 84513d730..710d0f6a7 100644
--- a/desktop/lib/state/pane_arrangement.dart
+++ b/desktop/lib/state/pane_arrangement.dart
@@ -29,10 +29,43 @@ class PaneArrangement {
required Size minimum,
}) {
if (index < 0 || index >= tiles.length || tiles.length >= 64) return null;
- final tile = tiles[index];
final x = axis == PaneResizeAxis.x;
- if (x ? tile.width / 2 < minimum.width : tile.height / 2 < minimum.height) {
- return null;
+ var layout = tiles;
+ var tile = layout[index];
+ final floor = x ? minimum.width : minimum.height;
+ final length = x ? tile.width : tile.height;
+ // A small pane still splits: insert room along its band, then normalize
+ // the expanded canvas. Other bands keep their physical size. Stretching
+ // the whole layout on every split would grow it exponentially.
+ final extra = math.max(0.0, 2 * floor - length);
+ if (extra > 0) {
+ final start = x ? tile.left : tile.top;
+ final end = x ? tile.right : tile.bottom;
+ double expand(double value) =>
+ (value +
+ (value <= start
+ ? 0
+ : value >= end
+ ? extra
+ : (value - start) / length * extra)) /
+ (1 + extra);
+ layout = [
+ for (final current in layout)
+ x
+ ? Rect.fromLTRB(
+ expand(current.left),
+ current.top,
+ expand(current.right),
+ current.bottom,
+ )
+ : Rect.fromLTRB(
+ current.left,
+ expand(current.top),
+ current.right,
+ expand(current.bottom),
+ ),
+ ];
+ tile = layout[index];
}
final first = x
? Rect.fromLTRB(tile.left, tile.top, tile.center.dx, tile.bottom)
@@ -41,10 +74,10 @@ class PaneArrangement {
? Rect.fromLTRB(tile.center.dx, tile.top, tile.right, tile.bottom)
: Rect.fromLTRB(tile.left, tile.center.dy, tile.right, tile.bottom);
return PaneArrangement([
- ...tiles.take(index),
+ ...layout.take(index),
first,
second,
- ...tiles.skip(index + 1),
+ ...layout.skip(index + 1),
]);
}
diff --git a/desktop/lib/widgets/pane_grid.dart b/desktop/lib/widgets/pane_grid.dart
index 8bc120ee3..7c37d75e2 100644
--- a/desktop/lib/widgets/pane_grid.dart
+++ b/desktop/lib/widgets/pane_grid.dart
@@ -240,7 +240,8 @@ class _SwarmCanvas extends StatefulWidget {
class _SwarmCanvasState extends State<_SwarmCanvas> {
final _scroll = ScrollController(keepScrollOffset: false);
- final _offsets = <String, double>{};
+ final _horizontalScroll = ScrollController(keepScrollOffset: false);
+ final _offsets = <String, Offset>{};
final _inputLayers = <int, GlobalKey<_PaneLayerState>>{};
final _idleFocus = FocusNode(
debugLabel: 'Swarm navigation',
@@ -285,6 +286,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
_resizeRequest = widget.notifier.paneResizeRequest;
_lastInputDestination = _inputDestination;
if (_scroll.hasClients) _scroll.jumpTo(0);
+ if (_horizontalScroll.hasClients) _horizontalScroll.jumpTo(0);
}
}
@@ -301,11 +303,16 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
}
if (_activeId != app.activeSwarmId) {
if (_resizeHelp.isShowing) _resizeHelp.hide();
- if (_scroll.hasClients) _offsets[_activeId] = _scroll.offset;
+ _offsets[_activeId] = Offset(
+ _horizontalScroll.hasClients ? _horizontalScroll.offset : 0,
+ _scroll.hasClients ? _scroll.offset : 0,
+ );
_activeId = app.activeSwarmId;
// The notification precedes the frame. Restore before layout/paint so
// switching never briefly displays the previous Swarm's scroll offset.
- if (_scroll.hasClients) _scroll.jumpTo(_offsets[_activeId] ?? 0);
+ final offset = _offsets[_activeId] ?? Offset.zero;
+ if (_scroll.hasClients) _scroll.jumpTo(offset.dy);
+ if (_horizontalScroll.hasClients) _horizontalScroll.jumpTo(offset.dx);
final open = app.swarms.map((s) => s.id).toSet();
_offsets.removeWhere((id, _) => !open.contains(id));
}
@@ -356,25 +363,43 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
sizes: app.activeSwarm.paneSizes,
);
final rect = geometry.rectangles[index];
- final current = _scroll.offset;
- final offset = rect.top < current || rect.height > viewport.height
- ? rect.top
- : rect.bottom > current + viewport.height
- ? rect.bottom - viewport.height
- : current;
- final target = offset.clamp(
- 0.0,
- (geometry.height - viewport.height).clamp(0.0, double.infinity),
- );
- if (target != current) {
- if (correctingLayout) {
- // The incoming viewport size will lay out the scroll view immediately
- // after this LayoutBuilder. Correct without notifying during layout.
- _scroll.position.correctPixels(target);
- } else {
- _scroll.jumpTo(target);
+ void reveal(
+ ScrollController scroll,
+ double start,
+ double end,
+ double viewportExtent,
+ double canvasExtent,
+ ) {
+ if (!scroll.hasClients) return;
+ final current = scroll.offset;
+ final offset = start < current || end - start > viewportExtent
+ ? start
+ : end > current + viewportExtent
+ ? end - viewportExtent
+ : current;
+ final target = offset.clamp(
+ 0.0,
+ (canvasExtent - viewportExtent).clamp(0.0, double.infinity),
+ );
+ if (target != current) {
+ if (correctingLayout) {
+ // Correct before the scroll view lays out, without notifying during
+ // layout. Both axes retain their controllers and terminal children.
+ scroll.position.correctPixels(target);
+ } else {
+ scroll.jumpTo(target);
+ }
}
}
+
+ reveal(_scroll, rect.top, rect.bottom, viewport.height, geometry.height);
+ reveal(
+ _horizontalScroll,
+ rect.left,
+ rect.right,
+ viewport.width,
+ geometry.width,
+ );
}
void _onFontChanged() => setState(() {});
@@ -386,6 +411,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
_resizeFocus.dispose();
_idleFocus.dispose();
_scroll.dispose();
+ _horizontalScroll.dispose();
super.dispose();
}
@@ -469,7 +495,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
app.activeSwarm.arrangedKey = layout.key;
final minimum = _MinTile.of();
app.activeSwarm.arrangedMinimum = Size(
- (minimum.width + kPaneGap) / (constraints.maxWidth + kPaneGap),
+ (minimum.width + kPaneGap) / (layout.width + kPaneGap),
(minimum.height + kPaneGap) / (layout.height + kPaneGap),
);
}
@@ -480,58 +506,78 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
};
final retainedIds = app.allPanes.map((pane) => pane.id).toSet();
_inputLayers.removeWhere((id, _) => !retainedIds.contains(id));
- // The scroll view stays mounted even when content fits. Its maximum
- // extent is then zero; keeping its ancestry is what avoids grafting.
+ final scrollBehavior = ScrollConfiguration.of(context);
+ // Both scroll views stay mounted when content fits. Stable ancestry
+ // retains terminal views as a split grows or shrinks the canvas.
return Focus(
focusNode: _idleFocus,
includeSemantics: false,
- child: SingleChildScrollView(
- controller: _scroll,
- child: SizedBox(
- width: constraints.maxWidth,
- height: layout.height,
- child: Stack(
- children: [
- if (visible.isEmpty)
- Positioned.fill(
- child: widget.empty ?? _EmptyGrid(notifier: app),
- ),
- for (final pane in app.allPanes)
- if (rectangles.containsKey(pane.id) ||
- pane.lastViewSize != null)
- Positioned.fromRect(
- key: ValueKey(pane.id),
- rect:
- rectangles[pane.id] ??
- Offset.zero & pane.lastViewSize!,
- child: _PaneLayer(
- key: _inputLayers.putIfAbsent(
- pane.id,
- () => GlobalKey<_PaneLayerState>(),
- ),
- session: pane.session,
- visible: rectangles.containsKey(pane.id),
- presentation: _presentation(
- pane,
- rectangles.containsKey(pane.id),
- ),
- child: _PaneCell(
- key: pane.cellKey,
- notifier: app,
- pane: pane,
- dragging: widget.dragging,
- visible: rectangles.containsKey(pane.id),
- swarmMode: true,
- onSplit: widget.onSplit,
- ),
- ),
+ child: Scrollbar(
+ key: const ValueKey('swarm-horizontal-scrollbar'),
+ controller: _horizontalScroll,
+ thumbVisibility: layout.width > constraints.maxWidth,
+ scrollbarOrientation: ScrollbarOrientation.bottom,
+ notificationPredicate: (notification) =>
+ notification.depth == 1 &&
+ notification.metrics.axis == Axis.horizontal,
+ // Keep the horizontal thumb at the viewport's bottom even when the
+ // workspace also scrolls vertically. Terminals retain their bars.
+ child: SingleChildScrollView(
+ controller: _scroll,
+ child: ScrollConfiguration(
+ behavior: scrollBehavior.copyWith(scrollbars: false),
+ child: SingleChildScrollView(
+ controller: _horizontalScroll,
+ scrollDirection: Axis.horizontal,
+ child: ScrollConfiguration(
+ behavior: scrollBehavior,
+ child: SizedBox(
+ width: layout.width,
+ height: layout.height,
+ child: Stack(
+ children: [
+ if (visible.isEmpty)
+ Positioned.fill(
+ child: widget.empty ?? _EmptyGrid(notifier: app),
+ ),
+ for (final pane in app.allPanes)
+ if (rectangles.containsKey(pane.id) ||
+ pane.lastViewSize != null)
+ Positioned.fromRect(
+ key: ValueKey(pane.id),
+ rect:
+ rectangles[pane.id] ??
+ Offset.zero & pane.lastViewSize!,
+ child: _PaneLayer(
+ key: _inputLayers.putIfAbsent(
+ pane.id,
+ () => GlobalKey<_PaneLayerState>(),
+ ),
+ session: pane.session,
+ visible: rectangles.containsKey(pane.id),
+ presentation: _presentation(
+ pane,
+ rectangles.containsKey(pane.id),
+ ),
+ child: _PaneCell(
+ key: pane.cellKey,
+ notifier: app,
+ pane: pane,
+ dragging: widget.dragging,
+ visible: rectangles.containsKey(pane.id),
+ swarmMode: true,
+ onSplit: widget.onSplit,
+ ),
+ ),
+ ),
+ if (app.zoomedPaneId == null &&
+ layout.arrangement?.dividers.isNotEmpty == true)
+ Positioned.fill(child: _resizeLayer(layout)),
+ ],
),
- if (app.zoomedPaneId == null &&
- layout.arrangement?.dividers.isNotEmpty == true)
- Positioned.fill(
- child: _resizeLayer(layout, constraints.biggest),
),
- ],
+ ),
+ ),
),
),
),
@@ -539,7 +585,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
},
);
- Widget _resizeLayer(_SwarmGeometry layout, Size viewport) {
+ Widget _resizeLayer(_SwarmGeometry layout) {
final app = widget.notifier;
final swarmId = app.activeSwarmId;
final arrangement = layout.arrangement!;
@@ -549,7 +595,7 @@ class _SwarmCanvasState extends State<_SwarmCanvas> {
final preferred = arrangement.dividers
.where((divider) => divider.touches(focused))
.firstOrNull;
- final extent = Size(viewport.width + kPaneGap, layout.height + kPaneGap);
+ final extent = Size(layout.width + kPaneGap, layout.height + kPaneGap);
final floor = _MinTile.of();
final minimum = Size(
(floor.width + kPaneGap) / extent.width,
@@ -666,7 +712,8 @@ class _SwarmGeometry {
required PanePreset? preset,
required Size minimum,
Map<String, PaneArrangement> sizes = const {},
- }) : height = viewport.height {
+ }) : width = viewport.width,
+ height = viewport.height {
if (count == 0) return;
if (count == 1) {
rectangles = [Offset.zero & viewport];
@@ -696,6 +743,12 @@ class _SwarmGeometry {
arrangement =
sizes[key] ?? PaneArrangement(shape.tilesFor(count, columns: columns));
for (final tile in arrangement!.tiles) {
+ if (manual != null) {
+ width = ((minimum.width + kPaneGap) / tile.width - kPaneGap).clamp(
+ width,
+ double.infinity,
+ );
+ }
height = ((minimum.height + kPaneGap) / tile.height - kPaneGap).clamp(
height,
double.infinity,
@@ -704,9 +757,9 @@ class _SwarmGeometry {
rectangles = [
for (final tile in arrangement!.tiles)
Rect.fromLTWH(
- tile.left * (viewport.width + kPaneGap),
+ tile.left * (width + kPaneGap),
tile.top * (height + kPaneGap),
- (tile.width * (viewport.width + kPaneGap) - kPaneGap).clamp(
+ (tile.width * (width + kPaneGap) - kPaneGap).clamp(
0,
double.infinity,
),
@@ -719,7 +772,7 @@ class _SwarmGeometry {
}
String? key;
PaneArrangement? arrangement;
- double height;
+ double width, height;
int? columns;
List<Rect> rectangles = const [];
}
diff --git a/desktop/test/pane_arrangement_test.dart b/desktop/test/pane_arrangement_test.dart
index 5cd9afec6..a3f79f9cb 100644
--- a/desktop/test/pane_arrangement_test.dart
+++ b/desktop/test/pane_arrangement_test.dart
@@ -6,6 +6,68 @@ import 'package:harness/state/pane_arrangement.dart';
import 'package:harness/state/pane_preset.dart';
void main() {
+ for (final axis in PaneResizeAxis.values) {
+ test(
+ 'small ${axis.name} splits grow linearly through the pane capacity',
+ () {
+ const viewport = Size(1280, 768);
+ const floor = Size(400, 240);
+ var extent = viewport;
+ var layout = PaneArrangement(PanePreset.middleMain.tilesFor(5));
+ for (var count = 5; count < 64; count++) {
+ final next = layout.split(
+ count - 1,
+ axis,
+ minimum: Size(
+ floor.width / extent.width,
+ floor.height / extent.height,
+ ),
+ );
+ expect(next, isNotNull);
+ layout = next!;
+ extent = Size(
+ max(
+ viewport.width,
+ floor.width / layout.tiles.map((tile) => tile.width).reduce(min),
+ ),
+ max(
+ viewport.height,
+ floor.height /
+ layout.tiles.map((tile) => tile.height).reduce(min),
+ ),
+ );
+ expect(PaneArrangement.fromJson(layout.toJson()), isNotNull);
+ expect(
+ layout.tiles.fold<double>(
+ 0,
+ (area, tile) => area + tile.width * tile.height,
+ ),
+ closeTo(1, .000001),
+ );
+ // Repeatedly splitting the newest small tile must add usable space,
+ // without magnifying the entire workspace on every split.
+ expect(
+ extent.width,
+ lessThanOrEqualTo(viewport.width + floor.width * count),
+ );
+ expect(
+ extent.height,
+ lessThanOrEqualTo(viewport.height + floor.height * count),
+ );
+ expect(
+ layout.tiles.last.width * extent.width,
+ greaterThanOrEqualTo(floor.width - .001),
+ );
+ expect(
+ layout.tiles.last.height * extent.height,
+ greaterThanOrEqualTo(floor.height - .001),
+ );
+ }
+ expect(layout.split(63, axis, minimum: Size.zero), isNull);
+ },
+ );
+ }
+
test('nested splits and local close repairs retain complete nonoverlapping coverage', () {
final random = Random(17);
for (var trial = 0; trial < 30; trial++) {
diff --git a/desktop/test/swarm_canvas_test.dart b/desktop/test/swarm_canvas_test.dart
index 402138417..38538dd30 100644
--- a/desktop/test/swarm_canvas_test.dart
+++ b/desktop/test/swarm_canvas_test.dart
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/state/pane_arrangement.dart';
import 'package:harness/state/pane_preset.dart';
import 'package:harness/terminal/terminal_font_store.dart';
import 'package:harness/widgets/pane_grid.dart';
@@ -104,7 +105,7 @@ void main() {
);
testWidgets(
- 'scroll positions restore on the first frame across different Swarm sizes',
+ 'both scroll positions restore on the first frame across different Swarm sizes',
(tester) async {
final app = createApp();
app.machineStates['m']!.nodeOnline = true;
@@ -112,16 +113,24 @@ void main() {
app.adoptSessionForTest(terminal('a$i', []));
}
app.setPreset(12, PanePreset.cols2);
+ app.activeSwarm.savePaneSizes(
+ '12:manual',
+ PaneArrangement(PanePreset.cols2.tilesFor(12)),
+ );
final first = app.activeSwarmId;
app.newSwarm();
for (var i = 12; i < 18; i++) {
app.adoptSessionForTest(terminal('a$i', []));
}
app.setPreset(6, PanePreset.cols2);
+ app.activeSwarm.savePaneSizes(
+ '6:manual',
+ PaneArrangement(PanePreset.cols2.tilesFor(6)),
+ );
final second = app.activeSwarmId;
app.selectSwarm(first);
tester.view.devicePixelRatio = 1;
- tester.view.physicalSize = const Size(1000, 500);
+ tester.view.physicalSize = const Size(600, 500);
addTearDown(tester.view.reset);
await tester.pumpWidget(
MaterialApp(home: PaneGrid(notifier: app, swarmMode: true)),
@@ -135,28 +144,49 @@ void main() {
scroll.jumpTo(600);
await tester.pump();
expect(scroll.position.maxScrollExtent, greaterThan(600));
+ final horizontal = tester
+ .widgetList<SingleChildScrollView>(find.byType(SingleChildScrollView))
+ .singleWhere((view) => view.scrollDirection == Axis.horizontal)
+ .controller!;
+ expect(horizontal.position.maxScrollExtent, greaterThan(200));
+ // The horizontal thumb remains reachable while vertically scrolled.
+ await tester.pump(const Duration(milliseconds: 300));
+ await tester.dragFrom(const Offset(60, 497), const Offset(80, 0));
+ await tester.pump();
+ expect(horizontal.offset, greaterThan(0));
+ expect(scroll.offset, 600);
+ horizontal.jumpTo(200);
+ await tester.pump();
app.selectSwarm(second);
await tester.pump();
expect(scroll.offset, 0);
+ expect(horizontal.offset, 0);
scroll.jumpTo(120);
+ horizontal.jumpTo(90);
await tester.pump();
app.selectSwarm(first);
await tester.pump();
expect(scroll.offset, 600);
+ expect(horizontal.offset, 200);
app.selectSwarm(second);
await tester.pump();
expect(scroll.offset, 120);
+ expect(horizontal.offset, 90);
app.newSwarm();
await tester.pump();
expect(scroll.offset, 0);
expect(scroll.position.maxScrollExtent, 0);
+ expect(horizontal.offset, 0);
+ expect(horizontal.position.maxScrollExtent, 0);
app.selectSwarm(first);
await tester.pump();
expect(scroll.offset, 600);
+ expect(horizontal.offset, 200);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
app.dispose();
},
+ variant: TargetPlatformVariant.only(TargetPlatform.macOS),
);
testWidgets(
diff --git a/desktop/test/swarm_split_test.dart b/desktop/test/swarm_split_test.dart
index b40960669..6101acf4b 100644
--- a/desktop/test/swarm_split_test.dart
+++ b/desktop/test/swarm_split_test.dart
@@ -59,6 +59,149 @@ void main() {
final title = axis == PaneResizeAxis.x
? 'New Pane to the Right'
: 'New Pane Below';
+ testWidgets('five-pane side tile can split $direction with scrolling', (
+ tester,
+ ) async {
+ final store = MemoryStore();
+ final app = createApp(store: store);
+ final machine = app.machineStates['m']!;
+ machine.nodeOnline = true;
+ machine.localOnly = true;
+ machine.agents[5] = const Agent(
+ id: 'a5',
+ name: 'Sixth helper',
+ engine: 'codex',
+ terminalAvailable: true,
+ );
+ final frames = <TerminalBinaryFrame>[];
+ final original = [
+ for (var i = 0; i < 5; i++)
+ app.adoptSessionForTest(terminal('a$i', frames)),
+ ];
+ final swarm = app.activeSwarm;
+ app.setPreset(5, PanePreset.middleMain);
+ app.newSwarm();
+ final helper = app.adoptSessionForTest(terminal('a5', frames));
+ app.selectSwarm(swarm.id);
+ final target = original[3];
+ app.focusPane(target.id);
+ await mount(tester, app);
+ final view = find.descendant(
+ of: find.byKey(target.cellKey),
+ matching: find.byType(TerminalView),
+ );
+ final retained = tester.element(view);
+ final button = find.descendant(
+ of: find.byKey(target.cellKey),
+ matching: find.byKey(ValueKey('pane-split-$direction')),
+ );
+ expect(tester.widget<IconButton>(button).onPressed, isNotNull);
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ final targetRect = tester.getRect(find.byKey(target.cellKey));
+ await mouse.addPointer(location: targetRect.center);
+ await mouse.moveTo(
+ axis == PaneResizeAxis.x
+ ? Offset(targetRect.right - 2, targetRect.center.dy)
+ : Offset(targetRect.center.dx, targetRect.bottom - 2),
+ );
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 120));
+ expect(button.hitTestable(), findsOneWidget);
+ await tester.tap(button);
+ await tester.pump();
+ expect(find.text(title), findsOneWidget);
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pump();
+ expect(app.panes, original);
+ await chord(
+ tester,
+ axis == PaneResizeAxis.x
+ ? LogicalKeyboardKey.keyR
+ : LogicalKeyboardKey.keyD,
+ );
+ final search = find.byKey(const ValueKey('swarm-search-input'));
+ expect(search, findsOneWidget);
+ await tester.enterText(search, 'Sixth helper');
+ await tester.pump();
+ await tester.sendKeyEvent(LogicalKeyboardKey.enter);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(app.panes, [...original.take(4), helper, original.last]);
+ expect(tester.element(view), same(retained));
+ final before = tester.getRect(find.byKey(target.cellKey));
+ final after = tester.getRect(find.byKey(helper.cellKey));
+ if (axis == PaneResizeAxis.x) {
+ expect(after.left, greaterThan(before.right));
+ expect(after.top, before.top);
+ } else {
+ expect(after.top, greaterThan(before.bottom));
+ expect(after.left, before.left);
+ }
+ final viewport = tester.view.physicalSize;
+ expect(after.left, greaterThanOrEqualTo(0));
+ expect(after.top, greaterThanOrEqualTo(0));
+ expect(after.right, lessThanOrEqualTo(viewport.width));
+ expect(after.bottom, lessThanOrEqualTo(viewport.height));
+ final canvasScrolls = tester
+ .widgetList<SingleChildScrollView>(find.byType(SingleChildScrollView))
+ .where((widget) => widget.controller != null);
+ final scroll = canvasScrolls
+ .singleWhere(
+ (widget) =>
+ widget.scrollDirection ==
+ (axis == PaneResizeAxis.x ? Axis.horizontal : Axis.vertical),
+ )
+ .controller!;
+ expect(scroll.position.maxScrollExtent, greaterThan(0));
+ // Directional focus also reveals an existing pane outside the viewport.
+ app.focusPane(original[2].id);
+ await chord(tester, LogicalKeyboardKey.arrowDown);
+ await tester.pump();
+ expect(app.focusedPaneId, original.last.id);
+ expect(
+ tester.getRect(find.byKey(original.last.cellKey)).right,
+ lessThanOrEqualTo(viewport.width + .001),
+ );
+ app.focusPane(original.last.id);
+ await chord(tester, LogicalKeyboardKey.arrowLeft);
+ await tester.pump();
+ expect(app.focusedPaneId, original[1].id);
+ final focused = tester.getRect(find.byKey(original[1].cellKey));
+ expect(focused.left, greaterThanOrEqualTo(0));
+ expect(focused.right, lessThanOrEqualTo(viewport.width + .001));
+ app.focusPane(helper.id, reveal: true);
+ await tester.pump();
+ expect(frames, isEmpty);
+ await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
+ await tester.pump(const Duration(milliseconds: 10));
+ expect(frames.single.streamId, helper.session!.streamId);
+ final savedTiles = app.activeSwarm.manualLayout!.tiles;
+ final savedExtent = scroll.position.maxScrollExtent;
+ await app.flushPaneLayout();
+ await mouse.removePointer();
+ await tester.pumpWidget(const SizedBox());
+ app.dispose();
+ final restored = createApp(store: store);
+ await restored.restorePaneLayoutForTest();
+ await mount(tester, restored);
+ expect(restored.activeSwarm.manualLayout!.tiles, savedTiles);
+ final restoredScroll = tester
+ .widgetList<SingleChildScrollView>(find.byType(SingleChildScrollView))
+ .where((view) => view.controller != null)
+ .singleWhere(
+ (view) =>
+ view.scrollDirection ==
+ (axis == PaneResizeAxis.x ? Axis.horizontal : Axis.vertical),
+ )
+ .controller!;
+ expect(
+ restoredScroll.position.maxScrollExtent,
+ closeTo(savedExtent, .001),
+ );
+ await tester.pumpWidget(const SizedBox());
+ restored.dispose();
+ });
+
for (final trigger in ['shortcut', 'palette', 'native menu']) {
testWidgets('$trigger splits the focused pane $direction', (
tester,
@@ -329,7 +472,7 @@ void main() {
app.selectSwarm(original);
app.focusPane(first.id);
await mountWide(tester, app);
- expect(app.preparePaneSplit(PaneResizeAxis.x), isNull);
+ expect(app.preparePaneSplit(PaneResizeAxis.x), isNotNull);
tester.view.physicalSize = const Size(3000, 1800);
await tester.pump();
final unchanged = [second, third];
@@ -449,14 +592,19 @@ void main() {
expect(app.panes, isEmpty);
expect(
original.panes.map((p) => p.agentId),
- change == 'switch' ? ['a0', 'a1', 'created'] : ['a0', 'a1'],
+ change == 'switch' || change == 'window'
+ ? ['a0', 'a1', 'created']
+ : ['a0', 'a1'],
+ );
+ expect(
+ original.manualLayout != null,
+ change == 'switch' || change == 'window',
);
- expect(original.manualLayout != null, change == 'switch');
expect(
app.machineStates['m']!.agents.any((a) => a.id == 'created'),
isTrue,
);
- if (change != 'switch') {
+ if (change != 'switch' && change != 'window') {
expect(app.lastError, contains('harness started'));
}
expect(connection.calls, isNot(contains('agent_delete')));
diff --git a/docs/keyboard.md b/docs/keyboard.md
index 4947401b9..5df7e0d7b 100644
--- a/docs/keyboard.md
+++ b/docs/keyboard.md
@@ -29,6 +29,8 @@ In the New Tab and New Pane pickers, New agent is selected when the query is emp
Hover near a pane’s right or bottom edge to reveal its **+** button, or use **File → Split Right… / Split Down…**. The picker shows **New Pane to the Right** or **New Pane Below**. The split is applied after choosing or creating a harness; Escape leaves the layout unchanged.
+When a split needs more room, the workspace expands and scrolls to keep both panes readable. Keyboard focus brings the selected pane into view. Splitting remains available up to the tab’s 64-pane limit.
+
In a picker: ↓ ⌃N ⌃J and ↑ ⌃P ⌃K move, ⏎ accepts, and Esc, ⌃C, or ⌃G closes. In the New Tab and New Pane pickers, ⌘⏎ accepts into the same requested destination. Preview starts hidden; ⌃/ toggles it and Page Up/Down scroll it without leaving the search input.
The terminal keeps ⌘C, ⌘V, ⌘A, Esc, ⌥⏎ and ⌃C for itself. `pane.pin`, `pane.focus_1…9`,
`pane.resize`, `pane.reset_sizes`, `machine.link` and a few others ship unbound and are in the palette.