]> git.lizzy.rs Git - micro.git/commitdiff
Added OutdentLine action
authorJon Craton <jncraton@gmail.com>
Sat, 15 Oct 2016 16:47:15 +0000 (12:47 -0400)
committerJon Craton <jncraton@gmail.com>
Sat, 15 Oct 2016 16:47:15 +0000 (12:47 -0400)
cmd/micro/actions.go
cmd/micro/bindings.go

index dfba85c39d5dabb12fdcb30c3cc6123cdf5e1a9e..48d2315ca0702f2502409c1786be567f6c7b58a9 100644 (file)
@@ -610,6 +610,31 @@ func (v *View) IndentSelection(usePlugin bool) bool {
        return false
 }
 
+// OutdentLine moves the current line back one indentation
+func (v *View) OutdentLine(usePlugin bool) bool {
+       if usePlugin && !PreActionCall("OutdentLine", v) {
+               return false
+       }
+
+       if v.Cursor.HasSelection() {
+               return false
+       }
+       
+       for x := 0; x < len(v.Buf.IndentString()); x++ {
+               if len(GetLeadingWhitespace(v.Buf.Line(v.Cursor.Y))) == 0 {
+                       break
+               }
+               v.Buf.Remove(Loc{0, v.Cursor.Y}, Loc{1, v.Cursor.Y})
+               v.Cursor.X -= 1
+       }
+       v.Cursor.Relocate()
+
+       if usePlugin {
+               return PostActionCall("OutdentLine", v)
+       }
+       return true
+}
+
 // OutdentSelection takes the current selection and moves it back one indent level
 func (v *View) OutdentSelection(usePlugin bool) bool {
        if usePlugin && !PreActionCall("OutdentSelection", v) {
index fadad29c9ee02c60ff23b8df98888ea7672462b2..0f0ea6ba1f7b471f8638222e7d4e729742495b2a 100644 (file)
@@ -56,6 +56,7 @@ var bindingActions = map[string]func(*View, bool) bool{
        "MoveLinesDown":       (*View).MoveLinesDown,
        "IndentSelection":     (*View).IndentSelection,
        "OutdentSelection":    (*View).OutdentSelection,
+       "OutdentLine":         (*View).OutdentLine,
        "Paste":               (*View).Paste,
        "PastePrimary":        (*View).PastePrimary,
        "SelectAll":           (*View).SelectAll,
@@ -386,7 +387,7 @@ func DefaultBindings() map[string]string {
                "Alt-CtrlH":      "DeleteWordLeft",
                "Alt-Backspace":  "DeleteWordLeft",
                "Tab":            "IndentSelection,InsertTab",
-               "Backtab":        "OutdentSelection",
+               "Backtab":        "OutdentSelection,OutdentLine",
                "CtrlO":          "OpenFile",
                "CtrlS":          "Save",
                "CtrlF":          "Find",