columns: enable toolbar scroll to top
Fixes: https://github.com/damus-io/notedeck/issues/969 Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -42,6 +42,18 @@ pub struct Columns {
|
||||
pub selected: i32,
|
||||
}
|
||||
|
||||
/// When selecting columns, return what happened
|
||||
pub enum SelectionResult {
|
||||
/// We're already selecting that
|
||||
AlreadySelected(usize),
|
||||
|
||||
/// New selection success!
|
||||
NewSelection(usize),
|
||||
|
||||
/// Failed to make a selection
|
||||
Failed,
|
||||
}
|
||||
|
||||
impl Columns {
|
||||
pub fn new() -> Self {
|
||||
Columns::default()
|
||||
@@ -60,20 +72,25 @@ impl Columns {
|
||||
/// Select the column based on the timeline kind.
|
||||
///
|
||||
/// TODO: add timeline if missing?
|
||||
pub fn select_by_kind(&mut self, kind: &TimelineKind) {
|
||||
pub fn select_by_kind(&mut self, kind: &TimelineKind) -> SelectionResult {
|
||||
for (i, col) in self.columns.iter().enumerate() {
|
||||
for route in col.router().routes() {
|
||||
if let Some(timeline) = route.timeline_id() {
|
||||
if timeline == kind {
|
||||
tracing::info!("selecting {kind:?} column");
|
||||
self.select_column(i as i32);
|
||||
return;
|
||||
if self.selected as usize == i {
|
||||
return SelectionResult::AlreadySelected(i);
|
||||
} else {
|
||||
self.select_column(i as i32);
|
||||
return SelectionResult::NewSelection(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tracing::error!("failed to select {kind:?} column");
|
||||
SelectionResult::Failed
|
||||
}
|
||||
|
||||
pub fn add_new_timeline_column(
|
||||
|
||||
Reference in New Issue
Block a user