]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/actions.go
LoadAll should reload plugins too
[micro.git] / cmd / micro / actions.go
index 41c89e7103ed6d482462a3e0ca89e0e68d66121b..83eec1440d82768b809879d8db588f46a847c3e9 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)
@@ -947,7 +951,7 @@ func (v *View) SaveAll(usePlugin bool) bool {
                }
 
                for _, t := range tabs {
-                       for _, v := range t.views {
+                       for _, v := range t.Views {
                                v.Save(false)
                        }
                }
@@ -1016,7 +1020,7 @@ func (v *View) saveToFile(filename string) {
 // SaveAs saves the buffer to disk with the given name
 func (v *View) SaveAs(usePlugin bool) bool {
        if v.mainCursor() {
-               if usePlugin && !PreActionCall("Find", v) {
+               if usePlugin && !PreActionCall("SaveAs", v) {
                        return false
                }
 
@@ -1033,7 +1037,7 @@ func (v *View) SaveAs(usePlugin bool) bool {
                }
 
                if usePlugin {
-                       PostActionCall("Find", v)
+                       PostActionCall("SaveAs", v)
                }
        }
        return false
@@ -1215,9 +1219,9 @@ func (v *View) Cut(usePlugin bool) bool {
                        return PostActionCall("Cut", v)
                }
                return true
+       } else {
+               return v.CutLine(usePlugin)
        }
-
-       return false
 }
 
 // DuplicateLine duplicates the current line or selection
@@ -1511,6 +1515,42 @@ func (v *View) PageDown(usePlugin bool) bool {
        return false
 }
 
+// SelectPageUp selects up one page
+func (v *View) SelectPageUp(usePlugin bool) bool {
+       if usePlugin && !PreActionCall("SelectPageUp", v) {
+               return false
+       }
+
+       if !v.Cursor.HasSelection() {
+               v.Cursor.OrigSelection[0] = v.Cursor.Loc
+       }
+       v.Cursor.UpN(v.Height)
+       v.Cursor.SelectTo(v.Cursor.Loc)
+
+       if usePlugin {
+               return PostActionCall("SelectPageUp", v)
+       }
+       return true
+}
+
+// SelectPageDown selects down one page
+func (v *View) SelectPageDown(usePlugin bool) bool {
+       if usePlugin && !PreActionCall("SelectPageDown", v) {
+               return false
+       }
+
+       if !v.Cursor.HasSelection() {
+               v.Cursor.OrigSelection[0] = v.Cursor.Loc
+       }
+       v.Cursor.DownN(v.Height)
+       v.Cursor.SelectTo(v.Cursor.Loc)
+
+       if usePlugin {
+               return PostActionCall("SelectPageDown", v)
+       }
+       return true
+}
+
 // CursorPageUp places the cursor a page up
 func (v *View) CursorPageUp(usePlugin bool) bool {
        if usePlugin && !PreActionCall("CursorPageUp", v) {
@@ -1804,12 +1844,12 @@ func (v *View) Quit(usePlugin bool) bool {
                // Make sure not to quit if there are unsaved changes
                if v.CanClose() {
                        v.CloseBuffer()
-                       if len(tabs[curTab].views) > 1 {
+                       if len(tabs[curTab].Views) > 1 {
                                v.splitNode.Delete()
                                tabs[v.TabNum].Cleanup()
                                tabs[v.TabNum].Resize()
                        } else if len(tabs) > 1 {
-                               if len(tabs[v.TabNum].views) == 1 {
+                               if len(tabs[v.TabNum].Views) == 1 {
                                        tabs = tabs[:v.TabNum+copy(tabs[v.TabNum:], tabs[v.TabNum+1:])]
                                        for i, t := range tabs {
                                                t.SetNum(i)
@@ -1848,7 +1888,7 @@ func (v *View) QuitAll(usePlugin bool) bool {
 
                closeAll := true
                for _, tab := range tabs {
-                       for _, v := range tab.views {
+                       for _, v := range tab.Views {
                                if !v.CanClose() {
                                        closeAll = false
                                }
@@ -1861,7 +1901,7 @@ func (v *View) QuitAll(usePlugin bool) bool {
 
                        if shouldQuit {
                                for _, tab := range tabs {
-                                       for _, v := range tab.views {
+                                       for _, v := range tab.Views {
                                                v.CloseBuffer()
                                        }
                                }
@@ -1893,7 +1933,7 @@ func (v *View) AddTab(usePlugin bool) bool {
                curTab = len(tabs) - 1
                if len(tabs) == 2 {
                        for _, t := range tabs {
-                               for _, v := range t.views {
+                               for _, v := range t.Views {
                                        v.ToggleTabbar()
                                }
                        }
@@ -1986,8 +2026,8 @@ func (v *View) Unsplit(usePlugin bool) bool {
                }
 
                curView := tabs[curTab].CurView
-               for i := len(tabs[curTab].views) - 1; i >= 0; i-- {
-                       view := tabs[curTab].views[i]
+               for i := len(tabs[curTab].Views) - 1; i >= 0; i-- {
+                       view := tabs[curTab].Views[i]
                        if view != nil && view.Num != curView {
                                view.Quit(true)
                                // messenger.Message("Quit ", view.Buf.Path)
@@ -2009,7 +2049,7 @@ func (v *View) NextSplit(usePlugin bool) bool {
                }
 
                tab := tabs[curTab]
-               if tab.CurView < len(tab.views)-1 {
+               if tab.CurView < len(tab.Views)-1 {
                        tab.CurView++
                } else {
                        tab.CurView = 0
@@ -2033,7 +2073,7 @@ func (v *View) PreviousSplit(usePlugin bool) bool {
                if tab.CurView > 0 {
                        tab.CurView--
                } else {
-                       tab.CurView = len(tab.views) - 1
+                       tab.CurView = len(tab.Views) - 1
                }
 
                if usePlugin {
@@ -2144,6 +2184,54 @@ func (v *View) SpawnMultiCursor(usePlugin bool) bool {
        return false
 }
 
+// SpawnMultiCursorSelect adds a cursor at the beginning of each line of a selection
+func (v *View) SpawnMultiCursorSelect(usePlugin bool) bool {
+       if v.Cursor == &v.Buf.Cursor {
+               if usePlugin && !PreActionCall("SpawnMultiCursorSelect", v) {
+                       return false
+               }
+
+               // Avoid cases where multiple cursors already exist, that would create problems
+               if len(v.Buf.cursors) > 1 {
+                       return false
+               }
+
+               var startLine int
+               var endLine int
+
+               a, b := v.Cursor.CurSelection[0].Y, v.Cursor.CurSelection[1].Y
+               if a > b {
+                       startLine, endLine = b, a
+               } else {
+                       startLine, endLine = a, b
+               }
+
+               if v.Cursor.HasSelection() {
+                       v.Cursor.ResetSelection()
+                       v.Cursor.GotoLoc(Loc{0, startLine})
+
+                       for i := startLine; i <= endLine; i++ {
+                               c := &Cursor{
+                                       buf: v.Buf,
+                               }
+                               c.GotoLoc(Loc{0, i})
+                               v.Buf.cursors = append(v.Buf.cursors, c)
+                       }
+                       v.Buf.MergeCursors()
+                       v.Buf.UpdateCursors()
+               } else {
+                       return false
+               }
+
+               if usePlugin {
+                       PostActionCall("SpawnMultiCursorSelect", v)
+               }
+
+               messenger.Message("Added cursors from selection")
+       }
+       return false
+}
+
 // MouseMultiCursor is a mouse action which puts a new cursor at the mouse position
 func (v *View) MouseMultiCursor(usePlugin bool, e *tcell.EventMouse) bool {
        if v.Cursor == &v.Buf.Cursor {