]> git.neil.brown.name Git - edlib.git/commitdiff
linecount: ensure we start a visible beginning of document
authorNeilBrown <neil@brown.name>
Sat, 3 Jun 2023 00:49:37 +0000 (10:49 +1000)
committerNeilBrown <neil@brown.name>
Wed, 28 Jun 2023 05:40:21 +0000 (15:40 +1000)
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 <neil@brown.name>
lib-linecount.c

index b14dc82a15423459e5d72d219759df015c1e3459..43c3f88e3700a0a0b8d67667b32fbf480cbb4f2d 100644 (file)
@@ -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 */