From 3a16197da71c48bdc84bd097f4e185fefc4720b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:29:02 +0100 Subject: [PATCH 1/4] actions: On `Cursor(Page)Down` with selection of newline place cursor to start --- internal/action/actions.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/action/actions.go b/internal/action/actions.go index 4599606c1..c1a96e336 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -254,8 +254,12 @@ 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() + } h.Relocate() return true } @@ -1732,6 +1736,7 @@ 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 @@ -1740,6 +1745,9 @@ func (h *BufPane) CursorPageDown() bool { h.ScrollDown(scrollAmount) h.ScrollAdjust() } + if selectionEndNewline { + h.Cursor.Start() + } h.Relocate() return true } From aaf45a871f45c06e7f46480f9f0cdd9a20b2b200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Tue, 26 Nov 2024 20:30:43 +0100 Subject: [PATCH 2/4] bufwindow: Don't highlight lines in ruler with active selection --- internal/display/bufwindow.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index 6315bcc60..1a2af426c 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 } From 50639015d748fc14c6484472b60ba7ca68798062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:25:14 +0100 Subject: [PATCH 3/4] cursor: Remove selection reduction by one character on `Deselect()` --- internal/action/actions.go | 1 - internal/buffer/cursor.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index c1a96e336..ec77ba5f1 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -293,7 +293,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) diff --git a/internal/buffer/cursor.go b/internal/buffer/cursor.go index d849f836b..f6eb91af7 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() From 2c4754d484cfe93166b49f043753e05e7010dee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6ran=20Karl?= <3951388+JoeKar@users.noreply.github.com> Date: Sat, 30 Nov 2024 16:51:13 +0100 Subject: [PATCH 4/4] actions: Prevent additional cursor move down on `Cursor(Page)Down` This is needed to not move two lines below the last visual selection when it has end behind the new line character. --- internal/action/actions.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/action/actions.go b/internal/action/actions.go index ec77ba5f1..2c5f51d23 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -256,9 +256,10 @@ func (h *BufPane) CursorUp() bool { 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 @@ -1739,6 +1740,9 @@ func (h *BufPane) CursorPageDown() bool { 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)