Remove auto indented spaces if the line is empty

This commit is contained in:
Zachary Yedidia
2016-08-22 10:04:23 -07:00
parent c340e6d48d
commit 760d709c34
2 changed files with 16 additions and 0 deletions

View File

@@ -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()

View File

@@ -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) {