Add padding to relocate func (fixes weird scrolling behavior)

This commit is contained in:
Camille Scholtz
2016-05-20 17:43:26 +02:00
parent bbcd33d9fd
commit 096221fd0e
3 changed files with 7 additions and 7 deletions

View File

@@ -149,7 +149,7 @@ func HandleCommand(input string, view *View) {
if strings.Contains(flags, "c") {
// The 'check' flag was used
Search(search, view, true)
view.Relocate()
view.Relocate(0)
Redraw(view)
choice, canceled := messenger.YesNoPrompt("Perform replacement? (y,n)")
if canceled {

View File

@@ -121,7 +121,7 @@ func Search(searchStr string, v *View, down bool) {
v.Cursor.curSelection[0] = charPos + match[0]
v.Cursor.curSelection[1] = charPos + match[1]
v.Cursor.x, v.Cursor.y = FromCharPos(charPos+match[1]-1, v.Buf)
if v.Relocate() {
if v.Relocate(4) {
v.matches = Match(v)
}
lastSearch = searchStr

View File

@@ -196,21 +196,21 @@ func (v *View) ReOpen() {
v.Buf = buf
v.matches = Match(v)
v.Cursor.Relocate()
v.Relocate()
v.Relocate(0)
}
}
// Relocate moves the view window so that the cursor is in view
// This is useful if the user has scrolled far away, and then starts typing
func (v *View) Relocate() bool {
func (v *View) Relocate(x int) bool {
ret := false
cy := v.Cursor.y
if cy < v.Topline {
v.Topline = cy - 4
v.Topline = cy - x
ret = true
}
if cy > v.Topline+v.height-1 {
v.Topline = cy - v.height + 5
v.Topline = cy - v.height + 1 + x
ret = true
}
@@ -378,7 +378,7 @@ func (v *View) HandleEvent(event tcell.Event) {
}
if relocate {
v.Relocate()
v.Relocate(0)
}
if settings["syntax"].(bool) {
v.matches = Match(v)