AmendHub

Download (as of this amendment):

jcs

/

textview

/

amendments

/

47

TVFindInRect: When we don't get a start hint, make an educated guess

This greatly speeds up scrolling
 
Also move everything to longs, on a huge text we were hitting the
max short size and wrapping around

jcs made amendment 47 over 2 years ago
--- textview.c Fri Nov 8 22:48:46 2024 +++ textview.c Sat Nov 9 00:21:14 2024 @@ -59,10 +59,10 @@ short TVScrollDivisor(struct TVRec *tv); Boolean TVCalcLinesLocked(struct TVRec *tv, Boolean ignore_dirty); void TVApplyStyle(struct TVStyle *style); struct TVStyle * TVFindStyle(struct TVRec *tv, struct TVStyle *style); -void TVScrollUnlocked(struct TVRec *tv, short horiz, short vert); +void TVScrollUnlocked(struct TVRec *tv, long horiz, long vert); Boolean TVGetOffsetCallback(struct TVRec *tv, struct TVFindInRectMatch *match, void *cookie); -Boolean TVFindInRect(struct TVRec *tv, BigRect *findrect, short startline, +Boolean TVFindInRect(struct TVRec *tv, BigRect *findrect, long startline, TVFindInRectCallback callback, void *cookie); Boolean TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch *match, void *cookie); @@ -282,7 +282,7 @@ TVAppendLocked(struct TVRec *tv, struct TVStyle *style if (tv->scrolled.top + redraw.bottom > 0L && tv->scrolled.top + redraw.top < tv->frame.bottom) - TVFindInRect(tv, &redraw, fromline ? fromline->nline : 1, + TVFindInRect(tv, &redraw, fromline ? fromline->nline : 0, TVDrawMatch, NULL); TVRevealCanvas(tv); @@ -309,7 +309,7 @@ TVResize(TVHandle tvh) long width, height, n; struct TVLine *line; BigRect visible; - short nline; + long nline; unsigned long top_start; tv = TVLock(tvh); @@ -393,7 +393,7 @@ TVResize(TVHandle tvh) visible.left = -(tv->scrolled.left); visible.bottom = visible.top + tv->frame.bottom; visible.right = visible.left + tv->frame.right; - TVFindInRect(tv, &visible, 1, TVDrawMatch, NULL); + TVFindInRect(tv, &visible, 0, TVDrawMatch, NULL); TVRevealCanvas(tv); TVUnlock(tv); @@ -600,7 +600,7 @@ TVGetOffset(TVHandle tvh, Point p) prect.bottom = prect.top; off = 0; - if (!TVFindInRect(tv, &prect, 1, TVGetOffsetCallback, &off)) + if (!TVFindInRect(tv, &prect, 0, TVGetOffsetCallback, &off)) off = -1; TVRevealCanvas(tv); @@ -624,7 +624,7 @@ TVTrackScrollControl(ControlHandle control, short part KeyMap km; BigRect visible; long n, top; - unsigned short nline; + unsigned long nline; Boolean horiz, cmd_down; if (tv_track_control == NULL) { @@ -647,7 +647,7 @@ TVTrackScrollControl(ControlHandle control, short part visible.left = -(tv->scrolled.left); visible.bottom = visible.top + tv->frame.bottom; visible.right = visible.left + tv->frame.right; - TVFindInRect(tv, &visible, 1, TVSetTopBottomMatch, NULL); + TVFindInRect(tv, &visible, 0, TVSetTopBottomMatch, NULL); if (tv->top_line == NULL) { tv->top_line = TVGetLine(tv, nline); @@ -678,7 +678,7 @@ TVTrackScrollControl(ControlHandle control, short part } /* nothing found, just scroll to the top */ - TVScrollUnlocked(tv, 0, -(tv->scrolled.top)); + TVScrollUnlocked(tv, 0, tv->bounds.bottom); break; case inPageUp: /* scroll to put the top mostly-visible line at the bottom */ @@ -714,8 +714,7 @@ TVTrackScrollControl(ControlHandle control, short part } /* nothing found, just scroll to the bottom */ - TVScrollUnlocked(tv, 0, (long)tv->frame.bottom - - tv->scrolled.bottom); + TVScrollUnlocked(tv, 0, -(tv->bounds.bottom)); break; } @@ -724,13 +723,13 @@ TVTrackScrollControl(ControlHandle control, short part } void -TVScroll(TVHandle tvh, short horiz, short vert) +TVScroll(TVHandle tvh, long horiz, long vert) { struct TVRec *tv; tv = TVLock(tvh); - TVScrollUnlocked(tv, (long)horiz * TVScrollDivisor(tv), - (long)vert * TVScrollDivisor(tv)); + TVScrollUnlocked(tv, horiz * TVScrollDivisor(tv), + vert * TVScrollDivisor(tv)); TVUnlock(tv); } @@ -835,7 +834,7 @@ TVUpdate(TVHandle tvh) visible.left = -(tv->scrolled.left); visible.bottom = visible.top + tv->frame.bottom; visible.right = visible.left + tv->frame.right; - TVFindInRect(tv, &visible, 1, TVDrawMatch, NULL); + TVFindInRect(tv, &visible, 0, TVDrawMatch, NULL); TVRevealCanvas(tv); TVUnlock(tv); @@ -872,7 +871,6 @@ struct TVRec * TVLock(TVHandle tvh) { struct TVRec *tv; - short n; HLock(tvh); tv = *tvh; @@ -1463,11 +1461,11 @@ TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch } Boolean -TVFindInRect(struct TVRec *tv, BigRect *rect, short startline, +TVFindInRect(struct TVRec *tv, BigRect *rect, long startline, TVFindInRectCallback callback, void *cookie) { struct TVFindInRectMatch match; - unsigned short nline; + unsigned long nline; Boolean ret; TVUseCanvas(tv); @@ -1476,6 +1474,20 @@ TVFindInRect(struct TVRec *tv, BigRect *rect, short st match.chunk = NULL; ret = false; + if (startline == 0 && tv->nlines > 1) { + /* take a stab at getting us closer */ + startline = rect->top / (tv->bounds.bottom / tv->nlines); + if (startline > 1) { + match.line = TVGetLine(tv, startline); + while (startline > 0 && match.line->rect.top > rect->top) { + startline--; + match.line = TVGetLine(tv, startline); + } + } + if (startline == 0) + startline = 1; + } + for (nline = startline; nline <= tv->nlines; nline++) { match.line = TVGetLine(tv, nline); if (match.line == NULL) @@ -1568,7 +1580,7 @@ TVSetTopBottomMatch(struct TVRec *tv, struct TVFindInR } void -TVScrollUnlocked(struct TVRec *tv, short horiz, short vert) +TVScrollUnlocked(struct TVRec *tv, long horiz, long vert) { struct TVChunk *chunk; struct TVLine *line; @@ -1616,7 +1628,7 @@ TVScrollUnlocked(struct TVRec *tv, short horiz, short visible.left = -(tv->scrolled.left); visible.bottom = visible.top + tv->frame.bottom; visible.right = visible.left + tv->frame.right; - TVFindInRect(tv, &visible, 1, TVDrawMatch, NULL); + TVFindInRect(tv, &visible, 0, TVDrawMatch, NULL); TVRevealCanvas(tv); return; } @@ -1632,7 +1644,7 @@ TVScrollUnlocked(struct TVRec *tv, short horiz, short HUnlock(vacated); DisposeRgn(vacated); - TVFindInRect(tv, &visible, 1, TVDrawMatch, NULL); + TVFindInRect(tv, &visible, 0, TVDrawMatch, NULL); TVRevealCanvas(tv); } --- textview.h Fri Nov 8 22:24:25 2024 +++ textview.h Sat Nov 9 00:05:56 2024 @@ -164,7 +164,7 @@ void TVClick(TVHandle tvh, Point p, Boolean extend); unsigned long TVGetText(TVHandle tvh, char *dst, unsigned long start, unsigned long end); long TVGetOffset(TVHandle tvh, Point p); -void TVScroll(TVHandle tvh, short horiz, short vert); +void TVScroll(TVHandle tvh, long horiz, long vert); void TVCopy(TVHandle tvh); void TVSetSelect(TVHandle tvh, unsigned long start, unsigned long end); void TVClear(TVHandle tvh);