diff options
| author | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2019-01-01 14:32:26 +0300 |
|---|---|---|
| committer | Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com> | 2019-01-01 14:32:26 +0300 |
| commit | f5bc05b6af765a72bbaa6cc72854681718221c5e (patch) | |
| tree | 955430848cdffce6cf4cbf91fc0577825f9fc4e2 | |
| parent | switch esc keybinding to q, add home/end buttons to repository nav and fic a ... (diff) | |
| download | gitbatch-f5bc05b6af765a72bbaa6cc72854681718221c5e.tar.gz | |
add page up page down controls on the repo view
| -rw-r--r-- | pkg/gui/keybindings.go | 16 | ||||
| -rw-r--r-- | pkg/gui/mainview.go | 45 |
2 files changed, 61 insertions, 0 deletions
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index 330c67a..7aaee56 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -318,6 +318,14 @@ func (gui *Gui) generateKeybindings() error { Vital: false, }, { View: mainViewFeature.Name, + Key: gocui.KeyPgup, + Modifier: gocui.ModNone, + Handler: gui.pageUp, + Display: "page up", + Description: "Page up", + Vital: false, + }, { + View: mainViewFeature.Name, Key: gocui.KeyHome, Modifier: gocui.ModNone, Handler: gui.cursorTop, @@ -326,6 +334,14 @@ func (gui *Gui) generateKeybindings() error { Vital: false, }, { View: mainViewFeature.Name, + Key: gocui.KeyPgdn, + Modifier: gocui.ModNone, + Handler: gui.pageDown, + Display: "page down", + Description: "Page Down", + Vital: false, + }, { + View: mainViewFeature.Name, Key: gocui.KeyEnd, Modifier: gocui.ModNone, Handler: gui.cursorEnd, diff --git a/pkg/gui/mainview.go b/pkg/gui/mainview.go index 109d066..869b334 100644 --- a/pkg/gui/mainview.go +++ b/pkg/gui/mainview.go @@ -132,6 +132,51 @@ func (gui *Gui) cursorEnd(g *gocui.Gui, v *gocui.View) error { return gui.renderMain() } +// moves cursor down for a page size +func (gui *Gui) pageDown(g *gocui.Gui, v *gocui.View) error { + if v != nil { + ox, oy := v.Origin() + cx, _ := v.Cursor() + _, vy := v.Size() + lr := len(gui.State.Repositories) + if oy+vy >= lr-vy { + if err := v.SetOrigin(ox, lr-vy); err != nil { + return err + } + } else if err := v.SetOrigin(ox, oy+vy); err != nil { + return err + } + if err := v.SetCursor(cx, 0); err != nil { + return err + } + } + return gui.renderMain() +} + +// moves cursor up for a page size +func (gui *Gui) pageUp(g *gocui.Gui, v *gocui.View) error { + if v != nil { + ox, oy := v.Origin() + cx, cy := v.Cursor() + _, vy := v.Size() + if oy == 0 || oy+cy < vy { + if err := v.SetOrigin(ox, 0); err != nil { + return err + } + } else if oy <= vy { + if err := v.SetOrigin(ox, oy+cy-vy); err != nil { + return err + } + } else if err := v.SetOrigin(ox, oy-vy); err != nil { + return err + } + if err := v.SetCursor(cx, 0); err != nil { + return err + } + } + return gui.renderMain() +} + // returns the entity at cursors position by taking its position in the gui's // slice of repositories. Since it is not a %100 percent safe methodology it may // rrequire a better implementation or the slice's order must be synchronized |
