Fix incorrect LastVisualX after changing bufWidth w/o resize (#2629)
* Fix incorrect LastVisualX after changing bufWidth w/o resize When we resize a buffer pane with softwrap enabled, we update the cursors LastVisualX values to ensure that moving cursor up or down within a wrapped line will move the cursor to the correct location. The problem is that we need to do it also in cases when the visual buffer width within the buffer window is changing without resizing the window itself, e.g. when toggling the ruler on/off. So update LastVisualX whenever the buffer width changes, not neccesarily as a result of resizing the buffer window. * Update LastVisualX and relocate when toggling wordwrap on/off Visual location of a cursor may change not only when softwrap is toggled on or off but also when wordwrap is toggled on or off without changing the softwrap setting. So need to update cursor LastVisualX values and relocate the view if needed, just like when softwrap is toggled, to make sure that moving the cursor up and down will work correctly and that the cursor will not be left out of the view.
This commit is contained in:
parent
5d3dbde698
commit
3f0cd019d7
1 changed files with 11 additions and 7 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue