mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-09 08:30:23 +09:00
Add auto indent
This commit is contained in:
@@ -75,3 +75,16 @@ func Contains(list []string, a string) bool {
|
||||
func Insert(str string, pos int, value string) string {
|
||||
return string([]rune(str)[:pos]) + value + string([]rune(str)[pos:])
|
||||
}
|
||||
|
||||
// GetLeadingWhitespace returns the leading whitespace of the given string
|
||||
func GetLeadingWhitespace(str string) string {
|
||||
ws := ""
|
||||
for _, c := range str {
|
||||
if c == ' ' || c == '\t' {
|
||||
ws += string(c)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return ws
|
||||
}
|
||||
|
||||
@@ -377,8 +377,17 @@ func (v *View) HandleEvent(event tcell.Event) {
|
||||
v.cursor.DeleteSelection()
|
||||
v.cursor.ResetSelection()
|
||||
}
|
||||
|
||||
v.eh.Insert(v.cursor.Loc(), "\n")
|
||||
ws := GetLeadingWhitespace(v.buf.lines[v.cursor.y])
|
||||
v.cursor.Right()
|
||||
|
||||
if settings.AutoIndent {
|
||||
v.eh.Insert(v.cursor.Loc(), ws)
|
||||
for i := 0; i < len(ws); i++ {
|
||||
v.cursor.Right()
|
||||
}
|
||||
}
|
||||
v.cursor.lastVisualX = v.cursor.GetVisualX()
|
||||
case tcell.KeySpace:
|
||||
// Insert a space
|
||||
|
||||
@@ -14,14 +14,14 @@
|
||||
|
||||
- [ ] Persistent undo/redo (saved between open and closing micro)
|
||||
|
||||
- [ ] Auto indent
|
||||
|
||||
- [ ] More options
|
||||
- [ ] Tabs to spaces
|
||||
- [ ] Wrap lines
|
||||
|
||||
### Done
|
||||
|
||||
- [x] Auto indent
|
||||
|
||||
- [x] Line numbers
|
||||
|
||||
- [x] Search and replace
|
||||
|
||||
Reference in New Issue
Block a user