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

Avoid bottom line when jump-target #415

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Changes from all 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
12 changes: 10 additions & 2 deletions oviewer/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"strconv"
)

// bottomMargin is the margin of the bottom line when specifying section
const bottomMargin = 2

// MoveLine fires an eventGoto event that moves to the specified line.
func (root *Root) MoveLine(num int) {
if !root.checkScreen() {
Expand Down Expand Up @@ -243,6 +246,11 @@ func (m *Document) searchGoTo(lN int, x int) {
m.moveYUp(m.JumpTarget)
}

// Bottom line of jumpTarget when specifying a section
func (m *Document) bottomJumpTarget() int {
return m.statusPos - bottomMargin
}

// searchGoSection will go to the section with the matching term after searching.
// Move the JumpTarget so that it can be seen from the beginning of the section.
func (m *Document) searchGoSection(lN int, x int) {
Expand Down Expand Up @@ -270,12 +278,12 @@ func (m *Document) searchGoSection(lN int, x int) {
}
}

if m.statusPos > y+m.headerLen {
if m.bottomJumpTarget() > y+m.headerLen {
m.JumpTarget = y
return
}

m.JumpTarget = m.statusPos - (m.headerLen + 1)
m.JumpTarget = m.bottomJumpTarget() - (m.headerLen + 1)
m.moveYDown(y - m.JumpTarget)
}

Expand Down