feat(multiverse): Allow timeline items to be selected

This commit is contained in:
Damir Jelić
2025-06-04 11:13:45 +02:00
parent f7265c39e0
commit 80b8a6d8cc
2 changed files with 22 additions and 7 deletions

View File

@@ -48,6 +48,8 @@ pub struct RoomView {
mode: Mode,
timeline_list: ListState,
input: Input,
}
@@ -61,6 +63,7 @@ impl RoomView {
current_pagination: Default::default(),
mode: Mode::Normal { invited_room_view: None },
input: Input::new(),
timeline_list: ListState::default(),
}
}
@@ -125,6 +128,14 @@ impl RoomView {
}
}
(_, Down) | (KeyModifiers::CONTROL, Char('n')) => {
self.timeline_list.select_next()
}
(_, Up) | (KeyModifiers::CONTROL, Char('p')) => {
self.timeline_list.select_previous()
}
(_, Esc) => self.timeline_list.select(None),
_ => self.input.handle_key_press(key),
}
}
@@ -197,6 +208,7 @@ impl RoomView {
}
}
self.timeline_list = ListState::default();
self.selected_room = room;
}
@@ -458,7 +470,7 @@ impl Widget for &mut RoomView {
let items = items.lock();
let mut timeline = TimelineView::new(items.deref());
timeline.render(timeline_area, buf);
timeline.render(timeline_area, buf, &mut self.timeline_list);
}
}
} else {

View File

@@ -20,8 +20,10 @@ impl<'a> TimelineView<'a> {
}
}
impl Widget for &mut TimelineView<'_> {
fn render(self, area: Rect, buf: &mut Buffer)
impl StatefulWidget for &mut TimelineView<'_> {
type State = ListState;
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State)
where
Self: Sized,
{
@@ -139,10 +141,11 @@ impl Widget for &mut TimelineView<'_> {
})
.collect::<Vec<_>>();
let list = List::new(list_items).highlight_spacing(HighlightSpacing::Always);
let list = List::new(list_items)
.highlight_spacing(HighlightSpacing::Always)
.highlight_symbol(">")
.highlight_style(SELECTED_STYLE_FG);
let mut dummy_list_state = ListState::default();
StatefulWidget::render(list, area, buf, &mut dummy_list_state);
StatefulWidget::render(list, area, buf, state);
}
}