enter to expand database tree

pull/85/head
Takayuki Maeda 3 years ago
parent 6f8b13714a
commit 9d5fcfb18b

@ -16,6 +16,7 @@ pub enum MoveSelection {
Right,
Top,
End,
Enter,
}
#[derive(Debug, Clone, Copy)]
@ -112,6 +113,7 @@ impl DatabaseTree {
MoveSelection::Right => self.selection_right(selection),
MoveSelection::Top => Self::selection_start(selection),
MoveSelection::End => self.selection_end(selection),
MoveSelection::Enter => self.expand(selection),
};
let changed_index = new_index.map(|i| i != selection).unwrap_or_default();
@ -315,6 +317,26 @@ impl DatabaseTree {
self.select_parent(current_index)
}
fn expand(&mut self, current_selection: usize) -> Option<usize> {
let item = &mut self.items.tree_items.get(current_selection)?;
if item.kind().is_database() {
if item.kind().is_database_collapsed() {
self.items.expand(current_selection, false);
return None;
}
}
if item.kind().is_schema() {
if item.kind().is_schema_collapsed() {
self.items.expand(current_selection, false);
return None;
}
}
None
}
fn selection_right(&mut self, current_selection: usize) -> Option<usize> {
let item = &mut self.items.tree_items.get(current_selection)?;

@ -22,6 +22,8 @@ pub fn common_nav(key: Key, key_config: &KeyConfig) -> Option<MoveSelection> {
Some(MoveSelection::Top)
} else if key == key_config.scroll_to_bottom {
Some(MoveSelection::End)
} else if key == key_config.enter {
Some(MoveSelection::Enter)
} else {
None
}

Loading…
Cancel
Save