Merge
This commit is contained in:
commit
312595ba4f
2 changed files with 49 additions and 18 deletions
|
@ -19,6 +19,8 @@ var helpBinding string
|
|||
var bindingActions = map[string]func(*View) bool{
|
||||
"CursorUp": (*View).CursorUp,
|
||||
"CursorDown": (*View).CursorDown,
|
||||
"CursorPageUp": (*View).CursorPageUp,
|
||||
"CursorPageDown": (*View).CursorPageDown,
|
||||
"CursorLeft": (*View).CursorLeft,
|
||||
"CursorRight": (*View).CursorRight,
|
||||
"CursorStart": (*View).CursorStart,
|
||||
|
@ -884,6 +886,26 @@ func (v *View) PageDown() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// CursorPageUp places the cursor a page up
|
||||
func (v *View) CursorPageUp() bool {
|
||||
if v.Cursor.HasSelection() {
|
||||
v.Cursor.SetLoc(v.Cursor.CurSelection[0])
|
||||
v.Cursor.ResetSelection()
|
||||
}
|
||||
v.Cursor.UpN(v.height)
|
||||
return true
|
||||
}
|
||||
|
||||
// CursorPageDown places the cursor a page up
|
||||
func (v *View) CursorPageDown() bool {
|
||||
if v.Cursor.HasSelection() {
|
||||
v.Cursor.SetLoc(v.Cursor.CurSelection[1])
|
||||
v.Cursor.ResetSelection()
|
||||
}
|
||||
v.Cursor.DownN(v.height)
|
||||
return true
|
||||
}
|
||||
|
||||
// HalfPageUp scrolls the view up half a page
|
||||
func (v *View) HalfPageUp() bool {
|
||||
if v.Topline > v.height/2 {
|
||||
|
|
|
@ -276,30 +276,39 @@ func (c *Cursor) RuneUnder(x int) rune {
|
|||
return line[x]
|
||||
}
|
||||
|
||||
// UpN moves the cursor up N lines (if possible)
|
||||
func (c *Cursor) UpN(amount int) {
|
||||
proposedY := c.Y - amount
|
||||
if proposedY < 0 {
|
||||
proposedY = 0
|
||||
} else if proposedY >= c.buf.NumLines {
|
||||
proposedY = c.buf.NumLines - 1
|
||||
}
|
||||
if proposedY == c.Y {
|
||||
return
|
||||
}
|
||||
|
||||
c.Y = proposedY
|
||||
runes := []rune(c.buf.Lines[c.Y])
|
||||
c.X = c.GetCharPosInLine(c.Y, c.LastVisualX)
|
||||
if c.X > len(runes) {
|
||||
c.X = len(runes)
|
||||
}
|
||||
}
|
||||
|
||||
// DownN moves the cursor down N lines (if possible)
|
||||
func (c *Cursor) DownN(amount int) {
|
||||
c.UpN(-amount)
|
||||
}
|
||||
|
||||
// Up moves the cursor up one line (if possible)
|
||||
func (c *Cursor) Up() {
|
||||
if c.Y > 0 {
|
||||
c.Y--
|
||||
|
||||
runes := []rune(c.buf.Lines[c.Y])
|
||||
c.X = c.GetCharPosInLine(c.Y, c.LastVisualX)
|
||||
if c.X > len(runes) {
|
||||
c.X = len(runes)
|
||||
}
|
||||
}
|
||||
c.UpN(1)
|
||||
}
|
||||
|
||||
// Down moves the cursor down one line (if possible)
|
||||
func (c *Cursor) Down() {
|
||||
if c.Y < c.buf.NumLines-1 {
|
||||
c.Y++
|
||||
|
||||
runes := []rune(c.buf.Lines[c.Y])
|
||||
c.X = c.GetCharPosInLine(c.Y, c.LastVisualX)
|
||||
if c.X > len(runes) {
|
||||
c.X = len(runes)
|
||||
}
|
||||
}
|
||||
c.DownN(1)
|
||||
}
|
||||
|
||||
// Left moves the cursor left one cell (if possible) or to the last line if it is at the beginning
|
||||
|
|
Loading…
Reference in a new issue