]> git.lizzy.rs Git - micro.git/commitdiff
home toggles between start of line and start of text
authorJT Olio <hello@jtolio.com>
Thu, 5 Apr 2018 21:25:30 +0000 (15:25 -0600)
committerJT Olio <hello@jtolio.com>
Thu, 5 Apr 2018 21:25:34 +0000 (15:25 -0600)
by default home sends the cursor to the beginning of the line.
if the cursor is at the beginning of the line already though, home
will send the cursor to the first non-whitespace rune. tapping home
will toggle between these two line starts.

cmd/micro/actions.go
cmd/micro/cursor.go

index 21179e3bb14de2f25490f40f9d5fa6bb5efeb53e..4d52e79bfc5e1386a0e0513c23c3d372f62e0608 100644 (file)
@@ -435,7 +435,11 @@ func (v *View) StartOfLine(usePlugin bool) bool {
 
        v.deselect(0)
 
-       v.Cursor.Start()
+       if v.Cursor.X != 0 {
+               v.Cursor.Start()
+       } else {
+               v.Cursor.StartOfText()
+       }
 
        if usePlugin {
                return PostActionCall("StartOfLine", v)
index 15b01010eec9879ba45dbaf8fda1b5c8c1e41c10..452268ba12b1f3802623be7fca8c5d33097e81e0 100644 (file)
@@ -333,6 +333,18 @@ func (c *Cursor) Start() {
        c.LastVisualX = c.GetVisualX()
 }
 
+// StartOfText moves the cursor to the first non-whitespace rune of 
+// the line it is on
+func (c *Cursor) StartOfText() {
+       c.Start()
+       for IsWhitespace(c.RuneUnder(c.X)) {
+               if c.X == Count(c.buf.Line(c.Y)) {
+                       break
+               }
+               c.Right()
+       }
+}
+
 // GetCharPosInLine gets the char position of a visual x y
 // coordinate (this is necessary because tabs are 1 char but
 // 4 visual spaces)