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

Fixed the first line by moving sections #187

Merged
merged 2 commits into from
May 9, 2022
Merged
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions oviewer/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func KeyBindString(k KeyBind) string {
k.writeKeyBind(&b, actionSync, "screen sync")
k.writeKeyBind(&b, actionFollow, "follow mode toggle")
k.writeKeyBind(&b, actionFollowAll, "follow all mode toggle")
k.writeKeyBind(&b, actionFollowSection, "follow section mode toggle")
k.writeKeyBind(&b, actionToggleMouse, "enable/disable mouse")

fmt.Fprint(&b, gchalk.Bold("\n\tMoving\n"))
Expand All @@ -59,9 +58,6 @@ func KeyBindString(k KeyBind) string {
k.writeKeyBind(&b, actionMoveHfLeft, "scroll left half screen")
k.writeKeyBind(&b, actionMoveHfRight, "scroll right half screen")
k.writeKeyBind(&b, actionGoLine, "number of go to line")
k.writeKeyBind(&b, actionNextSection, "next section")
k.writeKeyBind(&b, actionPrevSection, "previous section")
k.writeKeyBind(&b, actionLastSection, "last section")

fmt.Fprint(&b, gchalk.Bold("\n\tMove document\n"))
fmt.Fprint(&b, "\n")
Expand Down Expand Up @@ -98,8 +94,15 @@ func KeyBindString(k KeyBind) string {
k.writeKeyBind(&b, actionHeader, "number of header lines")
k.writeKeyBind(&b, actionSkipLines, "number of skip lines")
k.writeKeyBind(&b, actionTabWidth, "TAB width")

fmt.Fprint(&b, gchalk.Bold("\n\tSection\n"))
fmt.Fprint(&b, "\n")
k.writeKeyBind(&b, actionSection, "section delimiter string")
k.writeKeyBind(&b, actionSectionStart, "section start position")
k.writeKeyBind(&b, actionNextSection, "next section")
k.writeKeyBind(&b, actionPrevSection, "previous section")
k.writeKeyBind(&b, actionLastSection, "last section")
k.writeKeyBind(&b, actionFollowSection, "follow section mode toggle")

fmt.Fprint(&b, gchalk.Bold("\n\tClose and reload\n"))
fmt.Fprint(&b, "\n")
Expand Down
17 changes: 11 additions & 6 deletions oviewer/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (root *Root) nextSction() {
root.resetSelect()
defer root.releaseEventBuffer()
m := root.Doc
num := m.topLN + (1 - root.Doc.SectionStartPosition)
num := m.topLN + m.firstLine() + (1 - root.Doc.SectionStartPosition)
searcher := NewSearcher(root.Doc.SectionDelimiter, root.Doc.SectionDelimiterReg, true, true)
ctx := context.Background()
defer ctx.Done()
Expand All @@ -296,7 +296,7 @@ func (root *Root) nextSction() {
root.movePgDn()
return
}
root.moveLine(n + root.Doc.SectionStartPosition)
root.moveLine((n - root.Doc.firstLine()) + root.Doc.SectionStartPosition)
}

func (root *Root) prevSection() {
Expand All @@ -317,7 +317,7 @@ func (root *Root) prevSection() {
root.moveLine(0)
return
}
root.moveLine(n + root.Doc.SectionStartPosition)
root.moveLine((n - root.Doc.firstLine()) + root.Doc.SectionStartPosition)
}

func (root *Root) lastSection() {
Expand All @@ -328,7 +328,8 @@ func (root *Root) lastSectionPos() int {
root.resetSelect()

m := root.Doc
num := m.BufEndNum() - (1 + root.Doc.SectionStartPosition)
// +1 to avoid if the bottom line is a session delimiter.
num := m.BufEndNum() - 2
searcher := NewSearcher(root.Doc.SectionDelimiter, root.Doc.SectionDelimiterReg, true, true)
ctx := context.Background()
defer ctx.Done()
Expand All @@ -342,11 +343,15 @@ func (root *Root) lastSectionPos() int {
// (it is already the last section).
return 0
}

bottom := m.BufEndNum() - m.latestNum
top := m.topLN
root.moveLine(n + root.Doc.SectionStartPosition)
top = m.topLN - top
root.moveLine((n - root.Doc.firstLine()) + root.Doc.SectionStartPosition)
if top == 0 {
return 0
}

top = m.topLN - top
return bottom - top
}

Expand Down