From ef043a4a9c664f7277e28d53f77b0fbb8fdd2079 Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Mon, 25 Dec 2023 13:43:06 +0900 Subject: [PATCH] Adjust position only when moving to the beginning Changed policy to adjust section header movement only when moving to the beginning. --- oviewer/document.go | 13 ++++++++----- oviewer/draw.go | 6 +++++- oviewer/move_vertical.go | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/oviewer/document.go b/oviewer/document.go index 849ee13b..430b7bb9 100644 --- a/oviewer/document.go +++ b/oviewer/document.go @@ -113,6 +113,8 @@ type Document struct { seekable bool // Is it possible to reopen. reopenable bool + // startTopFlag + startTopFlag bool } // store represents store management. @@ -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 diff --git a/oviewer/draw.go b/oviewer/draw.go index 4c1a9fea..9989c43d 100644 --- a/oviewer/draw.go +++ b/oviewer/draw.go @@ -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) @@ -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 } diff --git a/oviewer/move_vertical.go b/oviewer/move_vertical.go index 8d5abd39..c6454ab3 100644 --- a/oviewer/move_vertical.go +++ b/oviewer/move_vertical.go @@ -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()) }