Skip to content

Commit

Permalink
Add notations to jump to the first and last pages
Browse files Browse the repository at this point in the history
  • Loading branch information
baskerville committed Jun 1, 2020
1 parent ba12084 commit 3dda6a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 3 additions & 1 deletion doc/NAVIGATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ For the page names to be resolved, you'll need to name the first page of each ca

`-` or `+` can be prepended to a page number to jump to a relative page.

You can jump to a random page by specifying `_` as the page number.
Instead of the page number, you can specify one of the following characters:
- `(` and `)` to jump to the first and last page.
- `_` to jump to a random page.
6 changes: 5 additions & 1 deletion src/view/home/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,7 +1321,11 @@ impl View for Home {
true
},
Event::Submit(ViewId::GoToPageInput, ref text) => {
if text == "_" {
if text == "(" {
self.go_to_page(0, hub, context);
} else if text == ")" {
self.go_to_page(self.pages_count.saturating_sub(1), hub, context);
} else if text == "_" {
let index = (context.rng.next_u64() % self.pages_count as u64) as usize;
self.go_to_page(index, hub, context);
} else if let Ok(index) = text.parse::<usize>() {
Expand Down
4 changes: 4 additions & 0 deletions src/view/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2934,6 +2934,10 @@ impl View for Reader {
if text == "_" {
let location = (context.rng.next_u64() % self.pages_count as u64) as usize;
self.go_to_page(location, true, hub, context);
} else if text == "(" {
self.go_to_page(0, true, hub, context);
} else if text == ")" {
self.go_to_page(self.pages_count.saturating_sub(1), true, hub, context);
} else if let Ok(number) = caps[2].parse::<f64>() {
let location = if !self.synthetic {
let mut index = number.max(0.0) as usize;
Expand Down

0 comments on commit 3dda6a0

Please sign in to comment.