diff --git a/internal/action/actions.go b/internal/action/actions.go index 4599606c16..2c5f51d233 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -254,8 +254,13 @@ func (h *BufPane) CursorUp() bool { // CursorDown moves the cursor down func (h *BufPane) CursorDown() bool { + selectionEndNewline := h.Cursor.HasSelection() && h.Cursor.CurSelection[1].X == 0 h.Cursor.Deselect(false) - h.MoveCursorDown(1) + if selectionEndNewline { + h.Cursor.Start() + } else { + h.MoveCursorDown(1) + } h.Relocate() return true } @@ -289,7 +294,6 @@ func (h *BufPane) CursorLeft() bool { func (h *BufPane) CursorRight() bool { if h.Cursor.HasSelection() { h.Cursor.Deselect(false) - h.Cursor.Right() } else { tabstospaces := h.Buf.Settings["tabstospaces"].(bool) tabmovement := h.Buf.Settings["tabmovement"].(bool) @@ -1732,14 +1736,21 @@ func (h *BufPane) CursorPageUp() bool { // CursorPageDown places the cursor a page down, // moving the view to keep cursor at the same relative position in the view func (h *BufPane) CursorPageDown() bool { + selectionEndNewline := h.Cursor.HasSelection() && h.Cursor.CurSelection[1].X == 0 h.Cursor.Deselect(false) pageOverlap := int(h.Buf.Settings["pageoverlap"].(float64)) scrollAmount := h.BufView().Height - pageOverlap + if selectionEndNewline { + scrollAmount-- + } h.MoveCursorDown(scrollAmount) if h.Cursor.Num == 0 { h.ScrollDown(scrollAmount) h.ScrollAdjust() } + if selectionEndNewline { + h.Cursor.Start() + } h.Relocate() return true } diff --git a/internal/buffer/cursor.go b/internal/buffer/cursor.go index d849f836b2..f6eb91af7e 100644 --- a/internal/buffer/cursor.go +++ b/internal/buffer/cursor.go @@ -193,7 +193,7 @@ func (c *Cursor) Deselect(start bool) { if start { c.Loc = c.CurSelection[0] } else { - c.Loc = c.CurSelection[1].Move(-1, c.buf) + c.Loc = c.CurSelection[1] } c.ResetSelection() c.StoreVisualX() diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index 6315bcc60a..1a2af426cf 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -449,7 +449,7 @@ func (w *BufWindow) displayBuffer() { currentLine := false for _, c := range cursors { - if bloc.Y == c.Y && w.active { + if !c.HasSelection() && bloc.Y == c.Y && w.active { currentLine = true break }