From 760d709c34edb8cee369e93731e9d3a4c4b448d8 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Mon, 22 Aug 2016 10:04:23 -0700 Subject: [PATCH] Remove auto indented spaces if the line is empty --- cmd/micro/actions.go | 5 +++++ cmd/micro/util.go | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/cmd/micro/actions.go b/cmd/micro/actions.go index 02b72659..b1c18d60 100644 --- a/cmd/micro/actions.go +++ b/cmd/micro/actions.go @@ -428,6 +428,11 @@ func (v *View) InsertNewline(usePlugin bool) bool { for i := 0; i < len(ws); i++ { v.Cursor.Right() } + + if IsSpacesOrTabs(v.Buf.Line(v.Cursor.Y - 1)) { + line := v.Buf.Line(v.Cursor.Y - 1) + v.Buf.Remove(Loc{0, v.Cursor.Y - 1}, Loc{Count(line), v.Cursor.Y - 1}) + } } v.Cursor.LastVisualX = v.Cursor.GetVisualX() diff --git a/cmd/micro/util.go b/cmd/micro/util.go index f5d77abc..c477c41e 100644 --- a/cmd/micro/util.go +++ b/cmd/micro/util.go @@ -112,6 +112,17 @@ func IsSpaces(str string) bool { return true } +// IsSpacesOrTabs checks if a given string contains only spaces and tabs +func IsSpacesOrTabs(str string) bool { + for _, c := range str { + if c != ' ' && c != '\t' { + return false + } + } + + return true +} + // ParseBool is almost exactly like strconv.ParseBool, except it also accepts 'on' and 'off' // as 'true' and 'false' respectively func ParseBool(str string) (bool, error) {