Skip to content

Commit

Permalink
Avoid bottom line when jump-target
Browse files Browse the repository at this point in the history
Avoid bottom line when jump-target is set to section.
  • Loading branch information
noborus committed Jul 17, 2023
1 parent 5e2ab3c commit 2e88d22
Showing 1 changed file with 10 additions and 2 deletions.
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

0 comments on commit 2e88d22

Please sign in to comment.