Skip to content

Commit

Permalink
implement nano-like page up/page down functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
nimishjha committed Oct 23, 2024
1 parent b3227d6 commit 0a78e53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 27 deletions.
35 changes: 15 additions & 20 deletions internal/action/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -1696,31 +1696,26 @@ func (h *BufPane) SelectPageDown() bool {
return true
}

// CursorPageUp places the cursor a page up
// CursorPageUp scrolls the view up a page,
// keeping the cursor at the same relative position in the view
func (h *BufPane) CursorPageUp() bool {
h.Cursor.Deselect(true)

if h.Cursor.HasSelection() {
h.Cursor.Loc = h.Cursor.CurSelection[0]
h.Cursor.ResetSelection()
h.Cursor.StoreVisualX()
}
h.MoveCursorUp(h.BufView().Height)
h.Relocate()
scrollmargin := int(h.Buf.Settings["scrollmargin"].(float64))
pageOffset := h.BufView().Height - scrollmargin
h.Buf.ClearCursors()
h.ScrollUp(pageOffset)
h.MoveCursorUp(pageOffset)
return true
}

// CursorPageDown places the cursor a page up
// CursorPageDown scrolls the view down a page,
// keeping the cursor at the same relative position in the view
func (h *BufPane) CursorPageDown() bool {
h.Cursor.Deselect(false)

if h.Cursor.HasSelection() {
h.Cursor.Loc = h.Cursor.CurSelection[1]
h.Cursor.ResetSelection()
h.Cursor.StoreVisualX()
}
h.MoveCursorDown(h.BufView().Height)
h.Relocate()
scrollmargin := int(h.Buf.Settings["scrollmargin"].(float64))
pageOffset := h.BufView().Height - scrollmargin
h.Buf.ClearCursors()
h.ScrollDown(pageOffset)
h.ScrollAdjust()
h.MoveCursorDown(pageOffset)
return true
}

Expand Down
8 changes: 1 addition & 7 deletions internal/display/softwrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,7 @@ func (w *BufWindow) diff(s1, s2 SLoc) int {
// within the buffer boundaries.
func (w *BufWindow) Scroll(s SLoc, n int) SLoc {
if !w.Buf.Settings["softwrap"].(bool) {
s.Line += n
if s.Line < 0 {
s.Line = 0
}
if s.Line > w.Buf.LinesNum()-1 {
s.Line = w.Buf.LinesNum() - 1
}
s.Line = util.Clamp(s.Line + n, 0, w.Buf.LinesNum()-1)
return s
}
return w.scroll(s, n)
Expand Down

0 comments on commit 0a78e53

Please sign in to comment.