diff --git a/src/help.c b/src/help.c index 9245805..feb1976 100644 --- a/src/help.c +++ b/src/help.c @@ -44,6 +44,28 @@ char *tempfilename = NULL; /* Name of the safe temporary file that we will use for wrapping * and writing the help text. */ +/* Return the maximum length at which help text is wrapped. */ +int max_wrapping_len() +{ + int max = 0; + int len; + const char *ptr = beg_of_intro; + + while (strlen(ptr) > 0) { + len = help_line_len(ptr); + + if (max < len) + max = len; + + while (*ptr == '\n') + ++ptr; + + ptr += len; + } + + return max; +} + /* Writes the hard wrapped help text in the temp file and displays it. */ void display_the_help_text(bool redisplaying) { @@ -51,12 +73,22 @@ void display_the_help_text(bool redisplaying) const char *ptr = beg_of_intro; /* The current line of the help text. */ FILE *fp = fopen(tempfilename, "w+b"); + static int last_wrap_len = 0; + + /* If window size has changed and there is for no need for rewrapping, + * only refresh the window contents. */ + if (redisplaying && last_wrap_len == max_wrapping_len()) { + fclose(fp); + return; + } if (fp == NULL) { statusline(ALERT, _("Error writing temp file: %s"), strerror(errno)); return; } + last_wrap_len = max_wrapping_len(); + /* Wrap and copy the rest of the help_text into the temporary file. */ while (strlen(ptr) > 0) { line_size = help_line_len(ptr); diff --git a/src/nano.c b/src/nano.c index ea6b633..9a5c168 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1352,6 +1352,9 @@ void regenerate_screen(void) * dimensions. */ window_init(); + if (inhelp) + display_the_help_text(TRUE); + /* Redraw the contents of the windows that need it. */ total_refresh(); } diff --git a/src/winio.c b/src/winio.c index 3cefb5e..54ef4df 100644 --- a/src/winio.c +++ b/src/winio.c @@ -3101,10 +3101,7 @@ void total_refresh(void) { total_redraw(); titlebar(title); - if (inhelp) - display_the_help_text(TRUE); - else - edit_refresh(); + edit_refresh(); bottombars(currmenu); }