Add pagedown, pageup, halfpagedown, halfpageup

This commit is contained in:
Zachary Yedidia
2016-03-19 09:12:03 -04:00
parent a98030403a
commit a5ddd9e521
3 changed files with 80 additions and 27 deletions

32
todolist.md Normal file
View File

@@ -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...

View File

@@ -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...

48
view.go
View File

@@ -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()