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
feat(web): scroll an overflowing tab strip by arrows and mouse wheel
Dev jacob62f2fceb6fae
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dartindex f0e727769..80eb19f97 100644--- a/desktop/lib/screens/swarm_screen.dart+++ b/desktop/lib/screens/swarm_screen.dart@@ -74,6 +74,7 @@ import '../widgets/workspace_status_line.dart';import '../widgets/workspace_pull_request_label.dart';import '../widgets/workspace_bar_control.dart';import '../widgets/workspace_tab_close.dart';+import '../widgets/workspace_tab_scroller.dart';import '../widgets/session_work_dialog.dart';import '../widgets/web_download_button.dart';import '../widgets/workspace_share_button.dart';@@ -6830,7 +6831,13 @@ class _SwarmScreenState extends State<SwarmScreen> {),];final total = _tabWidths.fold(0.0, (sum, width) => sum + width);- final tabsWidth = math.min(total, tabBudget);+ // Arrows come out of the tabs' own budget, so the bar never reflows.+ final arrows = chrome?.scrollsTabsByArrows == true && total > tabBudget;+ final tabsWidth = math.max(+ 0.0,+ math.min(total, tabBudget) -+ (arrows ? cell.width * kWorkspaceTabArrowCells * 2 : 0),+ );_revealSelectedTab(tabsWidth);return Material(key: const ValueKey('workspace-tab-bar'),@@ -6845,104 +6852,100 @@ class _SwarmScreenState extends State<SwarmScreen> {width: leadingWidth,child: chrome.leading(context, _workspaceCommands),),- SizedBox(- width: tabsWidth,- child: ReorderableListView.builder(- scrollController: _tabScroll,- itemExtentBuilder: (index, _) => _tabWidths[index],- scrollDirection: Axis.horizontal,- shrinkWrap: true,- buildDefaultDragHandles: false,- itemCount: shown.length,- onReorderItem: (old, to) =>- app.reorderSwarm(shown[old].id, to),- itemBuilder: (context, index) {- final swarm = shown[index];- final selected = app.activeSwarmId == swarm.id;- final activity = activities[index];- final nameHint = workspaceTabTooltip(- labels[index],- swarm.name,- clipped:- workspaceBarTextSizeOf(context, labels[index]).width +- (activity == null ? 0 : cell.width * 2) >- _tabWidths[index] - cell.width * 2,- );- final tabHint = [- ?nameHint,- if (activity != null) activity.label,- ].join('\n');- return ReorderableDragStartListener(- key: ValueKey(swarm.id),- index: index,- child: Listener(- onPointerDown: (event) {- _middleDownTab = event.buttons == kTertiaryButton- ? swarm.id- : null;- },- onPointerUp: (event) {- final armed = _middleDownTab;- _middleDownTab = null;- if (armed == swarm.id) {- unawaited(app.closeSwarm(swarm.id));- }- },- child: GestureDetector(- onDoubleTap: () => _rename(swarm.id),- child: Center(- child: WorkspaceBarControl(- label:- '${labels[index]}: ${swarm.name}${activity == null ? '' : ', ${activity.label}'}',- tooltip: tabHint.isEmpty ? null : tabHint,- selectedBackground: grid.AppPalette.swarmWelcome,- selected: selected,- highlighted:- selected &&- app.tabStripFocused &&- _tabStripFocus.hasPrimaryFocus,- onPressed: _shortcutsEnabled- ? () => app.selectSwarm(swarm.id)- : null,- builder: (context, emphasized) => SizedBox(- height: double.infinity,- child: Padding(- padding: EdgeInsets.symmetric(- horizontal: cell.width,- ),- child: _withTabClose(- closeCells > 0,- id: swarm.id,- visible: selected || emphasized,- color: theme.foreground,- child: Center(- child: activity == null- ? Text(- labels[index],- maxLines: 1,- overflow: TextOverflow.ellipsis,- textAlign: TextAlign.center,- style: workspaceBarTextStyle(- color: theme.foreground,- emphasized: emphasized,- ),- )- : Row(- mainAxisSize: MainAxisSize.min,- children: [- Text(- '${index + 1}:',- style: workspaceBarTextStyle(- color: theme.foreground,- emphasized: emphasized,- ),+ _withTabArrows(+ arrows,+ color: theme.foreground,+ child: SizedBox(+ width: tabsWidth,+ child: ReorderableListView.builder(+ scrollController: _tabScroll,+ itemExtentBuilder: (index, _) => _tabWidths[index],+ scrollDirection: Axis.horizontal,+ shrinkWrap: true,+ buildDefaultDragHandles: false,+ itemCount: shown.length,+ onReorderItem: (old, to) =>+ app.reorderSwarm(shown[old].id, to),+ itemBuilder: (context, index) {+ final swarm = shown[index];+ final selected = app.activeSwarmId == swarm.id;+ final activity = activities[index];+ final nameHint = workspaceTabTooltip(+ labels[index],+ swarm.name,+ clipped:+ workspaceBarTextSizeOf(+ context,+ labels[index],+ ).width ++ (activity == null ? 0 : cell.width * 2) >+ _tabWidths[index] - cell.width * 2,+ );+ final tabHint = [+ ?nameHint,+ if (activity != null) activity.label,+ ].join('\n');+ return ReorderableDragStartListener(+ key: ValueKey(swarm.id),+ index: index,+ child: Listener(+ onPointerDown: (event) {+ _middleDownTab = event.buttons == kTertiaryButton+ ? swarm.id+ : null;+ },+ onPointerUp: (event) {+ final armed = _middleDownTab;+ _middleDownTab = null;+ if (armed == swarm.id) {+ unawaited(app.closeSwarm(swarm.id));+ }+ },+ child: GestureDetector(+ onDoubleTap: () => _rename(swarm.id),+ child: Center(+ child: WorkspaceBarControl(+ label:+ '${labels[index]}: ${swarm.name}${activity == null ? '' : ', ${activity.label}'}',+ tooltip: tabHint.isEmpty ? null : tabHint,+ selectedBackground:+ grid.AppPalette.swarmWelcome,+ selected: selected,+ highlighted:+ selected &&+ app.tabStripFocused &&+ _tabStripFocus.hasPrimaryFocus,+ onPressed: _shortcutsEnabled+ ? () => app.selectSwarm(swarm.id)+ : null,+ builder: (context, emphasized) => SizedBox(+ height: double.infinity,+ child: Padding(+ padding: EdgeInsets.symmetric(+ horizontal: cell.width,+ ),+ child: _withTabClose(+ closeCells > 0,+ id: swarm.id,+ visible: selected || emphasized,+ color: theme.foreground,+ child: Center(+ child: activity == null+ ? Text(+ labels[index],+ maxLines: 1,+ overflow: TextOverflow.ellipsis,+ textAlign: TextAlign.center,+ style: workspaceBarTextStyle(+ color: theme.foreground,+ emphasized: emphasized,),- Flexible(- child: Text(- names[swarm.id]!,- maxLines: 1,- overflow:- TextOverflow.ellipsis,+ )+ : Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ Text(+ '${index + 1}:',style:workspaceBarTextStyle(color:@@ -6951,44 +6954,59 @@ class _SwarmScreenState extends State<SwarmScreen> {emphasized,),),- ),- SizedBox(width: cell.width),- ListenableBuilder(- listenable: _tabScroll,- builder: (context, _) {- final left = _tabWidths- .take(index)- .fold(- 0.0,- (a, b) => a + b,- );- final offset =- _tabScroll.hasClients- ? _tabScroll.offset- : 0.0;- return ActivityMark(- key: ValueKey(- 'tab-activity:${swarm.id}',- ),- activity: activity,- color: activityColor(- activity,- theme,- color: prefs.color,- ),- emphasized: emphasized,- tooltip: false,- visible:- left <- offset +- tabsWidth &&- left + _tabWidths[index] >- offset,- );- },- ),- ],- ),+ Flexible(+ child: Text(+ names[swarm.id]!,+ maxLines: 1,+ overflow:+ TextOverflow.ellipsis,+ style:+ workspaceBarTextStyle(+ color: theme+ .foreground,+ emphasized:+ emphasized,+ ),+ ),+ ),+ SizedBox(width: cell.width),+ ListenableBuilder(+ listenable: _tabScroll,+ builder: (context, _) {+ final left = _tabWidths+ .take(index)+ .fold(+ 0.0,+ (a, b) => a + b,+ );+ final offset =+ _tabScroll.hasClients+ ? _tabScroll.offset+ : 0.0;+ return ActivityMark(+ key: ValueKey(+ 'tab-activity:${swarm.id}',+ ),+ activity: activity,+ color: activityColor(+ activity,+ theme,+ color: prefs.color,+ ),+ emphasized: emphasized,+ tooltip: false,+ visible:+ left <+ offset ++ tabsWidth &&+ left + _tabWidths[index] >+ offset,+ );+ },+ ),+ ],+ ),+ ),),),),@@ -6996,9 +7014,9 @@ class _SwarmScreenState extends State<SwarmScreen> {),),),- ),- );- },+ );+ },+ ),),),_statusToolSymbol(@@ -7077,6 +7095,21 @@ class _SwarmScreenState extends State<SwarmScreen> {/// A host's narrow bar (the web on a phone): its tab switcher in place of/// the tab list, and no Store button, which the host's menu already offers.+ /// The tab list, inside the arrows' scroller whenever the host scrolls tabs+ /// by mouse — drawn only while [arrows], the list overflowing.+ Widget _withTabArrows(+ bool arrows, {+ required Color color,+ required Widget child,+ }) => widget.chrome?.scrollsTabsByArrows != true+ ? child+ : WorkspaceTabScroller(+ controller: _tabScroll,+ arrows: arrows,+ color: color,+ child: child,+ );+/// A tab's label, with a close mark when the host closes tabs by mouse.Widget _withTabClose(bool closes, {diff --git a/desktop/lib/state/workspace_chrome.dart b/desktop/lib/state/workspace_chrome.dartindex 08e30df03..44b4ed0bc 100644--- a/desktop/lib/state/workspace_chrome.dart+++ b/desktop/lib/state/workspace_chrome.dart@@ -47,6 +47,7 @@ class WorkspaceChrome {this.viewMachineCloses = false,this.closesTabs = false,this.showsShareStatus = false,+ this.scrollsTabsByArrows = false,this.compactTabs,this.compactBelow = 0,});@@ -77,6 +78,9 @@ class WorkspaceChrome {/// True marks each shared harness's pane header Public or Private.final bool showsShareStatus;+ /// True puts arrows either side of a tab list too long for the bar.+ final bool scrollsTabsByArrows;+/// Below [compactBelow] of window width the workspace goes compact: this/// replaces the tab list (the Store button steps aside), and only the focused/// harness is drawn — a phone has room for neither a tab row nor a grid.diff --git a/desktop/lib/web/shell/web_chrome.dart b/desktop/lib/web/shell/web_chrome.dartindex 750aecc6d..1ca63470f 100644--- a/desktop/lib/web/shell/web_chrome.dart+++ b/desktop/lib/web/shell/web_chrome.dart@@ -20,6 +20,7 @@ WorkspaceChrome webWorkspaceChrome(AppNotifier app) => WorkspaceChrome(viewMachineCloses: true,closesTabs: true,showsShareStatus: true,+ scrollsTabsByArrows: true,compactTabs: (context, commands) =>WebTabSwitcher(app: app, commands: commands),compactBelow: kWebCompactBelow,diff --git a/desktop/lib/widgets/workspace_tab_scroller.dart b/desktop/lib/widgets/workspace_tab_scroller.dartnew file mode 100644index 000000000..1ad5a0f3b--- /dev/null+++ b/desktop/lib/widgets/workspace_tab_scroller.dart@@ -0,0 +1,156 @@+import 'package:flutter/gestures.dart';+import 'package:flutter/material.dart';+import 'package:lucide_icons_flutter/lucide_icons.dart';++import '../shared/theme/workspace_bar_style.dart';+import 'workspace_bar_control.dart';++/// Cells each arrow takes beside an overflowing tab list.+const int kWorkspaceTabArrowCells = 3;++/// Arrows either side of a tab list that no longer fits, for hosts with no+/// trackpad-sideways habit to lean on ([WorkspaceChrome.scrollsTabsByArrows]).+/// Each arrow pages the list by most of its width and goes faint at its end;+/// a mouse wheel over the strip scrolls it sideways.+class WorkspaceTabScroller extends StatefulWidget {+ const WorkspaceTabScroller({+ super.key,+ required this.controller,+ required this.arrows,+ required this.color,+ required this.child,+ });++ final ScrollController controller;++ /// Whether the list overflows, so the arrows are drawn. They keep their+ /// slots either way: the list never moves in the tree, so it is never+ /// remounted onto the shared controller.+ final bool arrows;+ final Color color;+ final Widget child;++ @override+ State<WorkspaceTabScroller> createState() => _WorkspaceTabScrollerState();+}++class _WorkspaceTabScrollerState extends State<WorkspaceTabScroller> {+ @override+ void initState() {+ super.initState();+ widget.controller.addListener(_changed);+ // The list has no extent until it has laid out once.+ WidgetsBinding.instance.addPostFrameCallback((_) => _changed());+ }++ @override+ void didUpdateWidget(WorkspaceTabScroller oldWidget) {+ super.didUpdateWidget(oldWidget);+ if (oldWidget.controller == widget.controller) return;+ oldWidget.controller.removeListener(_changed);+ widget.controller.addListener(_changed);+ }++ @override+ void dispose() {+ widget.controller.removeListener(_changed);+ super.dispose();+ }++ void _changed() {+ if (mounted) setState(() {});+ }++ // Only while exactly one list is attached; `position` asserts otherwise.+ ScrollPosition? get _position => widget.controller.positions.length == 1+ ? widget.controller.positions.single+ : null;++ void _page(int direction) {+ final position = _position;+ if (position == null) return;+ final target =+ (position.pixels + direction * position.viewportDimension * .8).clamp(+ position.minScrollExtent,+ position.maxScrollExtent,+ );+ widget.controller.animateTo(+ target,+ duration: const Duration(milliseconds: 220),+ curve: Curves.easeOutCubic,+ );+ }++ /// A mouse wheel rolls the strip sideways, as it does over native tabs. A+ /// horizontal list takes only sideways deltas, which a wheel never sends.+ void _wheel(PointerSignalEvent event) {+ if (!widget.arrows || event is! PointerScrollEvent) return;+ final position = _position;+ final delta = event.scrollDelta.dx.abs() > event.scrollDelta.dy.abs()+ ? event.scrollDelta.dx+ : event.scrollDelta.dy;+ if (position == null || delta == 0) return;+ GestureBinding.instance.pointerSignalResolver.register(event, (_) {+ position.jumpTo(+ (position.pixels + delta).clamp(+ position.minScrollExtent,+ position.maxScrollExtent,+ ),+ );+ });+ }++ Widget _arrow(int direction, bool enabled) {+ final cell = workspaceBarCellSizeOf(context);+ final left = direction < 0;+ return WorkspaceBarControl(+ key: ValueKey(left ? 'tab-scroll-left' : 'tab-scroll-right'),+ label: left ? 'Earlier tabs' : 'Later tabs',+ tooltip: left ? 'Earlier tabs' : 'Later tabs',+ onPressed: enabled ? () => _page(direction) : null,+ builder: (context, emphasized) => SizedBox(+ width: cell.width * kWorkspaceTabArrowCells,+ height: workspaceBarControlHeight(context),+ child: Icon(+ left ? LucideIcons.chevronLeft : LucideIcons.chevronRight,+ size: 16,+ color: widget.color.withValues(+ alpha: !enabled+ ? .22+ : emphasized+ ? 1+ : .7,+ ),+ ),+ ),+ );+ }++ Widget _slot(Widget arrow) => widget.arrows ? arrow : const SizedBox.shrink();++ @override+ Widget build(BuildContext context) {+ final position = _position;+ final atStart =+ position == null || position.pixels <= position.minScrollExtent;+ final atEnd =+ position == null || position.pixels >= position.maxScrollExtent;+ return NotificationListener<ScrollMetricsNotification>(+ onNotification: (_) {+ _changed();+ return false;+ },+ child: Listener(+ onPointerSignal: _wheel,+ child: Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ _slot(_arrow(-1, !atStart)),+ widget.child,+ _slot(_arrow(1, !atEnd)),+ ],+ ),+ ),+ );+ }+}diff --git a/desktop/test/web/web_app_menu_test.dart b/desktop/test/web/web_app_menu_test.dartindex 1b7977a09..cc4d8f666 100644--- a/desktop/test/web/web_app_menu_test.dart+++ b/desktop/test/web/web_app_menu_test.dart@@ -1,6 +1,7 @@@TestOn('browser')library;+import 'package:flutter/gestures.dart';import 'package:flutter/material.dart';import 'package:flutter/services.dart';import 'package:flutter_test/flutter_test.dart';@@ -14,6 +15,7 @@ import 'package:harness/state/new_harness.dart';import 'package:harness/web/shell/web_workspace.dart';import 'package:harness/widgets/new_harness_form.dart';import 'package:harness/widgets/swarm_switcher.dart';+import 'package:harness/widgets/workspace_bar_control.dart';Future<AppNotifier> _mount(WidgetTester tester, {@@ -154,6 +156,76 @@ void main() {app.dispose();});+ testWidgets('tabs too many for the bar scroll by arrows and wheel', (+ tester,+ ) async {+ final app = await _mount(tester);+ expect(find.byKey(const ValueKey('tab-scroll-right')), findsNothing);+ for (var i = 0; i < 24; i++) {+ app.newSwarm(newTabPage: true);+ }+ await tester.pump(const Duration(milliseconds: 200));+ // The arrows read the list's extent after it lays out: one more frame.+ await tester.pump();+ final left = find.byKey(const ValueKey('tab-scroll-left'));+ final right = find.byKey(const ValueKey('tab-scroll-right'));+ expect(left, findsOneWidget);+ expect(right, findsOneWidget);+ bool enabled(Finder arrow) =>+ tester.widget<WorkspaceBarControl>(arrow).onPressed != null;+ // The newest tab is selected and revealed: the strip rests at its end.+ expect(enabled(left), isTrue);+ expect(enabled(right), isFalse);+ await tester.tap(left);+ await tester.pump(const Duration(milliseconds: 400));+ expect(enabled(right), isTrue);++ // A plain vertical wheel over the strip moves it sideways.+ final scrollable = tester.state<ScrollableState>(+ find+ .descendant(+ of: find.byKey(const ValueKey('workspace-tab-bar')),+ matching: find.byType(Scrollable),+ )+ .first,+ );+ final before = scrollable.position.pixels;+ await tester.sendEventToBinding(+ PointerScrollEvent(+ position: tester.getCenter(left) + const Offset(80, 0),+ scrollDelta: const Offset(0, -120),+ ),+ );+ await tester.pump();+ expect(scrollable.position.pixels, lessThan(before));+ expect(tester.takeException(), isNull);+ await tester.pumpWidget(const SizedBox.shrink());+ app.dispose();+ });++ testWidgets('crossing into and out of overflow keeps one tab list', (+ tester,+ ) async {+ final app = await _mount(tester);+ for (var i = 0; i < 12; i++) {+ app.newSwarm(newTabPage: true);+ }+ for (final width in [1800.0, 900.0, 1800.0, 700.0, 1280.0]) {+ tester.view.physicalSize = Size(width, 800);+ await tester.pump();+ await tester.pump();+ expect(tester.takeException(), isNull, reason: 'width $width');+ }+ while (app.swarms.length > 2) {+ await app.closeSwarm(app.swarms.last.id);+ await tester.pump();+ await tester.pump();+ expect(tester.takeException(), isNull, reason: '${app.swarms.length}');+ }+ await tester.pumpWidget(const SizedBox.shrink());+ app.dispose();+ });+testWidgets('keys still reach Settings beside the menu', (tester) async {final app = await _mount(tester);await tester.sendKeyDownEvent(LogicalKeyboardKey.altLeft);