help: keep the text at the same position when the screen is resized

However, prefer moving the starting point of the text backwards over
moving it forward, so that of the same paragraph more text is shown
instead of less.  But scroll an empty line out of view -- no text is
"lost" then.
master
Benno Schulenberg 2016-12-16 13:25:42 +01:00
parent f9fea02fc5
commit 3d62d32cbe
1 changed files with 25 additions and 3 deletions

View File

@ -39,6 +39,9 @@ const char *beg_of_intro = NULL;
/* The point in the help text where the introductory paragraphs
* begin. */
static size_t location;
/* The offset (in bytes) of the topleft of the shown help text. */
char *tempfilename = NULL;
/* Name of the safe temporary file that we will use for wrapping
* and writing the help text. */
@ -46,9 +49,8 @@ char *tempfilename = NULL;
/* Writes the hard wrapped help text in the temp file and displays it. */
void display_the_help_text(bool redisplaying)
{
int line_size;
int line_size, sum = 0;
const char *ptr = beg_of_intro;
/* The current line of the help text. */
FILE *fp = fopen(tempfilename, "w+b");
if (fp == NULL) {
@ -82,6 +84,16 @@ void display_the_help_text(bool redisplaying)
open_buffer(tempfilename, FALSE);
display_buffer();
/* Move to the position in the file where we were before. */
while (TRUE) {
sum += strlen(openfile->current->data);
if (sum > location)
break;
openfile->current = openfile->current->next;
}
openfile->edittop = openfile->current;
}
/* Our main help-viewer function. */
@ -97,6 +109,7 @@ void do_help(void)
functionptrtype func;
/* The function of the key the user typed in. */
FILE *fp;
filestruct *line;
int line_size;
int saved_margin = 0;
/* For avoiding the line numbers on the help screen. */
@ -121,6 +134,7 @@ void do_help(void)
/* Set help_text as the string to display. */
help_init();
location = 0;
assert(help_text != NULL);
@ -216,8 +230,16 @@ void do_help(void)
break;
} else
unbound_key(kbinput);
}
location = 0;
line = openfile->fileage;
/* Count how far (in bytes) edittop is into the file. */
while (line != openfile->edittop) {
location += strlen(line->data);
line = line->next;
}
}
/* We're exiting from the help screen. So, restore the flags and the
* original menu, refresh the entire screen and deallocate the memory. */