scrolling multiple line in databases and connections

pull/37/head
Takayuki Maeda 3 years ago
parent d493f46875
commit 6723e068f2

@ -10,6 +10,8 @@ use std::{collections::BTreeSet, usize};
pub enum MoveSelection {
Up,
Down,
MultipleUp,
MultipleDown,
Left,
Right,
Top,
@ -102,8 +104,10 @@ impl DatabaseTree {
pub fn move_selection(&mut self, dir: MoveSelection) -> bool {
self.selection.map_or(false, |selection| {
let new_index = match dir {
MoveSelection::Up => self.selection_updown(selection, true),
MoveSelection::Down => self.selection_updown(selection, false),
MoveSelection::Up => self.selection_updown(selection, true, 1),
MoveSelection::Down => self.selection_updown(selection, false, 1),
MoveSelection::MultipleUp => self.selection_updown(selection, true, 10),
MoveSelection::MultipleDown => self.selection_updown(selection, false, 10),
MoveSelection::Left => self.selection_left(selection),
MoveSelection::Right => self.selection_right(selection),
MoveSelection::Top => Self::selection_start(selection),
@ -188,15 +192,19 @@ impl DatabaseTree {
}
}
fn selection_updown(&self, current_index: usize, up: bool) -> Option<usize> {
fn selection_updown(&self, current_index: usize, up: bool, lines: usize) -> Option<usize> {
let mut index = current_index;
loop {
index = {
let new_index = if up {
index.saturating_sub(1)
index
.saturating_sub(lines)
.clamp(0, self.items.len().saturating_sub(1))
} else {
index.saturating_add(1)
index
.saturating_add(lines)
.clamp(0, self.items.len().saturating_sub(1))
};
if new_index == index {
@ -243,7 +251,7 @@ impl DatabaseTree {
let mut index = current_index;
while let Some(selection) = self.selection_updown(index, true) {
while let Some(selection) = self.selection_updown(index, true, 1) {
index = selection;
if self.items.tree_items[index].info().indent() < indent {
@ -282,7 +290,7 @@ impl DatabaseTree {
self.items.expand(current_selection, false);
return Some(current_selection);
}
return self.selection_updown(current_selection, false);
return self.selection_updown(current_selection, false, 1);
}
if item.kind().is_schema() {
@ -290,7 +298,7 @@ impl DatabaseTree {
self.items.expand(current_selection, false);
return Some(current_selection);
}
return self.selection_updown(current_selection, false);
return self.selection_updown(current_selection, false, 1);
}
None

@ -24,7 +24,9 @@ impl DatabaseTreeItems {
tree_items: self
.tree_items
.iter()
.filter(|item| item.is_database() || item.is_match(&filter_text))
.filter(|item| {
item.is_database() || item.kind().is_schema() || item.is_match(&filter_text)
})
.map(|item| {
let mut item = item.clone();
if item.is_database() {

@ -31,32 +31,46 @@ impl ConnectionsComponent {
}
}
fn next_connection(&mut self) {
fn next_connection(&mut self, lines: usize) {
let i = match self.state.selected() {
Some(i) => {
if i >= self.connections.len() - 1 {
self.connections.len() - 1
if i + lines >= self.connections.len() {
Some(self.connections.len() - 1)
} else {
i + 1
Some(i + lines)
}
}
None => 0,
None => None,
};
self.state.select(Some(i));
self.state.select(i);
}
fn previous_connection(&mut self) {
fn previous_connection(&mut self, lines: usize) {
let i = match self.state.selected() {
Some(i) => {
if i == 0 {
0
if i <= lines {
Some(0)
} else {
i - 1
Some(i - lines)
}
}
None => 0,
None => None,
};
self.state.select(Some(i));
self.state.select(i);
}
fn scroll_to_top(&mut self) {
if self.connections.is_empty() {
return;
}
self.state.select(Some(0));
}
fn scroll_to_bottom(&mut self) {
if self.connections.is_empty() {
return;
}
self.state.select(Some(self.connections.len() - 1));
}
pub fn selected_connection(&self) -> Option<&Connection> {
@ -101,10 +115,22 @@ impl Component for ConnectionsComponent {
fn event(&mut self, key: Key) -> Result<EventState> {
if key == self.key_config.scroll_down {
self.next_connection();
self.next_connection(1);
return Ok(EventState::Consumed);
} else if key == self.key_config.scroll_up {
self.previous_connection();
self.previous_connection(1);
return Ok(EventState::Consumed);
} else if key == self.key_config.scroll_down_multiple_lines {
self.next_connection(10);
return Ok(EventState::NotConsumed);
} else if key == self.key_config.scroll_up_multiple_lines {
self.previous_connection(10);
return Ok(EventState::Consumed);
} else if key == self.key_config.scroll_to_top {
self.scroll_to_top();
return Ok(EventState::Consumed);
} else if key == self.key_config.scroll_to_bottom {
self.scroll_to_bottom();
return Ok(EventState::Consumed);
}
Ok(EventState::NotConsumed)

@ -123,7 +123,7 @@ impl TableComponent {
self.selected_row.select(i);
}
fn scroll_top(&mut self) {
fn scroll_to_top(&mut self) {
if self.rows.is_empty() {
return;
}
@ -131,7 +131,7 @@ impl TableComponent {
self.selected_row.select(Some(0));
}
fn scroll_bottom(&mut self) {
fn scroll_to_bottom(&mut self) {
if self.rows.is_empty() {
return;
}
@ -504,10 +504,10 @@ impl Component for TableComponent {
self.previous_row(10);
return Ok(EventState::Consumed);
} else if key == self.key_config.scroll_to_top {
self.scroll_top();
self.scroll_to_top();
return Ok(EventState::Consumed);
} else if key == self.key_config.scroll_to_bottom {
self.scroll_bottom();
self.scroll_to_bottom();
return Ok(EventState::Consumed);
} else if key == self.key_config.scroll_right {
self.next_column();

@ -10,6 +10,10 @@ pub fn common_nav(key: Key, key_config: &KeyConfig) -> Option<MoveSelection> {
Some(MoveSelection::Down)
} else if key == key_config.scroll_up {
Some(MoveSelection::Up)
} else if key == key_config.scroll_down_multiple_lines {
Some(MoveSelection::MultipleDown)
} else if key == key_config.scroll_up_multiple_lines {
Some(MoveSelection::MultipleUp)
} else if key == key_config.scroll_right {
Some(MoveSelection::Right)
} else if key == key_config.scroll_left {

Loading…
Cancel
Save