Merge pull request #1084 from jtolds/master

home toggles between start of line and start of text
This commit is contained in:
Zachary Yedidia 2018-04-07 20:03:57 -04:00 committed by GitHub
commit 6ef273accd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View 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)

View 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)