diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index 5c7c8912..593bf7b7 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -53,8 +53,10 @@ func (w *BufWindow) SetBuffer(b *buffer.Buffer) { } else { w.StartLine.Row = 0 } - w.Relocate() + } + if option == "softwrap" || option == "wordwrap" { + w.Relocate() for _, c := range w.Buf.GetCursors() { c.LastVisualX = c.GetVisualX() } @@ -81,12 +83,6 @@ func (w *BufWindow) Resize(width, height int) { w.updateDisplayInfo() w.Relocate() - - if w.Buf.Settings["softwrap"].(bool) { - for _, c := range w.Buf.GetCursors() { - c.LastVisualX = c.GetVisualX() - } - } } // SetActive marks the window as active. @@ -150,10 +146,18 @@ func (w *BufWindow) updateDisplayInfo() { w.gutterOffset += w.maxLineNumLength + 1 } + prevBufWidth := w.bufWidth + w.bufWidth = w.Width - w.gutterOffset if w.Buf.Settings["scrollbar"].(bool) && w.Buf.LinesNum() > w.Height { w.bufWidth-- } + + if w.bufWidth != prevBufWidth && w.Buf.Settings["softwrap"].(bool) { + for _, c := range w.Buf.GetCursors() { + c.LastVisualX = c.GetVisualX() + } + } } func (w *BufWindow) getStartInfo(n, lineN int) ([]byte, int, int, *tcell.Style) {