]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/cursor.go
Code optimisation (#1117)
[micro.git] / cmd / micro / cursor.go
index 5eb00a72b3836f12276a7d428ee3026587334df7..452268ba12b1f3802623be7fca8c5d33097e81e0 100644 (file)
@@ -35,6 +35,13 @@ func (c *Cursor) Goto(b Cursor) {
        c.OrigSelection, c.CurSelection = b.OrigSelection, b.CurSelection
 }
 
+// GotoLoc puts the cursor at the given cursor's location and gives
+// the current cursor its selection too
+func (c *Cursor) GotoLoc(l Loc) {
+       c.X, c.Y = l.X, l.Y
+       c.LastVisualX = c.GetVisualX()
+}
+
 // CopySelection copies the user's selection to either "primary"
 // or "clipboard"
 func (c *Cursor) CopySelection(target string) {
@@ -326,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)