Float several chats and keep them working on every tab

Floating chats were stuck on other destinations: the hidden Chat tab
muted the window's hide animation, so the window stayed painted but took
no input. The reveal now uses its own ticker, each floating pane's focus
scope hangs from a FloatingFocusRoot above the destination stack, and the
windows show over every destination like the terminal.

Any number of chats can float; the shortcut, a window's X and the menu
show or hide them together. Each pane keeps its own frame (also while
docked), saved in record version 2; version 1 records still load. Drags
read the live frame so fast pointer events no longer lose movement.
This commit is contained in:
2026-11-10 15:26:38 +00:00
parent 827d9bd3b5
commit cdd54c113c
25 changed files with 962 additions and 419 deletions
@@ -237,7 +237,7 @@ void main() {
expect(widthOf(tester, 'two'), 1368 - 12 - 950);
expect(find.byType(ChatCenterStageStrip), findsNothing);
workspace.dock();
workspace.dock(workspace.floatingPanes.single.id);
await tester.pumpAndSettle();
expect(workspace.activePane?.sessionId, 'one');
expect(widthOf(tester, 'one'), 950);
@@ -42,7 +42,7 @@ class _Harness {
final controller = ChatWorkspaceController()
..open('a')
..splitActive('b', ChatSplitAxis.horizontal);
final frame = ChatFloatFrame();
final frames = ChatFloatFrames();
final typing = FocusNode(debugLabel: 'terminal');
final typed = <LogicalKeyboardKey>[];
@@ -53,7 +53,7 @@ class _Harness {
Expanded(
child: ChatWorkspace(
controller: controller,
floatFrame: frame,
floatFrames: frames,
singlePane: narrow,
onFocusPane: (pane) => _focus(pane.sessionId),
paneBuilder: (context, pane, active) => _Pane(pane.sessionId),
@@ -83,7 +83,7 @@ class _Harness {
void dispose() {
controller.dispose();
frame.dispose();
frames.dispose();
typing.dispose();
}
}
@@ -128,12 +128,12 @@ void main() {
// Plain Y and Shift+Y type; only the chord acts.
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
await _chord(tester, LogicalKeyboardKey.shiftLeft);
expect(h.controller.floatingPane, isNull);
expect(h.controller.floatingPanes, isEmpty);
tester.state<_PaneState>(_pane('b')).focus.requestFocus();
await tester.pump();
await _chord(tester, LogicalKeyboardKey.controlLeft);
expect(h.controller.floatingPane?.sessionId, 'b');
expect(h.controller.floatingPanes.firstOrNull?.sessionId, 'b');
expect(h.controller.paneCount, 1);
expect(find.byKey(const ValueKey('chat-float-title')), findsOneWidget);
// The chat moved: same State, same draft, its field has the keyboard.
@@ -157,7 +157,7 @@ void main() {
expect(a.focus.hasFocus, isTrue);
// Docking returns the same chat to the tiling.
h.controller.dock();
h.controller.dock(h.controller.floatingPanes.single.id);
await tester.pumpAndSettle();
expect(h.controller.paneCount, 2);
expect(tester.state<_PaneState>(_pane('b')), same(b));
@@ -174,7 +174,7 @@ void main() {
await tester.sendKeyEvent(LogicalKeyboardKey.keyY);
await _chord(tester, LogicalKeyboardKey.controlLeft);
// Nothing to float from the terminal: the shell gets Ctrl+Y (yank).
expect(h.controller.floatingPane, isNull);
expect(h.controller.floatingPanes, isEmpty);
expect(h.typed, contains(LogicalKeyboardKey.keyY));
expect(h.typed.where((k) => k == LogicalKeyboardKey.keyY).length, 2);
@@ -216,7 +216,7 @@ void main() {
tester.state<_PaneState>(_pane('b')).focus.requestFocus();
await tester.pump();
await _chord(tester, LogicalKeyboardKey.controlLeft);
expect(h.controller.floatingPane, isNull);
expect(h.controller.floatingPanes, isEmpty);
// A float saved on a wide window stays, unpainted, with its state.
h.controller.float(h.controller.panes.last.id);
await tester.pumpAndSettle();
@@ -125,7 +125,9 @@ void main() {
addTearDown(controller.dispose);
final outer = controller.root as ChatWorkspaceSplit;
controller.resize(outer.id, .3);
final ids = {for (final s in ['a', 'b', 'c', 'd']) s: _id(controller, s)};
final ids = {
for (final s in ['a', 'b', 'c', 'd']) s: _id(controller, s),
};
final serial = controller.moveSerial;
controller.swap(ids['a']!, ids['c']!);
expect(controller.panes.map((p) => p.sessionId), ['c', 'b', 'a', 'd']);
@@ -13,6 +13,12 @@ ChatWorkspaceController _three() => ChatWorkspaceController()
List<String> _sessions(ChatWorkspaceController c) =>
c.panes.map((p) => p.sessionId).toList();
List<String> _floating(ChatWorkspaceController c) =>
c.floatingPanes.map((p) => p.sessionId).toList();
ChatWorkspacePane _pane(ChatWorkspaceController c, String session) =>
c.panes.firstWhere((p) => p.sessionId == session);
class _Store implements ChatFloatStore {
_Store([this.record]);
ChatFloatRecord? record;
@@ -30,10 +36,11 @@ class _Store implements ChatFloatStore {
void main() {
test('float takes a pane out of the tiling and keeps its id', () {
final c = _three();
final b = c.panes.firstWhere((p) => p.sessionId == 'b');
final b = _pane(c, 'b');
c.activate(b.id);
c.float(b.id);
expect(c.floatingPane?.id, b.id);
expect(c.floatingPanes.single.id, b.id);
expect(c.isFloating(b.id), isTrue);
expect(c.floatShown, isTrue);
expect(_sessions(c), ['a', 'c']);
expect(c.activePane?.sessionId, isNot('b'));
@@ -44,37 +51,47 @@ void main() {
final c = ChatWorkspaceController()..open('a');
expect(c.canFloat(c.panes.single.id), isFalse);
c.float(c.panes.single.id);
expect(c.floatingPane, isNull);
expect(c.floatingPanes, isEmpty);
c.splitActive('b', ChatSplitAxis.horizontal);
final b = c.activePane!;
c.float(b.id);
// Closing the last tiled pane docks the floating chat in its place.
// The last tiled chat stays: it cannot float too.
expect(c.canFloat(c.panes.single.id), isFalse);
// Closing the last tiled pane docks the oldest floating chat in its place.
c.close(c.panes.single.id);
expect(c.floatingPane, isNull);
expect(c.floatingPanes, isEmpty);
expect(c.panes.single.id, b.id);
expect(c.activePaneId, b.id);
});
test('floating another chat swaps it with the floating one', () {
test('several chats float together and show or hide together', () {
final c = _three();
final a = c.panes.firstWhere((p) => p.sessionId == 'a');
final c3 = c.panes.firstWhere((p) => p.sessionId == 'c');
c.float(a.id);
c.float(_pane(c, 'a').id);
c.setFloatShown(false);
c.float(c3.id);
expect(c.floatingPane?.id, c3.id);
c.float(_pane(c, 'c').id);
expect(_floating(c), ['a', 'c']);
// Floating another one shows them all.
expect(c.floatShown, isTrue);
expect(_sessions(c), ['b']);
c.toggleFloatShown();
expect(c.floatShown, isFalse);
c.toggleFloatShown();
expect(c.floatShown, isTrue);
// Docking one leaves the other floating.
final a = c.floatingPanes.first;
c.dock(a.id);
expect(_floating(c), ['c']);
expect(c.activePaneId, a.id);
expect(_sessions(c), ['b', 'a']);
expect(c.panes.last.id, a.id);
});
test('dock puts the chat right of the active pane and activates it', () {
final c = _three();
final b = c.panes.firstWhere((p) => p.sessionId == 'b');
final b = _pane(c, 'b');
c.float(b.id);
final active = c.activePane!;
c.dock();
expect(c.floatingPane, isNull);
c.dock(b.id);
expect(c.floatingPanes, isEmpty);
expect(c.activePaneId, b.id);
final panes = c.panes.map((p) => p.id).toList();
expect(panes.indexOf(b.id), panes.indexOf(active.id) + 1);
@@ -83,7 +100,7 @@ void main() {
test('hide, show, reopen, close and /new follow the floating chat', () {
final c = _three();
final b = c.panes.firstWhere((p) => p.sessionId == 'b');
final b = _pane(c, 'b');
c.float(b.id);
c.toggleFloatShown();
expect(c.floatShown, isFalse);
@@ -93,55 +110,101 @@ void main() {
c.splitActive('b', ChatSplitAxis.vertical);
expect(c.paneCount, 2);
c.replaceSession('b', 'b2');
expect(c.floatingPane?.id, b.id);
expect(c.floatingPane?.sessionId, 'b2');
expect(c.floatingPanes.single.id, b.id);
expect(c.floatingPanes.single.sessionId, 'b2');
c.close(b.id);
expect(c.floatingPane, isNull);
expect(c.floatingPanes, isEmpty);
expect(c.paneCount, 2);
});
test('restoreFloat skips open sessions and taken ids', () {
test('/new into a session another float holds closes the duplicate', () {
final c = _three();
c.float(_pane(c, 'a').id);
c.float(_pane(c, 'b').id);
c.replaceSession('a', 'b');
expect(_floating(c), ['b']);
});
test('restoreFloats skips open sessions and taken ids', () {
final c = ChatWorkspaceController()
..open('a')
..splitActive('b', ChatSplitAxis.horizontal);
final taken = c.panes.first.id;
expect(
c.restoreFloat(const ChatWorkspacePane('x', 'a'), shown: true),
isFalse,
c.restoreFloats([
const ChatWorkspacePane('x', 'a'),
ChatWorkspacePane(taken, 'z'),
], shown: true),
0,
);
expect(c.restoreFloat(ChatWorkspacePane(taken, 'z'), shown: true), isFalse);
expect(
c.restoreFloat(const ChatWorkspacePane('x', 'z'), shown: false),
isTrue,
);
expect(c.floatingPane?.sessionId, 'z');
expect(c.floatShown, isFalse);
// A new split id never collides with the floating pane's.
expect(
c.restoreFloats([
const ChatWorkspacePane('x', 'z'),
const ChatWorkspacePane('y', 'w'),
const ChatWorkspacePane('x', 'v'),
], shown: false),
2,
);
expect(_floating(c), ['z', 'w']);
expect(c.floatShown, isFalse);
// A new split id never collides with a floating pane's.
c.splitActive('d', ChatSplitAxis.vertical);
expect(c.panes.map((p) => p.id), isNot(contains('x')));
expect(
c.panes.map((p) => p.id),
isNot(anyOf(contains('x'), contains('y'))),
);
});
test('a restored layout drops any floating chat', () {
test('a restored layout drops every floating chat', () {
final c = _three();
c.float(c.panes.first.id);
c.float(c.panes.first.id);
final snapshot = c.snapshot()!;
c.restoreLayout(snapshot);
expect(c.floatingPane, isNull);
expect(c.floatingPanes, isEmpty);
});
test('records round-trip and reject malformed input', () {
test('records round-trip, read version 1 and reject malformed input', () {
const record = ChatFloatRecord(
pane: ChatWorkspacePane('p1', 'server:abc'),
panes: [
ChatWorkspacePane('p1', 'server:abc'),
ChatWorkspacePane('p2', 'server:def'),
],
shown: true,
rect: Rect.fromLTWH(10, 20, 400, 300),
frames: {
'p1': Rect.fromLTWH(10, 20, 400, 300),
'p3': Rect.fromLTWH(1, 2, 330, 250),
},
);
expect(ChatFloatRecord.decode(record.encode()), record);
const none = ChatFloatRecord(rect: chatFloatDefaultRect);
const none = ChatFloatRecord();
expect(ChatFloatRecord.decode(none.encode()), none);
expect(
ChatFloatRecord.decode(
'{"version":1,"rect":[1,2,400,300],"shown":true,'
'"pane":{"id":"p","session_id":"s"}}',
),
const ChatFloatRecord(
panes: [ChatWorkspacePane('p', 's')],
shown: true,
frames: {'p': Rect.fromLTWH(1, 2, 400, 300)},
),
);
expect(
ChatFloatRecord.decode('{"version":1,"rect":[0,0,1,1],"pane":null}'),
none,
);
for (final bad in [
'',
'[]',
'{"version":2,"rect":[0,0,1,1]}',
'{"version":3,"panes":[],"frames":{}}',
'{"version":2,"panes":[]}',
'{"version":2,"panes":[7],"frames":{}}',
'{"version":2,"panes":[],"frames":{"p":[0,0,-1,1]}}',
'{"version":2,"panes":[],"frames":{" p":[0,0,1,1]}}',
'{"version":2,"panes":[{"id":"p","session_id":"a"},'
'{"id":"p","session_id":"b"}],"frames":{}}',
'{"version":1,"rect":[0,0,-1,1]}',
'{"version":1,"rect":[0,0,1]}',
'{"version":1,"rect":[0,0,1,1],"pane":{"id":" x","session_id":"a"}}',
@@ -151,41 +214,62 @@ void main() {
}
});
test('frames are kept per pane, cascade by default and restore', () {
final frames = ChatFloatFrames();
expect(frames.rectFor('a'), chatFloatDefaultRect);
expect(
frames.rectFor('b', index: 2),
chatFloatDefaultRect.shift(const Offset(64, 64)),
);
frames.move('a', const Rect.fromLTWH(1, 2, 400, 300));
expect(frames.rectFor('a', index: 3), const Rect.fromLTWH(1, 2, 400, 300));
frames.restore({'b': const Rect.fromLTWH(9, 9, 400, 300)});
expect(frames.rectFor('a'), chatFloatDefaultRect);
expect(frames.rectFor('b'), const Rect.fromLTWH(9, 9, 400, 300));
});
test('binding restores after the layout and saves changes', () async {
final c = ChatWorkspaceController()
..open('a')
..splitActive('b', ChatSplitAxis.horizontal);
final store = _Store(
const ChatFloatRecord(
pane: ChatWorkspacePane('f', 'c'),
panes: [ChatWorkspacePane('f', 'c'), ChatWorkspacePane('g', 'd')],
shown: true,
rect: Rect.fromLTWH(5, 6, 400, 300),
frames: {
'f': Rect.fromLTWH(5, 6, 400, 300),
'g': Rect.fromLTWH(50, 60, 400, 300),
},
),
);
final frame = ChatFloatFrame();
final frames = ChatFloatFrames();
final binding = ChatFloatBinding(
controller: c,
frame: frame,
frames: frames,
store: store,
debounce: Duration.zero,
);
await binding.start();
expect(c.floatingPane?.sessionId, 'c');
expect(_floating(c), ['c', 'd']);
expect(c.floatShown, isTrue);
expect(frame.rect, const Rect.fromLTWH(5, 6, 400, 300));
expect(frames.rectFor('f'), const Rect.fromLTWH(5, 6, 400, 300));
expect(frames.rectFor('g'), const Rect.fromLTWH(50, 60, 400, 300));
expect(store.writes, 0);
c.setFloatShown(false);
await Future<void>.delayed(Duration.zero);
await binding.flush();
expect(store.record?.shown, isFalse);
frame.move(const Rect.fromLTWH(50, 60, 400, 300));
frames.move('f', const Rect.fromLTWH(70, 80, 400, 300));
final writes = store.writes;
await binding.flush();
expect(store.writes, writes + 1);
expect(store.record?.rect.left, 50);
c.dock();
expect(store.record?.frames['f']?.left, 70);
// A docked chat keeps its frame for the next float; a closed one drops it.
c.dock('f');
c.close('g');
binding.dispose();
await Future<void>.delayed(Duration.zero);
expect(store.record?.pane, isNull);
expect(store.record?.panes, isEmpty);
expect(store.record?.frames.keys, ['f']);
});
}