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:
@@ -6,20 +6,46 @@ import 'package:flutter/foundation.dart';
|
||||
import 'chat_float_store.dart';
|
||||
import 'chat_workspace_controller.dart';
|
||||
|
||||
/// The floating chat window's frame. A drag moves it every pointer event
|
||||
/// without saving; [commit] marks the end of the drag.
|
||||
class ChatFloatFrame extends ChangeNotifier {
|
||||
ChatFloatFrame([this._rect = chatFloatDefaultRect]);
|
||||
Rect _rect;
|
||||
Rect get rect => _rect;
|
||||
/// The floating chat windows' frames, by pane id. A drag moves a window every
|
||||
/// pointer event without saving; [commit] marks the end of the drag. A pane
|
||||
/// keeps its frame while it is docked, so floating it again puts the window
|
||||
/// back where it was.
|
||||
class ChatFloatFrames extends ChangeNotifier {
|
||||
ChatFloatFrames([Map<String, Rect> frames = const {}])
|
||||
: _frames = {...frames};
|
||||
final Map<String, Rect> _frames;
|
||||
int _commits = 0;
|
||||
|
||||
Map<String, Rect> get frames => Map.unmodifiable(_frames);
|
||||
|
||||
/// Advances when a move or resize ends (the binding saves then).
|
||||
int get commits => _commits;
|
||||
|
||||
void move(Rect rect) {
|
||||
if (rect == _rect) return;
|
||||
_rect = rect;
|
||||
/// [paneId]'s frame; a window without one opens at the default frame,
|
||||
/// stepped down and right by [index] so stacked windows stay visible.
|
||||
Rect rectFor(String paneId, {int index = 0}) =>
|
||||
_frames[paneId] ??
|
||||
chatFloatDefaultRect.shift(Offset(32, 32) * index.toDouble());
|
||||
|
||||
/// Gives [paneId] its opening frame ([rectFor] at [index]) unless it has
|
||||
/// one, so the window stays put when other windows come and go.
|
||||
void place(String paneId, {required int index}) {
|
||||
if (_frames.containsKey(paneId)) return;
|
||||
move(paneId, rectFor(paneId, index: index));
|
||||
}
|
||||
|
||||
void move(String paneId, Rect rect) {
|
||||
if (_frames[paneId] == rect) return;
|
||||
_frames[paneId] = rect;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Replaces every frame (a restore).
|
||||
void restore(Map<String, Rect> frames) {
|
||||
if (mapEquals(frames, _frames)) return;
|
||||
_frames
|
||||
..clear()
|
||||
..addAll(frames);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -29,21 +55,21 @@ class ChatFloatFrame extends ChangeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
/// Saves which chat floats, whether it shows and the window's frame, and
|
||||
/// Saves which chats float, whether they show and their windows' frames, and
|
||||
/// restores them once the workspace layout itself has been restored.
|
||||
class ChatFloatBinding {
|
||||
ChatFloatBinding({
|
||||
required this.controller,
|
||||
required this.frame,
|
||||
required this.frames,
|
||||
required this.store,
|
||||
this.debounce = const Duration(milliseconds: 250),
|
||||
}) {
|
||||
controller.addListener(_changed);
|
||||
frame.addListener(_frameChanged);
|
||||
frames.addListener(_framesChanged);
|
||||
}
|
||||
|
||||
final ChatWorkspaceController controller;
|
||||
final ChatFloatFrame frame;
|
||||
final ChatFloatFrames frames;
|
||||
final ChatFloatStore store;
|
||||
final Duration debounce;
|
||||
ChatFloatRecord? _saved;
|
||||
@@ -53,11 +79,22 @@ class ChatFloatBinding {
|
||||
Timer? _timer;
|
||||
Future<void> _writes = Future.value();
|
||||
|
||||
ChatFloatRecord get _current => ChatFloatRecord(
|
||||
pane: controller.floatingPane,
|
||||
shown: controller.floatShown,
|
||||
rect: frame.rect,
|
||||
);
|
||||
/// Frames of panes still open somewhere (tiled or floating); a closed
|
||||
/// pane's frame is dropped.
|
||||
ChatFloatRecord get _current {
|
||||
final open = {
|
||||
for (final pane in controller.panes) pane.id,
|
||||
for (final pane in controller.floatingPanes) pane.id,
|
||||
};
|
||||
return ChatFloatRecord(
|
||||
panes: controller.floatingPanes,
|
||||
shown: controller.floatShown,
|
||||
frames: {
|
||||
for (final MapEntry(:key, :value) in frames.frames.entries)
|
||||
if (open.contains(key)) key: value,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Call after the workspace layout restored, so a saved float can tell
|
||||
/// whether its chat is already open in the tiling.
|
||||
@@ -66,25 +103,24 @@ class ChatFloatBinding {
|
||||
try {
|
||||
record = await store.read();
|
||||
} on Object {
|
||||
// Unavailable preferences leave the default frame and no float.
|
||||
// Unavailable preferences leave the default frames and no float.
|
||||
}
|
||||
if (_disposed) return;
|
||||
if (record != null) {
|
||||
_saved = record;
|
||||
_commits = frame.commits;
|
||||
frame.move(record.rect);
|
||||
final pane = record.pane;
|
||||
if (pane != null && controller.floatingPane == null) {
|
||||
controller.restoreFloat(pane, shown: record.shown);
|
||||
_commits = frames.commits;
|
||||
frames.restore(record.frames);
|
||||
if (record.panes.isNotEmpty && controller.floatingPanes.isEmpty) {
|
||||
controller.restoreFloats(record.panes, shown: record.shown);
|
||||
}
|
||||
}
|
||||
_loading = false;
|
||||
_changed();
|
||||
}
|
||||
|
||||
void _frameChanged() {
|
||||
if (frame.commits == _commits) return;
|
||||
_commits = frame.commits;
|
||||
void _framesChanged() {
|
||||
if (frames.commits == _commits) return;
|
||||
_commits = frames.commits;
|
||||
_changed();
|
||||
}
|
||||
|
||||
@@ -113,7 +149,7 @@ class ChatFloatBinding {
|
||||
void dispose() {
|
||||
if (_disposed) return;
|
||||
controller.removeListener(_changed);
|
||||
frame.removeListener(_frameChanged);
|
||||
frames.removeListener(_framesChanged);
|
||||
unawaited(flush());
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../ui/floating/floating_layer.dart';
|
||||
@@ -11,18 +12,18 @@ import 'chat_float_shortcut.dart';
|
||||
import 'chat_float_window.dart';
|
||||
import 'chat_workspace_controller.dart';
|
||||
|
||||
/// The split workspace ([child]) with its floating chat over the app: the
|
||||
/// window, its show and hide motion, its focus and its shortcut (see
|
||||
/// [chatFloatShortcut]). [content] is the floating pane's live view, moved
|
||||
/// here from the tiling rather than rebuilt.
|
||||
/// The split workspace ([child]) with its floating chats over the app: their
|
||||
/// windows, show and hide motion, focus and shortcut (see
|
||||
/// [chatFloatShortcut]). [content] is a floating pane's live view, moved here
|
||||
/// from the tiling rather than rebuilt.
|
||||
///
|
||||
/// The window shows only while [enabled] (a wide layout) and the Chat
|
||||
/// destination is current; otherwise the floating chat is kept, unpainted.
|
||||
/// The windows show while [enabled] (a wide layout), over every destination,
|
||||
/// like the floating terminal. They show and hide together.
|
||||
class ChatFloatHost extends StatefulWidget {
|
||||
const ChatFloatHost({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.frame,
|
||||
required this.frames,
|
||||
required this.enabled,
|
||||
required this.title,
|
||||
required this.content,
|
||||
@@ -33,13 +34,13 @@ class ChatFloatHost extends StatefulWidget {
|
||||
});
|
||||
|
||||
final ChatWorkspaceController controller;
|
||||
final ChatFloatFrame frame;
|
||||
final ChatFloatFrames frames;
|
||||
final bool enabled;
|
||||
final String title;
|
||||
final Widget? content;
|
||||
final String Function(ChatWorkspacePane pane) title;
|
||||
final Widget Function(ChatWorkspacePane pane) content;
|
||||
|
||||
/// The floating pane's focus scope.
|
||||
final FocusScopeNode? scope;
|
||||
/// A floating pane's focus scope.
|
||||
final FocusScopeNode? Function(ChatWorkspacePane pane) scope;
|
||||
|
||||
/// The tiled pane with the keyboard, which the shortcut floats when no
|
||||
/// chat floats yet.
|
||||
@@ -51,20 +52,9 @@ class ChatFloatHost extends StatefulWidget {
|
||||
State<ChatFloatHost> createState() => _ChatFloatHostState();
|
||||
}
|
||||
|
||||
class _ChatFloatHostState extends State<ChatFloatHost>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late final AnimationController _reveal = AnimationController(
|
||||
vsync: this,
|
||||
duration: Motion.standard,
|
||||
);
|
||||
late final CurvedAnimation _curve = CurvedAnimation(
|
||||
parent: _reveal,
|
||||
curve: Motion.curve,
|
||||
reverseCurve: Curves.easeInCubic,
|
||||
);
|
||||
bool _current = true;
|
||||
class _ChatFloatHostState extends State<ChatFloatHost> {
|
||||
bool _visible = false;
|
||||
String? _paneId;
|
||||
Set<String> _paneIds = const {};
|
||||
FocusNode? _previous;
|
||||
|
||||
@override
|
||||
@@ -72,13 +62,6 @@ class _ChatFloatHostState extends State<ChatFloatHost>
|
||||
super.initState();
|
||||
FocusManager.instance.addEarlyKeyEventHandler(_key);
|
||||
widget.controller.addListener(_sync);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
// Another destination mutes this one's tickers and takes its focus.
|
||||
_current = TickerMode.valuesOf(context).enabled;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _sync());
|
||||
}
|
||||
|
||||
@@ -98,44 +81,41 @@ class _ChatFloatHostState extends State<ChatFloatHost>
|
||||
void dispose() {
|
||||
FocusManager.instance.removeEarlyKeyEventHandler(_key);
|
||||
widget.controller.removeListener(_sync);
|
||||
_curve.dispose();
|
||||
_reveal.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get _presentable => widget.enabled && _current;
|
||||
|
||||
void _sync() {
|
||||
if (!mounted) return;
|
||||
final pane = widget.controller.floatingPane;
|
||||
final visible = _presentable && widget.controller.floatShown;
|
||||
_reveal.duration = Motion.of(context, Motion.standard);
|
||||
if (pane == null) {
|
||||
// Docked or closed: the view went back to the tiling, so no motion.
|
||||
final panes = widget.controller.floatingPanes;
|
||||
final ids = {for (final pane in panes) pane.id};
|
||||
final visible = widget.enabled && widget.controller.floatShown;
|
||||
for (final (index, pane) in panes.indexed) {
|
||||
widget.frames.place(pane.id, index: index);
|
||||
}
|
||||
if (panes.isEmpty) {
|
||||
// Docked or closed: the views went back to the tiling.
|
||||
_previous = null;
|
||||
_reveal.value = 0;
|
||||
} else if (visible != _visible) {
|
||||
if (visible) {
|
||||
_remember();
|
||||
unawaited(_reveal.forward());
|
||||
_focusSoon(pane);
|
||||
_focusSoon(panes.last);
|
||||
} else {
|
||||
_release();
|
||||
unawaited(_reveal.reverse());
|
||||
}
|
||||
} else if (visible && pane.id != _paneId) {
|
||||
// Another chat replaced the floating one.
|
||||
_focusSoon(pane);
|
||||
} else if (visible) {
|
||||
// A newly floated chat takes the keyboard.
|
||||
final added = panes.where((p) => !_paneIds.contains(p.id)).lastOrNull;
|
||||
if (added != null) _focusSoon(added);
|
||||
}
|
||||
_paneId = pane?.id;
|
||||
_paneIds = ids;
|
||||
if (visible != _visible) setState(() => _visible = visible);
|
||||
}
|
||||
|
||||
bool _inside(FocusNode node) {
|
||||
final scope = widget.scope;
|
||||
bool _inside(FocusNode node) => widget.controller.floatingPanes.any((pane) {
|
||||
final scope = widget.scope(pane);
|
||||
return scope != null &&
|
||||
(identical(node, scope) || node.ancestors.contains(scope));
|
||||
}
|
||||
});
|
||||
|
||||
void _remember() {
|
||||
final current = FocusManager.instance.primaryFocus;
|
||||
@@ -148,30 +128,30 @@ class _ChatFloatHostState extends State<ChatFloatHost>
|
||||
void _focusSoon(ChatWorkspacePane pane) {
|
||||
WidgetsBinding.instance
|
||||
..addPostFrameCallback((_) {
|
||||
if (!mounted || widget.controller.floatingPane?.id != pane.id) return;
|
||||
if (!mounted || !widget.controller.isFloating(pane.id)) return;
|
||||
final focus = widget.onFocusPane;
|
||||
if (focus != null) {
|
||||
focus(pane);
|
||||
} else {
|
||||
widget.scope?.requestFocus();
|
||||
widget.scope(pane)?.requestFocus();
|
||||
}
|
||||
})
|
||||
..ensureVisualUpdate();
|
||||
}
|
||||
|
||||
/// Gives the keyboard back to what had it before the chat showed, if the
|
||||
/// Gives the keyboard back to what had it before the chats showed, if a
|
||||
/// floating chat has it now.
|
||||
void _release() {
|
||||
final previous = _previous;
|
||||
_previous = null;
|
||||
final scope = widget.scope;
|
||||
if (scope == null || !scope.hasFocus) return;
|
||||
final current = FocusManager.instance.primaryFocus;
|
||||
if (current == null || !_inside(current)) return;
|
||||
if (previous != null &&
|
||||
previous.context != null &&
|
||||
previous.canRequestFocus) {
|
||||
previous.requestFocus();
|
||||
} else {
|
||||
scope.unfocus();
|
||||
current.unfocus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,12 +159,12 @@ class _ChatFloatHostState extends State<ChatFloatHost>
|
||||
/// composer or the terminal; ignored (left to them) when it does nothing.
|
||||
KeyEventResult _key(KeyEvent event) {
|
||||
if (!mounted ||
|
||||
!_presentable ||
|
||||
!widget.enabled ||
|
||||
!chatFloatShortcut(event, HardwareKeyboard.instance)) {
|
||||
return KeyEventResult.ignored;
|
||||
}
|
||||
final controller = widget.controller;
|
||||
if (controller.floatingPane == null) {
|
||||
if (controller.floatingPanes.isEmpty) {
|
||||
final pane = widget.focusedPane();
|
||||
if (pane == null || !controller.canFloat(pane.id)) {
|
||||
return KeyEventResult.ignored;
|
||||
@@ -198,33 +178,37 @@ class _ChatFloatHostState extends State<ChatFloatHost>
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final content = widget.content;
|
||||
final panes = widget.controller.floatingPanes;
|
||||
final cupertino =
|
||||
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
||||
return Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
widget.child,
|
||||
if (content != null)
|
||||
for (final (index, pane) in panes.indexed)
|
||||
Positioned.fill(
|
||||
key: ValueKey(pane.id),
|
||||
// Shown over every destination; the window's motion keeps
|
||||
// running there (see [_ChatFloatSlot]).
|
||||
child: FloatingLayer(
|
||||
open: _visible,
|
||||
coverOverlay: true,
|
||||
builder: (context, bounds) => [
|
||||
ListenableBuilder(
|
||||
listenable: Listenable.merge([widget.frame, _reveal]),
|
||||
builder: (context, _) => ChatFloatWindow(
|
||||
frame: widget.frame,
|
||||
listenable: widget.frames,
|
||||
builder: (context, _) => _ChatFloatSlot(
|
||||
visible: _visible,
|
||||
rect: widget.frames.rectFor(pane.id, index: index),
|
||||
currentRect: () =>
|
||||
widget.frames.rectFor(pane.id, index: index),
|
||||
onMove: (rect) => widget.frames.move(pane.id, rect),
|
||||
onCommit: widget.frames.commit,
|
||||
bounds: bounds,
|
||||
title: widget.title,
|
||||
cupertino:
|
||||
chatControlsStyleOf(context) ==
|
||||
ChatControlsStyle.cupertino,
|
||||
reveal: _curve,
|
||||
hiding: !_visible,
|
||||
offstage: !_visible && _reveal.isDismissed,
|
||||
shortcut: chatFloatShortcutLabel(),
|
||||
onDock: widget.controller.dock,
|
||||
title: widget.title(pane),
|
||||
cupertino: cupertino,
|
||||
onDock: () => widget.controller.dock(pane.id),
|
||||
onHide: () => widget.controller.setFloatShown(false),
|
||||
child: content,
|
||||
child: widget.content(pane),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -234,3 +218,112 @@ class _ChatFloatHostState extends State<ChatFloatHost>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// One floating chat's window and its own grow-and-fade motion, so a chat
|
||||
/// floated while the others show animates in alone.
|
||||
class _ChatFloatSlot extends StatefulWidget {
|
||||
const _ChatFloatSlot({
|
||||
required this.visible,
|
||||
required this.rect,
|
||||
required this.currentRect,
|
||||
required this.onMove,
|
||||
required this.onCommit,
|
||||
required this.bounds,
|
||||
required this.title,
|
||||
required this.cupertino,
|
||||
required this.onDock,
|
||||
required this.onHide,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final bool visible;
|
||||
final Rect rect;
|
||||
final Rect Function() currentRect;
|
||||
final ValueChanged<Rect> onMove;
|
||||
final VoidCallback onCommit;
|
||||
final Size bounds;
|
||||
final String title;
|
||||
final bool cupertino;
|
||||
final VoidCallback onDock;
|
||||
final VoidCallback onHide;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<_ChatFloatSlot> createState() => _ChatFloatSlotState();
|
||||
}
|
||||
|
||||
class _ChatFloatSlotState extends State<_ChatFloatSlot>
|
||||
implements TickerProvider {
|
||||
Ticker? _ticker;
|
||||
|
||||
/// A ticker the hidden destination's [TickerMode] does not mute: the
|
||||
/// window must still show and hide over another destination, and a
|
||||
/// TickerMode cannot re-enable what an ancestor turned off.
|
||||
@override
|
||||
Ticker createTicker(TickerCallback onTick) {
|
||||
assert(_ticker == null, 'one reveal ticker per window');
|
||||
return _ticker = Ticker(onTick, debugLabel: 'chat float reveal');
|
||||
}
|
||||
|
||||
late final AnimationController _reveal = AnimationController(
|
||||
vsync: this,
|
||||
duration: Motion.standard,
|
||||
);
|
||||
late final CurvedAnimation _curve = CurvedAnimation(
|
||||
parent: _reveal,
|
||||
curve: Motion.curve,
|
||||
reverseCurve: Curves.easeInCubic,
|
||||
);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.visible) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) => _run());
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant _ChatFloatSlot oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.visible != widget.visible) _run();
|
||||
}
|
||||
|
||||
void _run() {
|
||||
if (!mounted) return;
|
||||
_reveal.duration = Motion.of(context, Motion.standard);
|
||||
unawaited(widget.visible ? _reveal.forward() : _reveal.reverse());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_curve.dispose();
|
||||
_reveal.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => AnimatedBuilder(
|
||||
animation: _reveal,
|
||||
builder: (context, _) {
|
||||
final offstage = !widget.visible && _reveal.isDismissed;
|
||||
return ChatFloatWindow(
|
||||
rect: widget.rect,
|
||||
currentRect: widget.currentRect,
|
||||
onMove: widget.onMove,
|
||||
onCommit: widget.onCommit,
|
||||
bounds: widget.bounds,
|
||||
title: widget.title,
|
||||
cupertino: widget.cupertino,
|
||||
reveal: _curve,
|
||||
hiding: !widget.visible,
|
||||
offstage: offstage,
|
||||
shortcut: chatFloatShortcutLabel(),
|
||||
onDock: widget.onDock,
|
||||
onHide: widget.onHide,
|
||||
// A hidden window's chat pauses its tickers like a hidden tab.
|
||||
child: TickerMode(enabled: !offstage, child: widget.child),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import '../../../core/servers/server_scope.dart';
|
||||
@@ -13,69 +14,128 @@ const chatFloatPreferenceKey = 'pipelines.next.chatFloat.v1';
|
||||
const Rect chatFloatDefaultRect = Rect.fromLTWH(120, 96, 480, 560);
|
||||
const Size chatFloatMinSize = Size(320, 240);
|
||||
|
||||
/// The floating chat as saved on this device: which pane floats (if any),
|
||||
/// whether it is shown, and the window's frame. Identities and geometry only,
|
||||
/// like the workspace snapshot.
|
||||
class ChatFloatRecord {
|
||||
const ChatFloatRecord({this.pane, this.shown = false, required this.rect});
|
||||
/// The most floating chats saved (and restored).
|
||||
const int chatFloatMaxPanes = 12;
|
||||
|
||||
final ChatWorkspacePane? pane;
|
||||
/// The floating chats as saved on this device: which panes float (oldest
|
||||
/// first), whether they are shown, and each window's frame by pane id
|
||||
/// (docked panes keep theirs, so floating again returns to the same place).
|
||||
/// Identities and geometry only, like the workspace snapshot.
|
||||
class ChatFloatRecord {
|
||||
const ChatFloatRecord({
|
||||
this.panes = const [],
|
||||
this.shown = false,
|
||||
this.frames = const {},
|
||||
});
|
||||
|
||||
final List<ChatWorkspacePane> panes;
|
||||
final bool shown;
|
||||
final Rect rect;
|
||||
final Map<String, Rect> frames;
|
||||
|
||||
String encode() => jsonEncode({
|
||||
'version': 1,
|
||||
'pane': pane == null
|
||||
? null
|
||||
: {'id': pane!.id, 'session_id': pane!.sessionId},
|
||||
'version': 2,
|
||||
'panes': [
|
||||
for (final pane in panes) {'id': pane.id, 'session_id': pane.sessionId},
|
||||
],
|
||||
'shown': shown,
|
||||
'rect': [rect.left, rect.top, rect.width, rect.height],
|
||||
'frames': {
|
||||
for (final MapEntry(:key, value: r) in frames.entries)
|
||||
key: [r.left, r.top, r.width, r.height],
|
||||
},
|
||||
});
|
||||
|
||||
static ChatFloatRecord? decode(String source) {
|
||||
if (source.length > 4096) return null;
|
||||
if (source.length > 65536) return null;
|
||||
try {
|
||||
final data = jsonDecode(source);
|
||||
if (data is! Map || data['version'] != 1) return null;
|
||||
final values = data['rect'];
|
||||
if (values is! List ||
|
||||
values.length != 4 ||
|
||||
values.any((v) => v is! num || !v.isFinite)) {
|
||||
return null;
|
||||
}
|
||||
final [left, top, width, height] = [
|
||||
for (final v in values) (v as num).toDouble(),
|
||||
];
|
||||
if (width <= 0 || height <= 0) return null;
|
||||
final pane = data['pane'];
|
||||
ChatWorkspacePane? floating;
|
||||
if (pane is Map) {
|
||||
final id = pane['id'], session = pane['session_id'];
|
||||
if (!_identity(id, 256) || !_identity(session, 512)) return null;
|
||||
floating = ChatWorkspacePane(id as String, session as String);
|
||||
} else if (pane != null) {
|
||||
return null;
|
||||
}
|
||||
return ChatFloatRecord(
|
||||
pane: floating,
|
||||
shown: data['shown'] == true,
|
||||
rect: Rect.fromLTWH(left, top, width, height),
|
||||
);
|
||||
if (data is! Map) return null;
|
||||
return switch (data['version']) {
|
||||
1 => _decodeV1(data),
|
||||
2 => _decodeV2(data),
|
||||
_ => null,
|
||||
};
|
||||
} on Object {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// One floating chat and one frame: the frame becomes that pane's.
|
||||
static ChatFloatRecord? _decodeV1(Map data) {
|
||||
final rect = _rect(data['rect']);
|
||||
if (rect == null) return null;
|
||||
final raw = data['pane'];
|
||||
if (raw == null) return const ChatFloatRecord();
|
||||
final pane = _pane(raw);
|
||||
if (pane == null) return null;
|
||||
return ChatFloatRecord(
|
||||
panes: [pane],
|
||||
shown: data['shown'] == true,
|
||||
frames: {pane.id: rect},
|
||||
);
|
||||
}
|
||||
|
||||
static ChatFloatRecord? _decodeV2(Map data) {
|
||||
final rawPanes = data['panes'], rawFrames = data['frames'];
|
||||
if (rawPanes is! List || rawFrames is! Map) return null;
|
||||
if (rawPanes.length > chatFloatMaxPanes) return null;
|
||||
final panes = <ChatWorkspacePane>[];
|
||||
for (final raw in rawPanes) {
|
||||
final pane = _pane(raw);
|
||||
if (pane == null || panes.any((p) => p.id == pane.id)) return null;
|
||||
panes.add(pane);
|
||||
}
|
||||
if (rawFrames.length > 4 * chatFloatMaxPanes) return null;
|
||||
final frames = <String, Rect>{};
|
||||
for (final MapEntry(:key, :value) in rawFrames.entries) {
|
||||
final rect = _rect(value);
|
||||
if (!_identity(key, 256) || rect == null) return null;
|
||||
frames[key as String] = rect;
|
||||
}
|
||||
return ChatFloatRecord(
|
||||
panes: panes,
|
||||
shown: data['shown'] == true,
|
||||
frames: frames,
|
||||
);
|
||||
}
|
||||
|
||||
static ChatWorkspacePane? _pane(Object? raw) {
|
||||
if (raw is! Map) return null;
|
||||
final id = raw['id'], session = raw['session_id'];
|
||||
if (!_identity(id, 256) || !_identity(session, 512)) return null;
|
||||
return ChatWorkspacePane(id as String, session as String);
|
||||
}
|
||||
|
||||
static Rect? _rect(Object? values) {
|
||||
if (values is! List ||
|
||||
values.length != 4 ||
|
||||
values.any((v) => v is! num || !v.isFinite)) {
|
||||
return null;
|
||||
}
|
||||
final [left, top, width, height] = [
|
||||
for (final v in values) (v as num).toDouble(),
|
||||
];
|
||||
if (width <= 0 || height <= 0) return null;
|
||||
return Rect.fromLTWH(left, top, width, height);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
other is ChatFloatRecord &&
|
||||
other.pane?.id == pane?.id &&
|
||||
other.pane?.sessionId == pane?.sessionId &&
|
||||
other.shown == shown &&
|
||||
other.rect == rect;
|
||||
listEquals(
|
||||
[for (final p in other.panes) (p.id, p.sessionId)],
|
||||
[for (final p in panes) (p.id, p.sessionId)],
|
||||
) &&
|
||||
mapEquals(other.frames, frames);
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(pane?.id, pane?.sessionId, shown, rect);
|
||||
int get hashCode => Object.hash(
|
||||
shown,
|
||||
Object.hashAll([for (final p in panes) (p.id, p.sessionId)]),
|
||||
Object.hashAllUnordered([
|
||||
for (final MapEntry(:key, :value) in frames.entries) (key, value),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
bool _identity(Object? value, int limit) =>
|
||||
|
||||
@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/window_margins.dart';
|
||||
import '../../terminal/terminal_float_frame.dart' show terminalFloatChrome;
|
||||
import 'chat_float_binding.dart';
|
||||
import 'chat_float_store.dart';
|
||||
|
||||
/// [rect] moved and shrunk to fit inside [bounds], at least the smallest
|
||||
@@ -24,13 +23,16 @@ Rect fitChatFloat(Rect rect, Size bounds) {
|
||||
);
|
||||
}
|
||||
|
||||
/// The floating chat's window: moved by its title bar, resized from its
|
||||
/// A floating chat's window: moved by its title bar, resized from its
|
||||
/// lower right corner, kept inside [bounds]. It grows and fades in from its
|
||||
/// place as [reveal] runs forward and leaves the same way in reverse.
|
||||
class ChatFloatWindow extends StatelessWidget {
|
||||
const ChatFloatWindow({
|
||||
super.key,
|
||||
required this.frame,
|
||||
required this.rect,
|
||||
required this.currentRect,
|
||||
required this.onMove,
|
||||
required this.onCommit,
|
||||
required this.bounds,
|
||||
required this.title,
|
||||
required this.cupertino,
|
||||
@@ -43,7 +45,15 @@ class ChatFloatWindow extends StatelessWidget {
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final ChatFloatFrame frame;
|
||||
/// The saved frame; it is drawn fitted inside [bounds].
|
||||
final Rect rect;
|
||||
|
||||
/// The frame now: several drag events can arrive before a rebuild.
|
||||
final Rect Function() currentRect;
|
||||
final ValueChanged<Rect> onMove;
|
||||
|
||||
/// A move or resize ended.
|
||||
final VoidCallback onCommit;
|
||||
final Size bounds;
|
||||
final String title;
|
||||
final bool cupertino;
|
||||
@@ -62,8 +72,8 @@ class ChatFloatWindow extends StatelessWidget {
|
||||
static const double revealScale = 0.92;
|
||||
|
||||
void _resize(Offset delta) {
|
||||
final rect = fitChatFloat(frame.rect, bounds);
|
||||
frame.move(
|
||||
final rect = fitChatFloat(currentRect(), bounds);
|
||||
onMove(
|
||||
fitChatFloat(
|
||||
Rect.fromLTWH(
|
||||
rect.left,
|
||||
@@ -78,7 +88,7 @@ class ChatFloatWindow extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final rect = fitChatFloat(frame.rect, bounds);
|
||||
final rect = fitChatFloat(this.rect, bounds);
|
||||
final window = SizedBox.fromSize(
|
||||
size: rect.size,
|
||||
child: Stack(
|
||||
@@ -122,7 +132,7 @@ class ChatFloatWindow extends StatelessWidget {
|
||||
).animate(reveal),
|
||||
child: Semantics(
|
||||
container: true,
|
||||
label: 'Floating chat',
|
||||
label: 'Floating chat: $title',
|
||||
identifier: 'chat-float-window',
|
||||
child: terminalFloatChrome(context, cupertino, window),
|
||||
),
|
||||
@@ -149,13 +159,13 @@ class ChatFloatWindow extends StatelessWidget {
|
||||
key: const ValueKey('chat-float-title'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
dragStartBehavior: DragStartBehavior.down,
|
||||
onPanUpdate: (details) => frame.move(
|
||||
onPanUpdate: (details) => onMove(
|
||||
fitChatFloat(
|
||||
fitChatFloat(frame.rect, bounds).shift(details.delta),
|
||||
fitChatFloat(currentRect(), bounds).shift(details.delta),
|
||||
bounds,
|
||||
),
|
||||
),
|
||||
onPanEnd: (_) => frame.commit(),
|
||||
onPanEnd: (_) => onCommit(),
|
||||
child: Padding(
|
||||
padding: const EdgeInsetsDirectional.only(start: 12),
|
||||
child: Align(
|
||||
@@ -175,7 +185,7 @@ class ChatFloatWindow extends StatelessWidget {
|
||||
onDock,
|
||||
),
|
||||
_button(
|
||||
'Hide floating chat ($shortcut)',
|
||||
'Hide floating chats ($shortcut)',
|
||||
Icons.close,
|
||||
CupertinoIcons.xmark,
|
||||
onHide,
|
||||
@@ -206,7 +216,7 @@ class ChatFloatWindow extends StatelessWidget {
|
||||
behavior: HitTestBehavior.opaque,
|
||||
dragStartBehavior: DragStartBehavior.down,
|
||||
onPanUpdate: (details) => _resize(details.delta),
|
||||
onPanEnd: (_) => frame.commit(),
|
||||
onPanEnd: (_) => onCommit(),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(4),
|
||||
child: Icon(
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../ui/floating/floating_layer.dart';
|
||||
import '../../../ui/motion/motion.dart';
|
||||
import '../../../ui/motion/quick_switch_animation.dart';
|
||||
import 'chat_center_stage_layout.dart';
|
||||
@@ -44,7 +45,7 @@ class ChatWorkspace extends StatefulWidget {
|
||||
this.onVisibleSessionIdsChanged,
|
||||
this.centerStage,
|
||||
this.paneColor,
|
||||
this.floatFrame,
|
||||
this.floatFrames,
|
||||
});
|
||||
final ChatWorkspaceController controller;
|
||||
final ChatWorkspacePaneBuilder paneBuilder;
|
||||
@@ -64,9 +65,10 @@ class ChatWorkspace extends StatefulWidget {
|
||||
/// A pane's chat colour, for its strip beside the stage.
|
||||
final Color? Function(ChatWorkspacePane)? paneColor;
|
||||
|
||||
/// Offers the floating chat (see [ChatFloatHost]) in this frame; null for a
|
||||
/// workspace without one. It shows only while the panes are not collapsed.
|
||||
final ChatFloatFrame? floatFrame;
|
||||
/// Offers floating chats (see [ChatFloatHost]) in these frames; null for a
|
||||
/// workspace without them. They show only while the panes are not
|
||||
/// collapsed.
|
||||
final ChatFloatFrames? floatFrames;
|
||||
|
||||
/// Keyboard navigation only: the owner can focus the target composer.
|
||||
/// Pointer activation leaves text-selection and pointer focus alone.
|
||||
@@ -293,10 +295,13 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
: !collapsed || pane.id == activeId)
|
||||
pane.sessionId,
|
||||
});
|
||||
final floating = widget.floatFrame == null
|
||||
? null
|
||||
: widget.controller.floatingPane;
|
||||
final existing = {...panes.map((p) => p.id), ?floating?.id};
|
||||
final floating = widget.floatFrames == null
|
||||
? const <ChatWorkspacePane>[]
|
||||
: widget.controller.floatingPanes;
|
||||
final existing = {
|
||||
...panes.map((p) => p.id),
|
||||
...floating.map((p) => p.id),
|
||||
};
|
||||
_views.removeWhere((id, _) => !existing.contains(id));
|
||||
for (final id
|
||||
in _panes.keys.where((id) => !existing.contains(id)).toList()) {
|
||||
@@ -359,17 +364,15 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
moveTargets[pane.id],
|
||||
),
|
||||
);
|
||||
final frame = widget.floatFrame;
|
||||
if (frame == null) return surface;
|
||||
final frames = widget.floatFrames;
|
||||
if (frames == null) return surface;
|
||||
return ChatFloatHost(
|
||||
controller: widget.controller,
|
||||
frame: frame,
|
||||
frames: frames,
|
||||
enabled: !widget.singlePane,
|
||||
title: floating == null
|
||||
? ''
|
||||
: widget.paneTitle?.call(floating) ?? floating.sessionId,
|
||||
content: floating == null ? null : _floatView(floating),
|
||||
scope: floating == null ? null : _panes[floating.id],
|
||||
title: (pane) => widget.paneTitle?.call(pane) ?? pane.sessionId,
|
||||
content: _floatView,
|
||||
scope: (pane) => _panes[pane.id],
|
||||
focusedPane: () => widget.controller.panes
|
||||
.where((pane) => _panes[pane.id]?.hasFocus ?? false)
|
||||
.firstOrNull,
|
||||
@@ -438,10 +441,18 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
);
|
||||
}
|
||||
|
||||
/// The floating chat's view: the same keyed content as in the tiling, so
|
||||
/// floating and docking move it without rebuilding the chat.
|
||||
Widget _floatView(ChatWorkspacePane pane) =>
|
||||
_paneContent(pane, active: true, peek: false, mobile: false, edges: {});
|
||||
/// A floating chat's view: the same keyed content as in the tiling, so
|
||||
/// floating and docking move it without rebuilding the chat. Its focus
|
||||
/// hangs from the shell's [FloatingFocusRoot], so it keeps the keyboard
|
||||
/// while another destination (which excludes this one) shows.
|
||||
Widget _floatView(ChatWorkspacePane pane) => _paneContent(
|
||||
pane,
|
||||
active: true,
|
||||
peek: false,
|
||||
mobile: false,
|
||||
edges: {},
|
||||
focusParent: FloatingFocusRoot.maybeOf(context),
|
||||
);
|
||||
|
||||
Widget _paneContent(
|
||||
ChatWorkspacePane pane, {
|
||||
@@ -450,9 +461,11 @@ class _ChatWorkspaceState extends State<ChatWorkspace>
|
||||
required bool mobile,
|
||||
required Set<String> edges,
|
||||
Map<ChatPaneDirection, String>? moveTargets,
|
||||
FocusNode? focusParent,
|
||||
}) => KeyedSubtree(
|
||||
key: _views.putIfAbsent(pane.id, () => GlobalKey(debugLabel: pane.id)),
|
||||
child: FocusScope(
|
||||
parentNode: focusParent,
|
||||
node: _panes.putIfAbsent(
|
||||
pane.id,
|
||||
() => FocusScopeNode(debugLabel: pane.id),
|
||||
|
||||
@@ -12,8 +12,9 @@ class ChatWorkspaceController extends ChangeNotifier {
|
||||
ChatWorkspaceNode? _root;
|
||||
String? _active;
|
||||
|
||||
/// The chat taken out of the tiling into the floating window, if any.
|
||||
ChatWorkspacePane? _floating;
|
||||
/// The chats taken out of the tiling into floating windows, oldest first.
|
||||
/// They show and hide together.
|
||||
final List<ChatWorkspacePane> _floating = [];
|
||||
bool _floatShown = false;
|
||||
double _mobilePeekFraction = .2;
|
||||
double get mobilePeekFraction => _mobilePeekFraction;
|
||||
@@ -55,7 +56,7 @@ class ChatWorkspaceController extends ChangeNotifier {
|
||||
}
|
||||
|
||||
collect(_root);
|
||||
collect(_floating);
|
||||
_floating.forEach(collect);
|
||||
String id;
|
||||
do {
|
||||
id = 'chat-$kind-${++_serial}';
|
||||
@@ -69,7 +70,7 @@ class ChatWorkspaceController extends ChangeNotifier {
|
||||
_root = snapshot.root;
|
||||
_active = snapshot.activePaneId;
|
||||
_mobilePeekFraction = snapshot.mobilePeekFraction;
|
||||
_floating = null;
|
||||
_floating.clear();
|
||||
_serial = 0;
|
||||
_changed();
|
||||
return true;
|
||||
|
||||
@@ -1,55 +1,49 @@
|
||||
part of 'chat_workspace_controller.dart';
|
||||
|
||||
/// One chat at a time can leave the split tiling for a floating window over
|
||||
/// the app. The floating pane keeps its id (and so its live view) while it
|
||||
/// floats, hides, docks or swaps places with another pane.
|
||||
/// Chats can leave the split tiling for floating windows over the app. They
|
||||
/// show and hide together. A floating pane keeps its id (and so its live view)
|
||||
/// while it floats, hides or docks.
|
||||
extension ChatWorkspaceFloat on ChatWorkspaceController {
|
||||
/// The floating chat, shown or hidden.
|
||||
ChatWorkspacePane? get floatingPane => _floating;
|
||||
/// The floating chats, shown or hidden, oldest first.
|
||||
List<ChatWorkspacePane> get floatingPanes => List.unmodifiable(_floating);
|
||||
|
||||
/// Whether the floating chat is shown (rather than hidden by Ctrl+Y).
|
||||
bool get floatShown => _floating != null && _floatShown;
|
||||
/// Whether [paneId] floats.
|
||||
bool isFloating(String paneId) => _floating.any((pane) => pane.id == paneId);
|
||||
|
||||
/// Whether [sessionId] is open in the tiling or the floating window.
|
||||
/// Whether the floating chats are shown (rather than hidden by Ctrl+Y).
|
||||
bool get floatShown => _floating.isNotEmpty && _floatShown;
|
||||
|
||||
/// Whether [sessionId] is open in the tiling or a floating window.
|
||||
bool holdsSession(String sessionId) =>
|
||||
_floating?.sessionId == sessionId ||
|
||||
_floating.any((pane) => pane.sessionId == sessionId) ||
|
||||
panes.any((pane) => pane.sessionId == sessionId);
|
||||
|
||||
/// A tiled pane can float when another chat stays in the tiling: a second
|
||||
/// tiled pane, or the chat floating now (which takes its place).
|
||||
/// A tiled pane can float while another chat stays in the tiling.
|
||||
bool canFloat(String paneId) =>
|
||||
panes.any((pane) => pane.id == paneId) &&
|
||||
(paneCount > 1 || _floating != null);
|
||||
paneCount > 1 && panes.any((pane) => pane.id == paneId);
|
||||
|
||||
/// Floats the tiled pane [paneId]. A chat already floating returns to the
|
||||
/// tiling in the place [paneId] leaves.
|
||||
/// Floats the tiled pane [paneId] and shows every floating chat.
|
||||
void float(String paneId) {
|
||||
if (!canFloat(paneId)) return;
|
||||
final pane = panes.firstWhere((pane) => pane.id == paneId);
|
||||
final previous = _floating;
|
||||
if (previous != null) {
|
||||
_root = _replace(_root!, paneId, previous);
|
||||
if (_active == paneId) _active = previous.id;
|
||||
} else {
|
||||
final index = panes.indexWhere((p) => p.id == paneId);
|
||||
_root = _remove(_root!, paneId);
|
||||
if (_active == paneId) {
|
||||
final after = panes;
|
||||
_active = after[index.clamp(0, after.length - 1)].id;
|
||||
}
|
||||
final index = panes.indexWhere((p) => p.id == paneId);
|
||||
_root = _remove(_root!, paneId);
|
||||
if (_active == paneId) {
|
||||
final after = panes;
|
||||
_active = after[index.clamp(0, after.length - 1)].id;
|
||||
}
|
||||
_floating = pane;
|
||||
_floating.add(pane);
|
||||
_floatShown = true;
|
||||
_changed();
|
||||
}
|
||||
|
||||
/// Puts the floating chat back into the tiling, to the right of the
|
||||
/// active pane, and makes it the active pane.
|
||||
void dock() {
|
||||
final pane = _floating;
|
||||
if (pane == null) return;
|
||||
/// Puts the floating chat [paneId] back into the tiling, to the right of
|
||||
/// the active pane, and makes it the active pane.
|
||||
void dock(String paneId) {
|
||||
final at = _floating.indexWhere((pane) => pane.id == paneId);
|
||||
if (at < 0) return;
|
||||
final pane = _floating.removeAt(at);
|
||||
final split = _id('split');
|
||||
_floating = null;
|
||||
if (_root == null) {
|
||||
_root = pane;
|
||||
} else {
|
||||
@@ -65,70 +59,82 @@ extension ChatWorkspaceFloat on ChatWorkspaceController {
|
||||
}
|
||||
|
||||
void setFloatShown(bool shown) {
|
||||
if (_floating == null || _floatShown == shown) return;
|
||||
if (_floating.isEmpty || _floatShown == shown) return;
|
||||
_floatShown = shown;
|
||||
_changed();
|
||||
}
|
||||
|
||||
void toggleFloatShown() => setFloatShown(!_floatShown);
|
||||
|
||||
/// Restores a saved floating chat unless its session is already open or
|
||||
/// its pane id is taken. With no tiled pane it becomes the tiling instead.
|
||||
bool restoreFloat(ChatWorkspacePane pane, {required bool shown}) {
|
||||
if (_floating != null || holdsSession(pane.sessionId)) return false;
|
||||
bool taken(ChatWorkspaceNode? node) =>
|
||||
node != null &&
|
||||
(node.id == pane.id ||
|
||||
node is ChatWorkspaceSplit &&
|
||||
(taken(node.first) || taken(node.second)));
|
||||
if (taken(_root)) return false;
|
||||
if (_root == null) {
|
||||
_root = pane;
|
||||
_active = pane.id;
|
||||
} else {
|
||||
_floating = pane;
|
||||
_floatShown = shown;
|
||||
/// Restores saved floating chats, skipping any whose session is already
|
||||
/// open or whose pane id is taken. With no tiled pane the first becomes
|
||||
/// the tiling instead. Returns how many were restored.
|
||||
int restoreFloats(List<ChatWorkspacePane> saved, {required bool shown}) {
|
||||
var restored = 0;
|
||||
for (final pane in saved) {
|
||||
if (holdsSession(pane.sessionId) || _taken(pane.id)) continue;
|
||||
if (_root == null) {
|
||||
_root = pane;
|
||||
_active = pane.id;
|
||||
} else {
|
||||
_floating.add(pane);
|
||||
}
|
||||
restored++;
|
||||
}
|
||||
if (restored == 0) return 0;
|
||||
_floatShown = shown;
|
||||
_changed();
|
||||
return true;
|
||||
return restored;
|
||||
}
|
||||
|
||||
/// Opening the floating chat (from the list, a link) shows it.
|
||||
bool _taken(String id) {
|
||||
bool inTree(ChatWorkspaceNode? node) =>
|
||||
node != null &&
|
||||
(node.id == id ||
|
||||
node is ChatWorkspaceSplit &&
|
||||
(inTree(node.first) || inTree(node.second)));
|
||||
return inTree(_root) || isFloating(id);
|
||||
}
|
||||
|
||||
/// Opening a floating chat (from the list, a link) shows the floats.
|
||||
bool _showFloating(String sessionId) {
|
||||
if (_floating?.sessionId != sessionId) return false;
|
||||
if (!_floating.any((pane) => pane.sessionId == sessionId)) return false;
|
||||
setFloatShown(true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _closeFloating(String paneId) {
|
||||
if (_floating?.id != paneId) return false;
|
||||
_floating = null;
|
||||
final at = _floating.indexWhere((pane) => pane.id == paneId);
|
||||
if (at < 0) return false;
|
||||
_floating.removeAt(at);
|
||||
_changed();
|
||||
return true;
|
||||
}
|
||||
|
||||
/// The tiling never empties while a chat floats: the floating chat docks.
|
||||
/// The tiling never empties while a chat floats: the oldest one docks.
|
||||
void _adoptFloatingIfEmpty() {
|
||||
if (_root != null || _floating == null) return;
|
||||
_root = _floating;
|
||||
_floating = null;
|
||||
if (_root != null || _floating.isEmpty) return;
|
||||
_root = _floating.removeAt(0);
|
||||
}
|
||||
|
||||
/// `/new` in the floating chat keeps it floating under the new session.
|
||||
/// `/new` in a floating chat keeps it floating under the new session.
|
||||
bool _replaceFloating(String oldId, String newId) {
|
||||
final pane = _floating;
|
||||
if (pane == null) return false;
|
||||
if (pane.sessionId == oldId) {
|
||||
if (panes.any((p) => p.sessionId == newId)) {
|
||||
final at = _floating.indexWhere((pane) => pane.sessionId == oldId);
|
||||
if (at >= 0) {
|
||||
final pane = _floating[at];
|
||||
final elsewhere =
|
||||
panes.any((p) => p.sessionId == newId) ||
|
||||
_floating.any((p) => p.sessionId == newId);
|
||||
if (elsewhere) {
|
||||
_closeFloating(pane.id);
|
||||
} else {
|
||||
_floating = ChatWorkspacePane(pane.id, newId);
|
||||
_floating[at] = ChatWorkspacePane(pane.id, newId);
|
||||
_changed();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (pane.sessionId != newId) return false;
|
||||
// A tiled chat moved to the session that floats: the float stays.
|
||||
if (!_floating.any((pane) => pane.sessionId == newId)) return false;
|
||||
// A tiled chat moved to a session that floats: the float stays.
|
||||
final tiled = panes.where((p) => p.sessionId == oldId).firstOrNull;
|
||||
if (tiled != null) close(tiled.id);
|
||||
setFloatShown(true);
|
||||
|
||||
@@ -142,8 +142,10 @@ class ChatWorkspaceGeometry {
|
||||
};
|
||||
if (gap < -slack || gap > chatPaneDividerExtent + slack) continue;
|
||||
final overlap = horizontal
|
||||
? math.min(origin.bottom, rect.bottom) - math.max(origin.top, rect.top)
|
||||
: math.min(origin.right, rect.right) - math.max(origin.left, rect.left);
|
||||
? math.min(origin.bottom, rect.bottom) -
|
||||
math.max(origin.top, rect.top)
|
||||
: math.min(origin.right, rect.right) -
|
||||
math.max(origin.left, rect.left);
|
||||
if (overlap <= slack) continue;
|
||||
final centred = horizontal
|
||||
? rect.top <= centre && centre < rect.bottom
|
||||
|
||||
Reference in New Issue
Block a user