Add more option support

This commit is contained in:
Zachary Yedidia
2019-01-24 18:25:59 -05:00
parent 0e4faf108d
commit ef18fc572c
4 changed files with 23 additions and 20 deletions

View File

@@ -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
}

View File

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

View File

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

View File

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