From 7c7eb8f83a3069afe9e4e580106113a7fd91672d Mon Sep 17 00:00:00 2001 From: Noboru Saito Date: Wed, 30 Oct 2024 14:03:21 +0900 Subject: [PATCH] Fix linkage of filter documents with headers Fixes misalignment of line number linkage when the filter document has a header. Add nil check as a precaution. --- oviewer/doclist.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/oviewer/doclist.go b/oviewer/doclist.go index d1800d6c..ee94f489 100644 --- a/oviewer/doclist.go +++ b/oviewer/doclist.go @@ -115,8 +115,14 @@ func (root *Root) nextDoc(ctx context.Context) { func (root *Root) previousDoc(ctx context.Context) { fromNum := root.CurrentDoc fromDoc := root.getDocument(fromNum) + if fromDoc == nil { + return + } toNum := root.CurrentDoc - 1 toDoc := root.getDocument(toNum) + if toDoc == nil { + return + } root.setDocumentNum(ctx, toNum) root.input.Event = normal() @@ -135,7 +141,7 @@ func (root *Root) linkLineNum(fromDoc, toDoc *Document) { } if n, ok := fromDoc.lineNumMap.LoadForward(fromDoc.topLN + fromDoc.firstLine()); ok { root.debugMessage("Move parent line number") - toDoc.moveLine(n) + toDoc.moveLine(n - toDoc.firstLine()) } }