Implement moving cursor up/down within a wrapped line

Modified behavior of CursorUp, CursorDown, CursorPageUp etc:
if softwrap is enabled, cursor moves by visual lines, not logical lines.

TODO: implement it also for Home and End keys: move cursor to the
visual start or end of a line. I haven't implemented it for now, because
I'm not sure what should be the behavior of StartOfTextToggle then
(considering that Home key is bound to StartOfTextToggle by default).

Fixes #1598
This commit is contained in:
Dmitry Maluka
2021-03-06 23:43:36 +01:00
parent 7a3d1e6e30
commit 6d13710d93
4 changed files with 72 additions and 8 deletions

View File

@@ -54,8 +54,15 @@ func (w *BufWindow) SetBuffer(b *buffer.Buffer) {
w.StartLine.Row = 0
}
w.Relocate()
for _, c := range w.Buf.GetCursors() {
c.LastVisualX = c.GetVisualX()
}
}
}
b.GetVisualX = func(loc buffer.Loc) int {
return w.VLocFromLoc(loc).VisualX
}
}
func (w *BufWindow) GetView() *View {
@@ -68,7 +75,15 @@ func (w *BufWindow) SetView(view *View) {
func (w *BufWindow) Resize(width, height int) {
w.Width, w.Height = width, height
w.updateDisplayInfo()
w.Relocate()
if w.Buf.Settings["softwrap"].(bool) {
for _, c := range w.Buf.GetCursors() {
c.LastVisualX = c.GetVisualX()
}
}
}
func (w *BufWindow) SetActive(b bool) {