From aa774164a7871144376ce436c31c4aa1db7ad3af Mon Sep 17 00:00:00 2001 From: Zachary Yedidia Date: Sat, 15 Jun 2019 18:00:24 -0400 Subject: [PATCH] Fix relocate bug --- internal/action/actions.go | 3 ++- internal/action/bufpane.go | 4 +--- internal/buffer/serialize.go | 5 ----- internal/display/bufwindow.go | 8 ++++++++ internal/display/statusline.go | 2 -- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index e6c4998d..72081718 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -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 } diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index ae6d56ce..39b6c145 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -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() diff --git a/internal/buffer/serialize.go b/internal/buffer/serialize.go index ffd554b6..2cadcc77 100644 --- a/internal/buffer/serialize.go +++ b/internal/buffer/serialize.go @@ -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) } } } diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index 80e0f668..ff779a10 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -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 diff --git a/internal/display/statusline.go b/internal/display/statusline.go index 79e090f2..beede173 100644 --- a/internal/display/statusline.go +++ b/internal/display/statusline.go @@ -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 {