Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actions: Perform Cursor(Page)Down with selection like GUI editors do #3540

Merged
merged 4 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion internal/action/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -289,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)
Expand Down Expand Up @@ -1732,6 +1735,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
Expand All @@ -1740,6 +1744,9 @@ func (h *BufPane) CursorPageDown() bool {
h.ScrollDown(scrollAmount)
h.ScrollAdjust()
}
if selectionEndNewline {
h.Cursor.Start()
}
h.Relocate()
return true
}
Expand Down
2 changes: 1 addition & 1 deletion internal/buffer/cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
JoeKar marked this conversation as resolved.
Show resolved Hide resolved
}
c.ResetSelection()
c.StoreVisualX()
Expand Down
2 changes: 1 addition & 1 deletion internal/display/bufwindow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down