Skip to content

Commit

Permalink
Merge pull request #466 from noborus/fix-section-header-2
Browse files Browse the repository at this point in the history
Adjust position only when moving to the beginning
  • Loading branch information
noborus authored Dec 25, 2023
2 parents 705aab0 + ef043a4 commit 6ab515e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
13 changes: 8 additions & 5 deletions oviewer/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ type Document struct {
seekable bool
// Is it possible to reopen.
reopenable bool
// startTopFlag
startTopFlag bool
}

// store represents store management.
Expand Down Expand Up @@ -171,11 +173,12 @@ func NewDocument() (*Document, error) {
TabWidth: 8,
MarkStyleWidth: 1,
},
ctlCh: make(chan controlSpecifier),
memoryLimit: 100,
seekable: true,
reopenable: true,
store: NewStore(),
ctlCh: make(chan controlSpecifier),
memoryLimit: 100,
seekable: true,
reopenable: true,
store: NewStore(),
startTopFlag: true,
}
if err := m.NewCache(); err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion oviewer/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ func (root *Root) draw() {

// Section header
n := root.drawSectionHeader(lN)
if lN == 0 && lN <= root.Doc.SectionHeaderNum {
if m.startTopFlag && lN < m.SectionHeaderNum {
lN = n
m.topLN = n
} else {
m.startTopFlag = false
}
// Body
lX, lN = root.drawBody(lX, lN)
Expand Down Expand Up @@ -117,6 +120,7 @@ func (root *Root) drawSectionHeader(lN int) int {
}

pn := lN
// If the line number is 0, it is the first line.
if pn == 0 {
pn = 1
}
Expand Down
1 change: 1 addition & 0 deletions oviewer/move_vertical.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (m *Document) moveLine(lN int) int {

// moveTop moves to the top.
func (m *Document) moveTop() {
m.startTopFlag = true
m.moveLine(m.BufStartNum())
}

Expand Down

0 comments on commit 6ab515e

Please sign in to comment.