From 921f88b95d3c2267e6c0b3de0822812e36850a1a Mon Sep 17 00:00:00 2001 From: Yannick A Date: Wed, 9 Aug 2017 17:58:37 +0200 Subject: [PATCH] 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 --- cmd/micro/cursor.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/micro/cursor.go b/cmd/micro/cursor.go index a0d3477f..2b5889a0 100644 --- a/cmd/micro/cursor.go +++ b/cmd/micro/cursor.go @@ -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)