From ef18fc572c55f4323fa6472e40e41cd7f180f383 Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Thu, 24 Jan 2019 18:25:59 -0500 Subject: [PATCH] Add more option support --- cmd/micro/action/actions.go | 6 +++--- cmd/micro/action/command.go | 7 +++---- cmd/micro/buffer/buffer.go | 6 +++++- cmd/micro/buffer/save.go | 24 ++++++++++++------------ 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/cmd/micro/action/actions.go b/cmd/micro/action/actions.go index d66991e4..f567cb24 100644 --- a/cmd/micro/action/actions.go +++ b/cmd/micro/action/actions.go @@ -471,7 +471,7 @@ func (h *BufPane) IndentSelection() bool { h.Cursor.SetSelectionEnd(buffer.Loc{X: endX + indentsize + 1, Y: endY}) } } - h.Cursor.Relocate() + h.Buf.RelocateCursors() return true } @@ -490,7 +490,7 @@ func (h *BufPane) OutdentLine() bool { } h.Buf.Remove(buffer.Loc{X: 0, Y: h.Cursor.Y}, buffer.Loc{X: 1, Y: h.Cursor.Y}) } - h.Cursor.Relocate() + h.Buf.RelocateCursors() return true } @@ -515,7 +515,7 @@ func (h *BufPane) OutdentSelection() bool { h.Buf.Remove(buffer.Loc{X: 0, Y: y}, buffer.Loc{X: 1, Y: y}) } } - h.Cursor.Relocate() + h.Buf.RelocateCursors() return true } diff --git a/cmd/micro/action/command.go b/cmd/micro/action/command.go index 7a34c6de..bcec0ee8 100644 --- a/cmd/micro/action/command.go +++ b/cmd/micro/action/command.go @@ -587,7 +587,7 @@ func (h *BufPane) ReplaceCmd(args []string) { } if !found || !inRange(locs[0]) || !inRange(locs[1]) { h.Cursor.ResetSelection() - h.Cursor.Relocate() + h.Buf.RelocateCursors() return } @@ -606,7 +606,7 @@ func (h *BufPane) ReplaceCmd(args []string) { searchLoc.X += utf8.RuneCount(replace) } else if canceled { h.Cursor.ResetSelection() - h.Cursor.Relocate() + h.Buf.RelocateCursors() return } if searching { @@ -617,8 +617,7 @@ func (h *BufPane) ReplaceCmd(args []string) { doReplacement() } - // TODO: relocate all cursors? - h.Cursor.Relocate() + h.Buf.RelocateCursors() if nreplaced > 1 { InfoBar.Message("Replaced ", nreplaced, " occurrences of ", search) diff --git a/cmd/micro/buffer/buffer.go b/cmd/micro/buffer/buffer.go index 83b22549..9de2b967 100644 --- a/cmd/micro/buffer/buffer.go +++ b/cmd/micro/buffer/buffer.go @@ -306,10 +306,14 @@ func (b *Buffer) ReOpen() error { b.ModTime, err = GetModTime(b.Path) b.isModified = false + b.RelocateCursors() + return err +} + +func (b *Buffer) RelocateCursors() { for _, c := range b.cursors { c.Relocate() } - return err } // RuneAt returns the rune at a given location in the buffer diff --git a/cmd/micro/buffer/save.go b/cmd/micro/buffer/save.go index 7337baad..a6e34f6e 100644 --- a/cmd/micro/buffer/save.go +++ b/cmd/micro/buffer/save.go @@ -8,6 +8,8 @@ import ( "os/exec" "os/signal" "path/filepath" + "unicode" + "unicode/utf8" "github.com/zyedidia/micro/cmd/micro/config" . "github.com/zyedidia/micro/cmd/micro/util" @@ -58,19 +60,17 @@ func (b *Buffer) SaveAs(filename string) error { return errors.New("Cannot save scratch buffer") } - // TODO: rmtrailingws and updaterules b.UpdateRules() - // if b.Settings["rmtrailingws"].(bool) { - // for i, l := range b.lines { - // pos := len(bytes.TrimRightFunc(l.data, unicode.IsSpace)) - // - // if pos < len(l.data) { - // b.deleteToEnd(Loc{pos, i}) - // } - // } - // - // b.Cursor.Relocate() - // } + if b.Settings["rmtrailingws"].(bool) { + for i, l := range b.lines { + leftover := utf8.RuneCount(bytes.TrimRightFunc(l.data, unicode.IsSpace)) + + linelen := utf8.RuneCount(l.data) + b.Remove(Loc{leftover, i}, Loc{linelen, i}) + } + + b.RelocateCursors() + } if b.Settings["eofnewline"].(bool) { end := b.End()