jcs
/textview
/amendments
/31
Fix scrolling since we're no longer tracking top and bottom lines
jcs made amendment 31 over 2 years ago
--- textview.c Mon Oct 21 22:14:53 2024
+++ textview.c Mon Oct 21 22:53:52 2024
@@ -423,7 +423,7 @@ TVTrackScrollControl(ControlHandle control, short part
{
struct TVRec *tv;
struct TVChunk *chunk, *top_chunk = NULL;
- struct TVLine *line, *oline;
+ struct TVLine *line, *oline, *top_line, *bottom_line;
KeyMap km;
long n, top;
unsigned short nline;
@@ -442,6 +442,37 @@ TVTrackScrollControl(ControlHandle control, short part
GetKeys(&km);
cmd_down = (km[1] & (1 << 15)) != 0;
+ top_line = NULL;
+ bottom_line = NULL;
+ 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;
+
+ if (tv->scrolled.top + line->rect.top >= tv->view_height)
+ /* is further down than the view, we've done enough lines */
+ break;
+
+ if (top_line == NULL)
+ top_line = line;
+
+ bottom_line = line;
+ }
+ if (top_line == NULL) {
+ top_line = TVGetLine(tv, nline);
+ if (top_line == NULL)
+ return;
+ }
+ if (bottom_line == NULL) {
+ bottom_line = TVGetLine(tv, tv->nlines);
+ if (bottom_line == NULL)
+ return;
+ }
+
switch (part) {
case inUpButton:
if (cmd_down) {
@@ -450,14 +481,12 @@ TVTrackScrollControl(ControlHandle control, short part
}
/* scroll to the line before the top-most line */
- if (tv->top_line > 1) {
- line = TVGetLine(tv, tv->top_line);
- if (line == NULL)
- break;
- oline = TVGetLine(tv, tv->top_line - 1);
+ if (top_line->nline > 1) {
+ oline = TVGetLine(tv, top_line->nline - 1);
if (oline == NULL)
break;
- TVScrollUnlocked(tv, 0, line->rect.top - oline->rect.top + 1);
+ TVScrollUnlocked(tv, 0, top_line->rect.top -
+ oline->rect.top + 1);
break;
}
@@ -466,17 +495,8 @@ TVTrackScrollControl(ControlHandle control, short part
break;
case inPageUp:
/* scroll to put the top mostly-visible line at the bottom */
- if (tv->top_line) {
- line = TVGetLine(tv, tv->top_line);
- if (line == NULL)
- break;
- TVScrollUnlocked(tv, 0, tv->view_height -
- (tv->scrolled.top + line->rect.bottom) - 1);
- break;
- }
-
- /* nothing found, just scroll to the top */
- TVScrollUnlocked(tv, 0, -(tv->scrolled.top));
+ TVScrollUnlocked(tv, 0, tv->view_height -
+ (tv->scrolled.top + top_line->rect.bottom) - 1);
break;
case inDownButton:
if (cmd_down) {
@@ -485,8 +505,8 @@ TVTrackScrollControl(ControlHandle control, short part
}
/* scroll to the line after the bottom-most line */
- if (tv->bottom_line < tv->nlines) {
- line = TVGetLine(tv, tv->bottom_line + 1);
+ if (bottom_line->nline < tv->nlines) {
+ line = TVGetLine(tv, bottom_line->nline + 1);
TVScrollUnlocked(tv, 0,
-(tv->scrolled.top - tv->view_height + line->rect.bottom));
break;
@@ -497,8 +517,8 @@ TVTrackScrollControl(ControlHandle control, short part
break;
case inPageDown:
/* scroll to put the bottom mostly-visible line at the top */
- if (tv->bottom_line < tv->nlines) {
- line = TVGetLine(tv, tv->bottom_line + 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) +
--- textview.h Mon Oct 21 20:18:31 2024
+++ textview.h Mon Oct 21 22:32:54 2024
@@ -117,8 +117,6 @@ struct TVRec {
#define TV_LINE_GROUP_NLINES 1000
#define TV_LINE_GROUP_SIZE (sizeof(struct TVLine) * TV_LINE_GROUP_NLINES)
unsigned short nlines;
- unsigned short top_line;
- unsigned short bottom_line;
char unlock_refcnt;
Boolean autoscroll;