From a5ddd9e5215ede7ef66d7ed8d09c592df4e45c0e Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sat, 19 Mar 2016 09:12:03 -0400 Subject: [PATCH] Add pagedown, pageup, halfpagedown, halfpageup --- todolist.md | 32 ++++++++++++++++++++++++++++++++ todolist.txt | 27 --------------------------- view.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 27 deletions(-) create mode 100644 todolist.md delete mode 100644 todolist.txt diff --git a/todolist.md b/todolist.md new file mode 100644 index 00000000..bee544f7 --- /dev/null +++ b/todolist.md @@ -0,0 +1,32 @@ +- [ ] Line numbers + +- [ ] Optimization + +- [ ] Better selection + - [ ] Double click selects current word + - [ ] Triple click enables line selection + +- [ ] More keybindings + - [x] Use pageup and pagedown keys + - [ ] Much more (copy sublime text or standard system applications) + +- [ ] Syntax highlighting + - [ ] Use nano-like syntax files (https://github.com/scopatz/nanorc) + - [ ] Allow additional colors and colorschemes + - [ ] Support for 256 color and true color + +- [ ] Help screen + - [ ] Help screen which lists keybindings and commands + - [ ] Opened with Ctrl-h + +- [ ] Undo/redo + - [ ] Undo/redo stack + - [ ] Functionality similar to nano + +- [ ] Command execution + - [ ] Allow executing simple commands at the bottom of the editor + (like vim or emacs) + +- [ ] Options + - [ ] Add options such as tab size, use tabs or use spaces, etc... + diff --git a/todolist.txt b/todolist.txt deleted file mode 100644 index 8859a098..00000000 --- a/todolist.txt +++ /dev/null @@ -1,27 +0,0 @@ -- Better selection - - Double click selects current word - - Triple click enables line selection - -- More keybindings - - Use pageup and pagedown keys - -- Syntax highlighting - - Use nano-like syntax files (https://github.com/scopatz/nanorc) - - Allow additional colors and colorschemes - - Support for 256 color and true color - -- Help screen - - Help screen which lists keybindings and commands - - Opened with Ctrl-h - -- Undo/redo - - Undo/redo stack - - Functionality similar to nano - -- Command execution - - Allow executing simple commands at the bottom of the editor - (like vim or emacs) - -- Options - - Add options such as tab size, use tabs or use spaces, etc... - diff --git a/view.go b/view.go index 21c1d215..364d6edc 100644 --- a/view.go +++ b/view.go @@ -71,6 +71,42 @@ func (v *View) ScrollDown(n int) { } } +// PageUp scrolls the view up a page +func (v *View) PageUp() { + if v.topline > v.height { + v.ScrollUp(v.height) + } else { + v.topline = 0 + } +} + +// PageDown scrolls the view down a page +func (v *View) PageDown() { + if len(v.buf.lines)-(v.topline+v.height) > v.height { + v.ScrollDown(v.height) + } else { + v.topline = len(v.buf.lines) - v.height + } +} + +// HalfPageUp scrolls the view up half a page +func (v *View) HalfPageUp() { + if v.topline > v.height/2 { + v.ScrollUp(v.height / 2) + } else { + v.topline = 0 + } +} + +// HalfPageDown scrolls the view down half a page +func (v *View) HalfPageDown() { + if len(v.buf.lines)-(v.topline+v.height) > v.height/2 { + v.ScrollDown(v.height / 2) + } else { + v.topline = len(v.buf.lines) - v.height + } +} + // HandleEvent handles an event passed by the main loop // It returns an int describing how the screen needs to be redrawn // 0: Screen does not need to be redrawn @@ -122,6 +158,18 @@ func (v *View) HandleEvent(event tcell.Event) int { } // Need to redraw the status line ret = 1 + case tcell.KeyPgUp: + v.PageUp() + return 2 + case tcell.KeyPgDn: + v.PageDown() + return 2 + case tcell.KeyCtrlU: + v.HalfPageUp() + return 2 + case tcell.KeyCtrlD: + v.HalfPageDown() + return 2 case tcell.KeyRune: if v.cursor.HasSelection() { v.cursor.DeleteSelected()