voelin-gpui: the server shown after a removal has its remembered folds

restore_tree (the folds ui.tree remembers for a server, put into its session
once) ran only in select_server, so the server that came on screen when the
one shown was removed, or when a save or a connect put another on screen, had
none of its folds: its tree showed everything open, and the next fold wrote
the one just made over what was stored.

transition_with, which every transition runs through, now restores the folds
of whichever server it leaves on screen before anything draws it, and
select_server no longer does it by itself. Two tests: removing the server on
screen shows the next with its stored fold, and a fold made then is added to
it where it used to replace it ([3, 7], not [3]); a save of another server
shows it the same way. Both failed on the code before (no session for the
server shown, so no folds).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-28 07:43:24 +03:00
1 parent 122b2d29fa
commit cc143f312d
2 files changed
+75 -3

No files matched your search

+74 -2
View File
@@ -535,6 +535,13 @@ impl AppState {
let mut transition = Cx::new(&host);
let result = f(&mut self.vm, &mut transition, &backing);
let update = transition.update;
// Whichever server the transition left on screen (a removal shows the
// first, a save the saved one, a connect the one it connects) has its
// remembered folds before the tree is built from it, and before the
// next fold writes them over.
if let Some(id) = self.vm.current {
self.restore_tree(id);
}
let refresh = self.perform(update, cx);
self.signals.raise(&refresh, cx);
result
@@ -788,7 +795,6 @@ impl AppState {
/// Show a server, and observe it.
pub fn select_server(&mut self, id: i64, cx: &mut Context<Self>) {
self.restore_tree(id);
self.transition_with(cx, |state, cx, backing| {
sequence::select_server(state, cx, backing, id)
});
@@ -936,7 +942,10 @@ impl AppState {
self.transition(cx, |state, cx| logic::open_member(state, cx, client));
}
/// Put the folds a server's tree remembered into its session, once.
/// Put the folds a server's tree remembered into its session, once: every
/// transition that can change the server on screen
/// ([`AppState::transition_with`]) and the start do it for the one that is
/// shown.
fn restore_tree(&mut self, id: i64) {
if self.switches.demo_ui || !self.tree_restored.insert(id) {
return;
@@ -1124,6 +1133,7 @@ mod tests {
use voelin_core::{Backends, Command, Event, ObserveState, SessionState, VoiceState};
use voelin_store::MemorySecrets;
use voelin_ui_vm::dev::logic as sample;
use voelin_ui_vm::settings::TreeState;
use super::*;
use crate::backend::testing::TempDir;
@@ -1487,6 +1497,68 @@ mod tests {
});
}
/// Two saved servers, the second with a fold remembered in `ui.tree`.
fn two_servers_the_second_with_a_fold() -> (Backend, [i64; 2]) {
let backend = backend_with(&[("Nightfall", "ts.example"), ("Lounge", "lounge.example")]);
let ids: Vec<i64> = backend.store.bookmarks().unwrap().iter().map(|b| b.id).collect();
let fold = TreeState { collapsed: vec![7], selected: None };
backend.prefs.set(&UI_TREE, TreeStates::from([(ids[1].to_string(), fold)])).unwrap();
(backend, [ids[0], ids[1]])
}
/// What `ui.tree` holds of a server.
fn remembered(app: &Entity<AppState>, id: i64, cx: &mut TestAppContext) -> Option<TreeState> {
app.read_with(cx, |app, _| app.backend().prefs.get(&UI_TREE).remove(&id.to_string()))
}
/// The server that comes on screen when the one shown is removed has the
/// folds `ui.tree` remembers for it, and the next fold adds to them where
/// it used to write over them (the session had none, so the stored ones
/// were replaced by the one just made).
#[gpui::test]
fn the_server_shown_after_a_removal_has_its_remembered_folds(cx: &mut TestAppContext) {
let (backend, [first, second]) = two_servers_the_second_with_a_fold();
let (app, _, _) = entity_over(cx, backend, Switches::default());
app.read_with(cx, |app, _| assert_eq!(app.vm.current, Some(first)));
app.update(cx, |app, cx| app.delete_bookmark(first, cx));
app.read_with(cx, |app, _| {
assert_eq!(app.vm.current, Some(second));
assert_eq!(app.vm.sessions[&second].collapsed, HashSet::from([7]));
});
app.update(cx, |app, cx| app.toggle_collapse(3, cx));
assert_eq!(
remembered(&app, second, cx),
Some(TreeState { collapsed: vec![3, 7], selected: None }),
"the fold made now is added to the one remembered"
);
}
/// The same for a server a save brings on screen: editing another server
/// shows it.
#[gpui::test]
fn a_server_a_save_shows_has_its_remembered_folds(cx: &mut TestAppContext) {
let (backend, [first, second]) = two_servers_the_second_with_a_fold();
let (app, _, _) = entity_over(cx, backend, Switches::default());
app.read_with(cx, |app, _| {
assert_eq!(app.vm.current, Some(first));
assert!(!app.vm.sessions.contains_key(&second), "not shown yet, not put back yet");
});
let form = app.read_with(cx, |app, _| app.bookmark_form(second));
app.update(cx, |app, cx| app.save_bookmark(&form, cx));
app.read_with(cx, |app, _| {
assert_eq!(app.vm.current, Some(second));
assert_eq!(app.vm.sessions[&second].collapsed, HashSet::from([7]));
});
app.update(cx, |app, cx| app.toggle_collapse(3, cx));
assert_eq!(
remembered(&app, second, cx),
Some(TreeState { collapsed: vec![3, 7], selected: None })
);
}
#[gpui::test]
fn a_removed_server_goes_from_the_rail_and_the_store_and_the_first_is_shown(
cx: &mut TestAppContext,
+1 -1
View File
@@ -1237,7 +1237,7 @@ front end](#shared-with-the-slint-front-end)):
| `edit_bookmark` | `EditServer { id }` | opens the form with `servers::form` |
| `save_bookmark` | `SaveServer` | `logic::bookmark_from_form`, the store, the secrets; shows the server |
| `save_and_connect` | `SaveAndConnect` | saves, then connects into the form's channel or the default one (`servers::connect_to`) |
| `delete_bookmark` | `DeleteServer { id }` | `CloseSession`, the secrets and the store, `logic::forget_server` |
| `delete_bookmark` | `DeleteServer { id }` | `CloseSession`, the secrets and the store, `logic::forget_server`; the server that comes on screen has its remembered folds put back (as has any server a transition puts on screen: a save, a connect) |
| `invite` | `Invite` | `logic::invite_link`, the link on the clipboard, the status line's note |
The others of that file: `join_channel`, `join_with_password`, `toggle_collapse`,