AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

80

TVResize+TVFindInRectLocked: Avoid manual searches


jcs made amendment 80 about 1 month ago
--- tv_layout.c Wed Oct 14 22:48:58 2026 +++ tv_layout.c Wed Oct 14 23:34:20 2026 @@ -23,11 +23,9 @@ Boolean TVResize(TVHandle tvh) { struct TVRec *tv; - long width, height, n; + long n; struct TVLine *line; struct TVChunk *chunk; - BigRect visible; - long nline; unsigned long top_start; tv = TVLock(tvh); @@ -36,20 +34,11 @@ TVResize(TVHandle tvh) EraseRect(&tv->frame); TVRevealCanvas(tv); - /* find text position of first line to try to stay there */ + /* find text position of first visible line to try to stay there */ top_start = 0; - for (nline = 1; nline <= tv->nlines; nline++) { - line = TVGetLine(tv, nline); - if (line == NULL) - break; - - if (tv->scrolled.top + line->rect.bottom < 0L) - /* is not in the view at all yet */ - continue; - + line = TVGetLine(tv, TVLineForY(tv, -(tv->scrolled.top))); + if (line != NULL) top_start = line->start; - break; - } #ifdef USE_CANVAS if (!TVSetupCanvas(tv)) { @@ -99,18 +88,13 @@ TVResize(TVHandle tvh) tv->scrolled.bottom = tv->frame.bottom; tv->scrolled.top = tv->scrolled.bottom - tv->bounds.bottom; } else { - for (nline = 1; nline <= tv->nlines; nline++) { - line = TVGetLine(tv, nline); - if (line == NULL) - break; - - if (line->start <= top_start && top_start < line->end) { - /* keep this line at the top */ - tv->scrolled.top = -(line->rect.top); - tv->scrolled.bottom = tv->scrolled.top + - tv->bounds.bottom; - break; - } + /* keep the line now holding that text at the top */ + line = TVGetLine(tv, TVLineForOffset(tv, top_start)); + if (line != NULL && line->start <= top_start && + top_start < line->end) { + tv->scrolled.top = -(line->rect.top); + tv->scrolled.bottom = tv->scrolled.top + + tv->bounds.bottom; } } } @@ -396,7 +380,7 @@ TVFindInRectLocked(struct TVRec *tv, BigRect *rect, lo TVFindInRectCallback callback, void *cookie) { struct TVFindInRectMatch match; - unsigned long nline, ppl; + unsigned long nline; Boolean ret; TVUseCanvas(tv); @@ -405,24 +389,9 @@ TVFindInRectLocked(struct TVRec *tv, BigRect *rect, lo match.chunk = NULL; ret = false; - if (startline == 0 && tv->nlines > 1) { - /* take a stab at getting us closer */ - ppl = (tv->bounds.bottom / tv->nlines); - if (ppl == 0) - ppl = 1; - startline = rect->top / ppl; - if (startline > tv->nlines) - startline = tv->nlines; - if (startline > 1) { - match.line = TVGetLine(tv, startline); - while (startline > 1 && match.line != NULL && - match.line->rect.top > rect->top) { - startline--; - match.line = TVGetLine(tv, startline); - } - } - } - + if (startline == 0) + startline = TVLineForY(tv, rect->top); + if (startline == 0) startline = 1;