diff --git a/src/help.c b/src/help.c index e243597..92e41ce 100644 --- a/src/help.c +++ b/src/help.c @@ -60,12 +60,19 @@ void do_help(void) FILE *fp; char *tempfilename = NULL; const char *ptr; + const char *beg_of_para; + /* The point in the help text where the introductory paragraphs + * begin. */ int line_size; + int top_lineno; int saved_margin = 0; /* For avoiding the line numbers on the help screen. */ char *saved_answer = answer != NULL ? strdup(answer) : NULL; /* In case user chooses help at prompt, save the string entered, * if any, by the user at the prompt. */ + bool window_below_74 = FALSE; + /* Gives help text the original look when window is resized to + * something more than 74 characters from anything below 74. */ blank_statusbar(); @@ -92,6 +99,8 @@ void do_help(void) while (*ptr == '\n') ++ptr; + beg_of_para = ptr; + /* Wrap and copy the rest of the help text into the temporary file. */ while (strlen(ptr) > 0) { line_size = help_line_len(ptr); @@ -145,6 +154,47 @@ void do_help(void) #ifndef NANO_TINY if (kbinput == KEY_WINCH) { kbinput = ERR; + + /* Rewrap and recopy the help text into the temporary file. */ + if (COLS < 74 || window_below_74) { + window_below_74 = TRUE; + top_lineno = openfile->edittop->lineno; + close_buffer(); + ptr = beg_of_para; + fp = fopen(tempfilename, "w"); + + while (strlen(ptr) > 0) { + line_size = help_line_len(ptr); + fwrite(ptr, sizeof(char), line_size, fp); + ptr += line_size; + + /* Hard-wrap every line of the paragraphs. */ + if (ptr < end_of_intro && *ptr != '\n') + fwrite("\n", sizeof(char), 1, fp); + + while (*ptr == '\n') + fwrite(ptr++, sizeof(char), 1, fp); + } + fclose(fp); + + if (!ISSET(MULTIBUFFER)) { + SET(MULTIBUFFER); + open_buffer(tempfilename, FALSE); + UNSET(MULTIBUFFER); + } else + open_buffer(tempfilename, FALSE); + + display_buffer(); + + /* Stay at the current line or, at least, close to it. */ + if (openfile->current->lineno < top_lineno) + while (openfile->current->lineno < top_lineno) + do_down(FALSE); + else + while (openfile->current->lineno > top_lineno) + do_up(FALSE); + } + continue; /* Redraw the screen. */ } #endif