jcs
/textview
/amendments
/78
TVTrackScrollControl: Use TVLineForY
jcs made amendment 78 about 1 month ago
--- textview.h Wed Oct 14 21:58:25 2026
+++ textview.h Wed Oct 14 23:05:18 2026
@@ -169,9 +169,6 @@ struct TVRec {
Boolean autoscroll;
Boolean linewrap;
char unlock_refcnt;
-
- struct TVLine *top_line;
- struct TVLine *bottom_line;
};
typedef struct TVRec ** TVHandle;
@@ -260,8 +257,6 @@ Boolean TVFindInRectLocked(struct TVRec *tv, BigRect *
long startline, TVFindInRectCallback callback, void *cookie);
Boolean TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch *match,
void *cookie);
-Boolean TVSetTopBottomMatch(struct TVRec *tv,
- struct TVFindInRectMatch *match, void *cookie);
void TVUseCanvas(struct TVRec *tv);
void TVRevealCanvas(struct TVRec *tv);
unsigned char TVCharAt(struct TVRec *tv, unsigned long off);
--- tv_draw.c Wed Oct 14 22:38:35 2026
+++ tv_draw.c Wed Oct 14 23:12:03 2026
@@ -79,12 +79,8 @@ pascal void
TVTrackScrollControl(ControlHandle control, short part)
{
struct TVRec *tv;
- struct TVChunk *chunk, *top_chunk = NULL;
- struct TVLine *line, *oline;
+ struct TVLine *top_line, *bottom_line, *line, *oline;
KeyMap km;
- BigRect visible;
- long n, top;
- unsigned long nline;
Boolean horiz, cmd_down;
if (tv_track_control == NULL) {
@@ -100,29 +96,13 @@ TVTrackScrollControl(ControlHandle control, short part
GetKeys(&km);
cmd_down = (km[1] & (1 << 15)) != 0;
- tv->top_line = NULL;
- tv->bottom_line = NULL;
-
- visible.top = -(tv->scrolled.top);
- visible.left = -(tv->scrolled.left);
- visible.bottom = visible.top + tv->frame.bottom;
- visible.right = visible.left + tv->frame.right;
- TVFindInRectLocked(tv, &visible, 0, TVSetTopBottomMatch, NULL);
-
- if (tv->top_line == NULL) {
- tv->top_line = TVGetLine(tv, 1);
- if (tv->top_line == NULL) {
- TVUnlock(tv);
- return;
- }
+ top_line = TVGetLine(tv, TVLineForY(tv, -(tv->scrolled.top)));
+ bottom_line = TVGetLine(tv, TVLineForY(tv, -(tv->scrolled.top) +
+ tv->frame.bottom - 1));
+ if (top_line == NULL || bottom_line == NULL) {
+ TVUnlock(tv);
+ return;
}
- if (tv->bottom_line == NULL) {
- tv->bottom_line = TVGetLine(tv, tv->nlines);
- if (tv->bottom_line == NULL) {
- TVUnlock(tv);
- return;
- }
- }
switch (part) {
case inUpButton:
@@ -132,11 +112,11 @@ TVTrackScrollControl(ControlHandle control, short part
}
/* scroll to the line before the top-most line */
- if (tv->top_line->nline > 1) {
- oline = TVGetLine(tv, tv->top_line->nline - 1);
+ if (top_line->nline > 1) {
+ oline = TVGetLine(tv, top_line->nline - 1);
if (oline == NULL)
break;
- TVScrollUnlocked(tv, 0, tv->top_line->rect.top -
+ TVScrollUnlocked(tv, 0, top_line->rect.top -
oline->rect.top + 1);
break;
}
@@ -147,7 +127,7 @@ TVTrackScrollControl(ControlHandle control, short part
case inPageUp:
/* scroll to put the top mostly-visible line at the bottom */
TVScrollUnlocked(tv, 0, (long)tv->frame.bottom -
- (tv->scrolled.top + tv->top_line->rect.bottom) - 1);
+ (tv->scrolled.top + top_line->rect.bottom) - 1);
break;
case inDownButton:
if (cmd_down) {
@@ -156,8 +136,8 @@ TVTrackScrollControl(ControlHandle control, short part
}
/* scroll to the line after the bottom-most line */
- if (tv->bottom_line->nline < tv->nlines) {
- line = TVGetLine(tv, tv->bottom_line->nline + 1);
+ if (bottom_line->nline < tv->nlines) {
+ line = TVGetLine(tv, bottom_line->nline + 1);
if (line == NULL)
break;
TVScrollUnlocked(tv, 0,
@@ -170,8 +150,8 @@ TVTrackScrollControl(ControlHandle control, short part
break;
case inPageDown:
/* scroll to put the bottom mostly-visible line at the top */
- if (tv->bottom_line->nline < tv->nlines) {
- line = TVGetLine(tv, tv->bottom_line->nline + 1);
+ if (bottom_line->nline < tv->nlines) {
+ line = TVGetLine(tv, bottom_line->nline + 1);
if (line == NULL)
break;
TVScrollUnlocked(tv, 0, -(line->rect.top + tv->scrolled.top) +
@@ -390,18 +370,6 @@ TVDrawMatch(struct TVRec *tv, struct TVFindInRectMatch
match->text_slab->base), 0, match->text_end - match->text_start);
tv->canvas_dirty = true;
- return true;
-}
-
-Boolean
-TVSetTopBottomMatch(struct TVRec *tv, struct TVFindInRectMatch *match,
- void *cookie)
-{
- if (tv->top_line == NULL)
- tv->top_line = match->line;
-
- tv->bottom_line = match->line;
-
return true;
}