mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-19 23:37:13 +09:00
Cursor move at the first char when Up on the first line (and at the last char when Down on last the line) (#773)
* Cursor move at the beginning of the line when Up on the first line (and at the last character when Down on last the line) * Fix an issue when Up to a shorter line than current line
This commit is contained in:
committed by
Zachary Yedidia
parent
7fe8d73473
commit
921f88b95d
@@ -249,20 +249,20 @@ func (c *Cursor) RuneUnder(x int) rune {
|
||||
func (c *Cursor) UpN(amount int) {
|
||||
proposedY := c.Y - amount
|
||||
if proposedY < 0 {
|
||||
proposedY = 0
|
||||
c.X = 0 // first line: X moved before the first character
|
||||
return
|
||||
} else if proposedY >= c.buf.NumLines {
|
||||
proposedY = c.buf.NumLines - 1
|
||||
}
|
||||
if proposedY == c.Y {
|
||||
return
|
||||
|
||||
runes := []rune(c.buf.Line(c.Y))
|
||||
c.X = c.GetCharPosInLine(proposedY, c.LastVisualX)
|
||||
|
||||
if c.X > len(runes) || proposedY == c.Y {
|
||||
c.X = len(runes)
|
||||
}
|
||||
|
||||
c.Y = proposedY
|
||||
runes := []rune(c.buf.Line(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)
|
||||
|
||||
Reference in New Issue
Block a user