Skip to content

Commit 80b8a6d

Browse files
committed
feat(multiverse): Allow timeline items to be selected
1 parent f7265c3 commit 80b8a6d

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

labs/multiverse/src/widgets/room_view/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub struct RoomView {
4848

4949
mode: Mode,
5050

51+
timeline_list: ListState,
52+
5153
input: Input,
5254
}
5355

@@ -61,6 +63,7 @@ impl RoomView {
6163
current_pagination: Default::default(),
6264
mode: Mode::Normal { invited_room_view: None },
6365
input: Input::new(),
66+
timeline_list: ListState::default(),
6467
}
6568
}
6669

@@ -125,6 +128,14 @@ impl RoomView {
125128
}
126129
}
127130

131+
(_, Down) | (KeyModifiers::CONTROL, Char('n')) => {
132+
self.timeline_list.select_next()
133+
}
134+
(_, Up) | (KeyModifiers::CONTROL, Char('p')) => {
135+
self.timeline_list.select_previous()
136+
}
137+
(_, Esc) => self.timeline_list.select(None),
138+
128139
_ => self.input.handle_key_press(key),
129140
}
130141
}
@@ -197,6 +208,7 @@ impl RoomView {
197208
}
198209
}
199210

211+
self.timeline_list = ListState::default();
200212
self.selected_room = room;
201213
}
202214

@@ -458,7 +470,7 @@ impl Widget for &mut RoomView {
458470
let items = items.lock();
459471
let mut timeline = TimelineView::new(items.deref());
460472

461-
timeline.render(timeline_area, buf);
473+
timeline.render(timeline_area, buf, &mut self.timeline_list);
462474
}
463475
}
464476
} else {

labs/multiverse/src/widgets/room_view/timeline.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ impl<'a> TimelineView<'a> {
2020
}
2121
}
2222

23-
impl Widget for &mut TimelineView<'_> {
24-
fn render(self, area: Rect, buf: &mut Buffer)
23+
impl StatefulWidget for &mut TimelineView<'_> {
24+
type State = ListState;
25+
26+
fn render(self, area: Rect, buf: &mut Buffer, state: &mut Self::State)
2527
where
2628
Self: Sized,
2729
{
@@ -139,10 +141,11 @@ impl Widget for &mut TimelineView<'_> {
139141
})
140142
.collect::<Vec<_>>();
141143

142-
let list = List::new(list_items).highlight_spacing(HighlightSpacing::Always);
143-
144-
let mut dummy_list_state = ListState::default();
144+
let list = List::new(list_items)
145+
.highlight_spacing(HighlightSpacing::Always)
146+
.highlight_symbol(">")
147+
.highlight_style(SELECTED_STYLE_FG);
145148

146-
StatefulWidget::render(list, area, buf, &mut dummy_list_state);
149+
StatefulWidget::render(list, area, buf, state);
147150
}
148151
}

0 commit comments

Comments
 (0)