Skip to content

Commit

Permalink
Merge pull request #465 from noborus/fix-section-header
Browse files Browse the repository at this point in the history
Fix position only if first line is section-header
  • Loading branch information
noborus authored Dec 24, 2023
2 parents 2b84aca + ea0c3f6 commit 705aab0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/viper v1.18.1 h1:rmuU42rScKWlhhJDyXZRKJQHXFX02chSVW1IvkPGiVM=
github.com/spf13/viper v1.18.1/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ=
github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -89,8 +87,6 @@ go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611 h1:qCEDpW1G+vcj3Y7Fy52pEM1AWm3abj8WimGYejI3SC4=
golang.org/x/exp v0.0.0-20231214170342-aacd6d4b4611/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 h1:+iq7lrkxmFNBM7xx+Rae2W6uyPfhPeDWD+n+JgppptE=
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand Down
16 changes: 8 additions & 8 deletions oviewer/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ func (root *Root) draw() {

// Section header
n := root.drawSectionHeader(lN)
if root.Doc.SectionHeaderNum > lN && lN != n {
if lN == 0 && lN <= root.Doc.SectionHeaderNum {
lN = n
if m.topLN == 0 {
m.topLN = 1
}
}

// Body
lX, lN = root.drawBody(lX, lN)

Expand Down Expand Up @@ -115,7 +111,6 @@ func (root *Root) drawHeader() int {
// drawSectionHeader advances the line
// if the section header contains a line in the terminal.
func (root *Root) drawSectionHeader(lN int) int {
log.Println("drawSectionHeader", lN)
m := root.Doc
if !m.SectionHeader || m.SectionDelimiter == "" {
return lN
Expand Down Expand Up @@ -154,6 +149,9 @@ func (root *Root) drawSectionHeader(lN int) int {
root.sectionLineHighlight(y, line.str)
m.headerLen += 1
if nextN != sn {
if root.scr.sectionHeaderLeft > 0 {
root.scr.sectionHeaderLeft--
}
sn = nextN
line, valid = m.getLineC(sn, m.TabWidth)
}
Expand Down Expand Up @@ -195,6 +193,9 @@ func (root *Root) drawBody(lX int, lN int) (int, int) {
lX = nextX
if nextY != lN {
lN = nextY
if root.scr.sectionHeaderLeft > 0 {
root.scr.sectionHeaderLeft--
}
line, valid = m.getLineC(lN, m.TabWidth)
root.bodyStyle(line.lc, root.StyleBody)
if valid {
Expand Down Expand Up @@ -656,10 +657,9 @@ func (root *Root) sectionLineHighlight(y int, str string) {
}
if root.scr.sectionHeaderLeft > 0 {
root.yStyle(y, root.StyleSectionLine)
root.scr.sectionHeaderLeft--
}
if root.Doc.SectionDelimiterReg.MatchString(str) {
root.yStyle(y, root.StyleSectionLine)
root.scr.sectionHeaderLeft = root.Doc.SectionHeaderNum - 1
root.scr.sectionHeaderLeft = root.Doc.SectionHeaderNum
}
}

0 comments on commit 705aab0

Please sign in to comment.