diff --git a/CHANGELOG.md b/CHANGELOG.md index c897040..227d7d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Alt-Left and Alt-Right for history navigation (#23) - You can type `..` in the bottom bar to go up a directory in the URL (#21) - Error popup for when input string would result in a too long out-of-spec URL (#25) +- Paging, using d and u, as well as Page Up and Page Down (#19) ### Changed - Bottom bar now says `URL/Num./Search: ` when space is pressed diff --git a/display/display.go b/display/display.go index 578a8a3..d10c23f 100644 --- a/display/display.go +++ b/display/display.go @@ -20,7 +20,9 @@ var tabMap = make(map[int]*structs.Page) // Map of tab number to page // Holds the actual tab primitives var tabViews = make(map[int]*cview.TextView) +// Terminal dimensions var termW int +var termH int // The user input and URL display bar at the bottom var bottomBar = cview.NewInputField(). @@ -69,6 +71,7 @@ var App = cview.NewApplication(). SetAfterResizeFunc(func(width int, height int) { // Store for calculations termW = width + termH = height // Shift new tabs created before app startup, when termW == 0 // XXX: This is hacky but works. The biggest issue is that there will sometimes be a tiny flash @@ -247,6 +250,12 @@ func Init() { case tcell.KeyCtrlD: go addBookmark() return nil + case tcell.KeyPgUp: + pageUp() + return nil + case tcell.KeyPgDn: + pageDown() + return nil case tcell.KeyRune: // Regular key was sent switch string(event.Rune()) { @@ -271,6 +280,13 @@ func Init() { case "?": Help() return nil + case "u": + pageUp() + return nil + case "d": + pageDown() + return nil + // Shift+NUMBER keys, for switching to a specific tab case "!": SwitchTab(0) diff --git a/display/private.go b/display/private.go index 2cde509..0beffc8 100644 --- a/display/private.go +++ b/display/private.go @@ -17,6 +17,18 @@ import ( // This file contains the functions that aren't part of the public API. +// pageUp scrolls up 75% of the height of the terminal, like Bombadillo. +func pageUp() { + row, col := tabViews[curTab].GetScrollOffset() + tabViews[curTab].ScrollTo(row-(termH/4)*3, col) +} + +// pageDown scrolls down 75% of the height of the terminal, like Bombadillo. +func pageDown() { + row, col := tabViews[curTab].GetScrollOffset() + tabViews[curTab].ScrollTo(row+(termH/4)*3, col) +} + func leftMargin() int { return int(float64(termW) * viper.GetFloat64("a-general.left_margin")) }