Add StartOfTextToggle and SelectToStartOfTextToggle actions. (#1612)

These actions reintroduce the behavior of micro where the Home key
toggles between the start of text (first) and the start of the line.
The same applies for the variant with selection. This commit also
sets these bindings as the defaults.
This commit is contained in:
Ján Jančár
2020-04-10 23:21:02 +02:00
committed by GitHub
parent d92deacf99
commit f0da73bae2
6 changed files with 220 additions and 166 deletions

View File

@@ -109,6 +109,19 @@ func (c *Cursor) StartOfText() {
}
}
// IsStartOfText returns whether the cursor is at the first
// non-whitespace rune of the line it is on
func (c *Cursor) IsStartOfText() bool {
x := 0
for util.IsWhitespace(c.RuneUnder(x)) {
if x == utf8.RuneCount(c.buf.LineBytes(c.Y)) {
break
}
x++
}
return c.X == x
}
// End moves the cursor to the end of the line it is on
func (c *Cursor) End() {
c.X = utf8.RuneCount(c.buf.LineBytes(c.Y))