diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index dfba85c3..48d2315c 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -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) { diff --git a/cmd/micro/bindings.go b/cmd/micro/bindings.go index fadad29c..0f0ea6ba 100644 --- a/cmd/micro/bindings.go +++ b/cmd/micro/bindings.go @@ -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",