From 0a791e7c4b5fe38ef808dc8f500dd4418fa1aa84 Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Fri, 20 May 2022 07:51:03 +0900 Subject: [PATCH] Clarification of the role of the lastSection move Separate tailSection from follow(). moved the set of lastSectionPosNum. --- oviewer/action.go | 11 +++++++++++ oviewer/event.go | 6 +----- oviewer/move.go | 1 - 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/oviewer/action.go b/oviewer/action.go index 552c0e73..ec973f40 100644 --- a/oviewer/action.go +++ b/oviewer/action.go @@ -434,6 +434,17 @@ func (root *Root) TailSync() { root.ViewSync() } +// tailSection moves to the last section +// and adjusts to its original position. +func (root *Root) tailSection() { + moved := root.Doc.topLN - root.Doc.lastSectionPosNum + root.lastSection() + if moved > 0 && (root.Doc.topLN+moved) < root.Doc.BufEndNum() { + root.moveLine(root.Doc.topLN + moved) + } + root.Doc.lastSectionPosNum = root.Doc.topLN +} + // prepareStartX prepares startX. func (root *Root) prepareStartX() { root.startX = 0 diff --git a/oviewer/event.go b/oviewer/event.go index 0b54d65f..8a5800e5 100644 --- a/oviewer/event.go +++ b/oviewer/event.go @@ -185,11 +185,7 @@ func (root *Root) follow() { root.skipDraw = false if root.Doc.FollowSection { - moved := root.Doc.topLN - root.Doc.lastSectionPosNum - root.lastSection() - if moved > 0 && (root.Doc.topLN+moved) < root.Doc.BufEndNum() { - root.moveLine(root.Doc.topLN + moved) - } + root.tailSection() } else { root.TailSync() } diff --git a/oviewer/move.go b/oviewer/move.go index a304d366..ab9658f8 100644 --- a/oviewer/move.go +++ b/oviewer/move.go @@ -337,7 +337,6 @@ func (root *Root) lastSection() { return } n = (n - root.Doc.firstLine()) + root.Doc.SectionStartPosition - m.lastSectionPosNum = n root.moveLine(n) }