From f8a171379a1922c7fb211a3524e94b26b7497060 Mon Sep 17 00:00:00 2001 From: JT Olio Date: Thu, 5 Apr 2018 15:25:30 -0600 Subject: [PATCH] home toggles between start of line and start of text 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 | 6 +++++- cmd/micro/cursor.go | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index 21179e3b..4d52e79b 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -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) diff --git a/cmd/micro/cursor.go b/cmd/micro/cursor.go index 15b01010..452268ba 100644 --- a/cmd/micro/cursor.go +++ b/cmd/micro/cursor.go @@ -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)