2
0
mirror of https://github.com/xvxx/phetch synced 2024-11-10 13:10:54 +00:00

fix (and saneify) pg dn

This commit is contained in:
dvkt 2019-12-30 21:55:02 -08:00
parent 79c2c5e7a3
commit f9a7c76552
2 changed files with 33 additions and 30 deletions

View File

@ -63,7 +63,6 @@ just unzip/untar the `phetch` program into your $PATH and get going!
- [ ] gopher://1436.ninja/1/twit.cgi ("iWritten and performed by Nathaniel" weirdness) - [ ] gopher://1436.ninja/1/twit.cgi ("iWritten and performed by Nathaniel" weirdness)
- [ ] screen flicker in win10 WSL - [ ] screen flicker in win10 WSL
- [ ] NUM entry and Find entry shouldn't use same buffer - [ ] NUM entry and Find entry shouldn't use same buffer
- [ ] page down / spacebar when last link selected & there is more content
## future features ## future features

View File

@ -199,11 +199,11 @@ impl Menu {
Action::None Action::None
} }
/// Scroll down by SCROLL_LINES, if possible.
fn action_page_down(&mut self) -> Action { fn action_page_down(&mut self) -> Action {
let lines = self.lines.len(); // If there are fewer menu items than screen lines, just
// select the final link and do nothing else.
// fewer lines than visible rows, just select last link if self.lines.len() < self.rows() {
if lines < self.rows() {
if !self.links.is_empty() { if !self.links.is_empty() {
self.link = self.links.len() - 1; self.link = self.links.len() - 1;
return Action::Redraw; return Action::Redraw;
@ -211,34 +211,38 @@ impl Menu {
return Action::None; return Action::None;
} }
let padding = self.padding_bottom(); // If we've already scrolled too far, select the final link
if self.scroll < padding { // and do nothing.
if self.scroll >= self.final_scroll() {
self.scroll = self.final_scroll();
self.link = self.links.len() - 1;
return Action::Redraw;
}
// Scroll...
self.scroll += SCROLL_LINES; self.scroll += SCROLL_LINES;
if self.scroll > padding {
self.scroll = padding; // ...but don't go past the final line.
if !self.links.is_empty() { if self.scroll > self.final_scroll() {
self.link = self.links.len() - 1; self.scroll = self.final_scroll();
return Action::Redraw; }
// If the selected link isn't visible...
if Some(LinkPos::Above) == self.link_visibility(self.link) {
// ...find the next one that is.
if let Some(&next_link_pos) = self
.links
.iter()
.skip(self.link + 1)
.find(|&&i| i >= self.scroll)
{
if let Some(next_link_line) = self.lines.get(next_link_pos) {
self.link = next_link_line.link;
} }
} }
} else if !self.links.is_empty() {
self.link = self.links.len() - 1;
return Action::Redraw;
} }
if let Some(dir) = self.link_visibility(self.link) {
match dir { Action::Redraw
LinkPos::Above => {
let scroll = self.scroll;
if let Some(&pos) = self.links.iter().skip(self.link).find(|&&i| i >= scroll) {
self.link = self.lines.get(pos).unwrap().link;
return Action::Redraw;
}
}
LinkPos::Below => {}
LinkPos::Visible => {}
}
}
Action::None
} }
fn action_page_up(&mut self) -> Action { fn action_page_up(&mut self) -> Action {
@ -338,8 +342,8 @@ impl Menu {
} }
} }
// how many rows to pad with blank lines at the end of the page /// Final `self.scroll` value.
fn padding_bottom(&self) -> usize { fn final_scroll(&self) -> usize {
let padding = (self.rows() as f64 * 0.9) as usize; let padding = (self.rows() as f64 * 0.9) as usize;
if self.lines.len() > padding { if self.lines.len() > padding {
self.lines.len() - padding self.lines.len() - padding
@ -379,7 +383,7 @@ impl Menu {
// no links or final link selected already // no links or final link selected already
if self.links.is_empty() || new_link >= self.links.len() { if self.links.is_empty() || new_link >= self.links.len() {
// if there are more rows, scroll down // if there are more rows, scroll down
if self.lines.len() >= self.rows() && self.scroll < self.padding_bottom() { if self.lines.len() >= self.rows() && self.scroll < self.final_scroll() {
self.scroll += 1; self.scroll += 1;
return Action::Redraw; return Action::Redraw;
} else { } else {