Merge: Next chat button cycles through the list
This commit is contained in:
@@ -10,14 +10,17 @@ import 'session_row_style.dart';
|
||||
typedef ChatSessionSection = ({String title, List<JsonMap> sessions});
|
||||
|
||||
/// Which list sections are folded away, kept by the list's screen so the
|
||||
/// keyboard shortcuts count only rows on screen. Closed starts folded.
|
||||
class ChatSectionFolds {
|
||||
/// keyboard shortcuts and Next chat count only rows on screen. Closed starts
|
||||
/// folded. It notifies when a section folds or unfolds.
|
||||
class ChatSectionFolds extends ChangeNotifier {
|
||||
final Set<String> _folded = {'Closed'};
|
||||
|
||||
bool isOpen(String title) => !_folded.contains(title);
|
||||
|
||||
void set(String title, bool open) =>
|
||||
open ? _folded.remove(title) : _folded.add(title);
|
||||
void set(String title, bool open) {
|
||||
final changed = open ? _folded.remove(title) : _folded.add(title);
|
||||
if (changed) notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
/// Groups the visible sessions the way the server reports them.
|
||||
|
||||
@@ -11,6 +11,7 @@ import '../../../../shell/shell_bar.dart';
|
||||
import '../../../../shell/shell_list_shortcuts.dart';
|
||||
import '../../data/chat_repository.dart';
|
||||
import '../../domain/chat_colors.dart';
|
||||
import '../../domain/chat_cycle.dart';
|
||||
import '../../domain/chat_sessions.dart';
|
||||
import 'chat_adaptive.dart';
|
||||
import 'chat_color_picker.dart';
|
||||
@@ -35,6 +36,7 @@ class ChatSessionsScreen extends StatefulWidget {
|
||||
this.controller,
|
||||
this.activeSessionId,
|
||||
this.publishShellBar,
|
||||
this.folds,
|
||||
});
|
||||
final ApiGateway gateway;
|
||||
final void Function(JsonMap session) onOpen;
|
||||
@@ -71,6 +73,10 @@ class ChatSessionsScreen extends StatefulWidget {
|
||||
/// Null makes this screen own its own.
|
||||
final ChatSessionsController? controller;
|
||||
|
||||
/// Which sections are folded, when the destination keeps them (Next chat
|
||||
/// counts the same rows); null makes this screen keep its own.
|
||||
final ChatSectionFolds? folds;
|
||||
|
||||
@override
|
||||
State<ChatSessionsScreen> createState() => _ChatSessionsScreenState();
|
||||
}
|
||||
@@ -85,7 +91,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
..activeSessionId = widget.activeSessionId
|
||||
..refresh();
|
||||
final _search = TextEditingController();
|
||||
final _folds = ChatSectionFolds();
|
||||
late final ChatSectionFolds _folds = widget.folds ?? ChatSectionFolds();
|
||||
Timer? _undoTimer;
|
||||
String? _markedActiveSessionId;
|
||||
|
||||
@@ -140,6 +146,7 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
_undoTimer?.cancel();
|
||||
_controller.removeListener(_reportSessions);
|
||||
if (widget.controller == null) _controller.dispose();
|
||||
if (widget.folds == null) _folds.dispose();
|
||||
_search.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
@@ -203,9 +210,9 @@ class _ChatSessionsScreenState extends State<ChatSessionsScreen> {
|
||||
/// Ctrl+N: opens the Nth row the list draws (Starred first, then Chats by
|
||||
/// directory, then Closed while it is unfolded), searched as shown.
|
||||
bool _openIndex(int index) {
|
||||
final visible = filterChatSessions(_controller.sessions, _search.text);
|
||||
final rows = chatSessionsInListOrder(
|
||||
chatSessionSections(visible),
|
||||
final rows = chatSessionsShown(
|
||||
_controller.sessions,
|
||||
query: _search.text,
|
||||
isOpen: _folds.isOpen,
|
||||
);
|
||||
if (index < 0 || index >= rows.length) return false;
|
||||
|
||||
Reference in New Issue
Block a user