h.Cursor.SetSelectionEnd(buffer.Loc{X: endX + indentsize + 1, Y: endY})
}
}
- h.Cursor.Relocate()
+ h.Buf.RelocateCursors()
return true
}
}
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
}
h.Buf.Remove(buffer.Loc{X: 0, Y: y}, buffer.Loc{X: 1, Y: y})
}
}
- h.Cursor.Relocate()
+ h.Buf.RelocateCursors()
return true
}
}
if !found || !inRange(locs[0]) || !inRange(locs[1]) {
h.Cursor.ResetSelection()
- h.Cursor.Relocate()
+ h.Buf.RelocateCursors()
return
}
searchLoc.X += utf8.RuneCount(replace)
} else if canceled {
h.Cursor.ResetSelection()
- h.Cursor.Relocate()
+ h.Buf.RelocateCursors()
return
}
if searching {
doReplacement()
}
- // TODO: relocate all cursors?
- h.Cursor.Relocate()
+ h.Buf.RelocateCursors()
if nreplaced > 1 {
InfoBar.Message("Replaced ", nreplaced, " occurrences of ", search)
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
"os/exec"
"os/signal"
"path/filepath"
+ "unicode"
+ "unicode/utf8"
"github.com/zyedidia/micro/cmd/micro/config"
. "github.com/zyedidia/micro/cmd/micro/util"
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()