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

@@ -67,6 +67,10 @@ func (c *Cursor) GotoLoc(l Loc) {
// GetVisualX returns the x value of the cursor in visual spaces
func (c *Cursor) GetVisualX() int {
if c.buf.GetVisualX != nil {
return c.buf.GetVisualX(c.Loc)
}
if c.X <= 0 {
c.X = 0
return 0