]> git.neil.brown.name Git - edlib.git/commitdiff
lib-render: move tab/non-tab distinction out of find_xy()
authorNeilBrown <neil@brown.name>
Fri, 18 Aug 2023 19:35:26 +0000 (05:35 +1000)
committerNeilBrown <neil@brown.name>
Fri, 18 Aug 2023 19:35:26 +0000 (05:35 +1000)
The special handling of tabs is best kept in common code.
So move more into do_measure().

Signed-off-by: NeilBrown <neil@brown.name>
DOC/TODO.md
lib-renderline.c

index 128dbf714e79071f3b3b98ca1b031a9111623f60..669bd549765fbd07113d9cf204beaf84f5c23e15 100644 (file)
@@ -10,9 +10,9 @@ the file.
 ### Triage
 
 
-- [ ] tabs can wrap around a newline - with part of tab at end of one
+- [X] tabs can wrap around a newline - with part of tab at end of one
       line and part at start of the next.  Do I want that?  do_measure()
-      decides.
+      decides. YES.
 - [X] in xcb, find-file draws result a pixel high, then moves done
       when cursor moves
 - [ ] favourites...  I want some favourite documents that are easy to
index 7dad2bdb24e996014ebf6fc77548ae25b8a91ce9..ef506a3e633860b3abff98ddefd68f37fb7c929b 100644 (file)
@@ -481,6 +481,13 @@ static inline struct call_return do_measure(struct pane *p safe,
            cr.i >= len)
                /* All fits in maxwidth */
                cr.ret = 2;
+       /* Report position in rd->line */
+       if (str == tb) {
+               cr.s = rd->line + ri->start;
+               if (splitpos + cr.i >= ri->tab_cols)
+                       cr.s += 1;
+       } else
+               cr.s = str + cr.i;
        return cr;
 }
 
@@ -968,12 +975,8 @@ static int find_xy(struct pane *p safe, struct pane *focus safe,
            ri->y + rd->line_height * splitpos > y &&
            xyattr)
                *xyattr = ri->attr;
-       if (rd->line[ri->start] == '\t')
-               /* do_measure reports how many spaces, we don't care */
-               /* FIXME but should do_measure report that?  Do I *want*
-                * a tab to wrap around a newline??
-                */
-               cr.i = 0;
+       if (cr.s)
+               return cr.s - rd->line;
        return start + cr.i;
 }