From 866176dab64fc2a08b393dcc33076d05da38eafa Mon Sep 17 00:00:00 2001 From: Joscha Date: Sat, 22 Feb 2025 12:30:38 +0100 Subject: [PATCH] Move cursor to new room in room list --- CHANGELOG.md | 1 + cove/src/ui/rooms.rs | 1 + cove/src/ui/widgets/list.rs | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f365f7b..fb950a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Procedure when bumping the version number: ### Updated - Documentation for `time_zone` config option +- When connecting to a room using `n` in the room list, the cursor now moves to that room ## v0.8.3 - 2024-05-20 diff --git a/cove/src/ui/rooms.rs b/cove/src/ui/rooms.rs index a6e7b34..04bce02 100644 --- a/cove/src/ui/rooms.rs +++ b/cove/src/ui/rooms.rs @@ -589,6 +589,7 @@ impl Rooms { return true; } ConnectResult::Connect(room) => { + self.list.move_cursor_to_id(&room); self.connect_to_room(room.clone()).await; self.state = State::ShowRoom(room); return true; diff --git a/cove/src/ui/widgets/list.rs b/cove/src/ui/widgets/list.rs index bb27540..3d7c6c8 100644 --- a/cove/src/ui/widgets/list.rs +++ b/cove/src/ui/widgets/list.rs @@ -239,6 +239,12 @@ impl ListState { }) } + pub fn move_cursor_to_id(&mut self, id: &Id) { + if let Some(new_cursor) = self.selectable_of_id(id) { + self.move_cursor_to(new_cursor); + } + } + fn fix_cursor(&mut self) { let new_cursor = if let Some(cursor) = &self.cursor { self.selectable_of_id(&cursor.id)