From 82526daf1af2b5a2d925977b9813be202c00cfeb Mon Sep 17 00:00:00 2001 From: NeilBrown Date: Sat, 3 Jun 2023 10:49:37 +1000 Subject: [PATCH] linecount: ensure we start a visible beginning of document The document we are counting might be a 'view' and the early lines might be clipped off. So use doc:set-ref to move to the beginning as visible from the focus. Also simplify the code as two conditions each have exactly the same result. Signed-off-by: NeilBrown --- lib-linecount.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/lib-linecount.c b/lib-linecount.c index b14dc82a..43c3f88e 100644 --- a/lib-linecount.c +++ b/lib-linecount.c @@ -127,21 +127,14 @@ static void count_calculate(struct pane *p safe, struct mark *m, *m2; m = vmark_first(p, type, owner); - if (m == NULL) { - /* No marks yet, let's make some */ + if (m == NULL || doc_prior(p, m) != WEOF) { + /* No mark at doc start, make some */ m = vmark_new(p, type, owner); if (!m) return; + call("doc:set-ref", p, 1, m); do_count(p, m, NULL, &l, &w, &c, 1); } - if (doc_prior(p, m) != WEOF) { - /* no mark at start of file */ - m2 = vmark_new(p, type, owner); - if (!m2) - return; - do_count(p, m2, m, &l, &w, &c, 1); - m = m2; - } if (need_recalc(p, m)) /* need to update this one */ -- 2.39.5