Fix relocate bug

This commit is contained in:
Zachary Yedidia
2019-06-15 18:00:24 -04:00
parent 47a129b70f
commit aa774164a7
5 changed files with 11 additions and 11 deletions

View File

@@ -966,7 +966,8 @@ func (h *BufPane) End() bool {
v.StartLine = 0
h.SetView(v)
} else {
h.StartLine = h.Buf.LinesNum() - v.Height
v.StartLine = h.Buf.LinesNum() - v.Height
h.SetView(v)
}
return false
}

View File

@@ -67,9 +67,6 @@ type BufPane struct {
Cursor *buffer.Cursor // the active cursor
StartLine int // Vertical scrolling
StartCol int // Horizontal scrolling
// Since tcell doesn't differentiate between a mouse release event
// and a mouse move event with no keys pressed, we need to keep
// track of whether or not the mouse was pressed (or not released) last event to determine
@@ -132,6 +129,7 @@ func (h *BufPane) OpenBuffer(b *buffer.Buffer) {
h.Buf = b
h.BWindow.SetBuffer(b)
h.Cursor = b.GetActiveCursor()
h.Resize(h.GetView().Width, h.GetView().Height)
v := new(display.View)
h.SetView(v)
h.Relocate()

View File

@@ -4,7 +4,6 @@ import (
"encoding/gob"
"errors"
"io"
"log"
"os"
"time"
@@ -39,7 +38,6 @@ func (b *Buffer) Serialize() error {
b.GetActiveCursor().Loc,
b.ModTime,
})
log.Println("save mod time", b.ModTime)
return err
})
}
@@ -66,12 +64,9 @@ func (b *Buffer) Unserialize() error {
if b.Settings["saveundo"].(bool) {
// We should only use last time's eventhandler if the file wasn't modified by someone else in the meantime
if b.ModTime == buffer.ModTime {
log.Println("good mod time")
b.EventHandler = buffer.EventHandler
b.EventHandler.cursors = b.cursors
b.EventHandler.buf = b.SharedBuffer
} else {
log.Println("bad mod time", b.ModTime, buffer.ModTime)
}
}
}

View File

@@ -1,6 +1,7 @@
package display
import (
"log"
"strconv"
"unicode/utf8"
@@ -149,21 +150,27 @@ func (w *BufWindow) Relocate() bool {
ret := false
activeC := w.Buf.GetActiveCursor()
cy := activeC.Y
log.Println("RELOCATE", w.StartLine, cy, height)
scrollmargin := int(b.Settings["scrollmargin"].(float64))
if cy < w.StartLine+scrollmargin && cy > scrollmargin-1 {
log.Println("a")
w.StartLine = cy - scrollmargin
ret = true
} else if cy < w.StartLine {
log.Println("b")
w.StartLine = cy
ret = true
}
if cy > w.StartLine+height-1-scrollmargin && cy < b.LinesNum()-scrollmargin {
log.Println("c")
w.StartLine = cy - height + 1 + scrollmargin
ret = true
} else if cy >= b.LinesNum()-scrollmargin && cy >= height {
log.Println("d")
w.StartLine = b.LinesNum() - height
ret = true
}
log.Println("RELOCATE DONE", w.StartLine)
// horizontal relocation (scrolling)
if !b.Settings["softwrap"].(bool) {
@@ -356,6 +363,7 @@ func (w *BufWindow) showCursor(x, y int, main bool) {
// displayBuffer draws the buffer being shown in this window on the screen.Screen
func (w *BufWindow) displayBuffer() {
log.Println("STARTLINE", w.StartLine)
b := w.Buf
hasMessage := len(b.Messages) > 0

View File

@@ -3,7 +3,6 @@ package display
import (
"bytes"
"fmt"
"log"
"path"
"regexp"
"strconv"
@@ -113,7 +112,6 @@ func (s *StatusLine) Display() {
c = ' '
x++
}
log.Println(x, string(c))
screen.Screen.SetContent(winX+x, y, c, nil, statusLineStyle)
}
} else if x >= s.win.Width-rightLen && x < rightLen+s.win.Width-rightLen {