always reset offset

This commit is contained in:
Takayuki Maeda 2021-09-12 00:58:00 +09:00
parent 0b0f56ed43
commit 4b27857bc5

View File

@ -59,8 +59,8 @@ impl TableComponent {
database: Database, database: Database,
table: DTable, table: DTable,
) { ) {
if !rows.is_empty() {
self.selected_row.select(None); self.selected_row.select(None);
if !rows.is_empty() {
self.selected_row.select(Some(0)) self.selected_row.select(Some(0))
} }
self.headers = headers; self.headers = headers;
@ -97,7 +97,7 @@ impl TableComponent {
let i = match self.selected_row.selected() { let i = match self.selected_row.selected() {
Some(i) => { Some(i) => {
if i + lines >= self.rows.len() { if i + lines >= self.rows.len() {
Some(self.rows.len() - 1) Some(self.rows.len().saturating_sub(1))
} else { } else {
Some(i + lines) Some(i + lines)
} }
@ -114,7 +114,7 @@ impl TableComponent {
if i <= lines { if i <= lines {
Some(0) Some(0)
} else { } else {
Some(i - lines) Some(i.saturating_sub(lines))
} }
} }
None => None, None => None,
@ -136,7 +136,8 @@ impl TableComponent {
return; return;
} }
self.reset_selection(); self.reset_selection();
self.selected_row.select(Some(self.rows.len() - 1)); self.selected_row
.select(Some(self.rows.len().saturating_sub(1)));
} }
fn next_column(&mut self) { fn next_column(&mut self) {