display: for a large paste or insertion, recalculate the multiline cache

When a large piece of text or code is pasted or inserted, it could
contain matches for start= and end= regexes, and backtracking from
the current screen could mistake an end for a start and could thus
miscolor things.  Avoid this by recalculating the multiline cache
for pastes and insertions that cover more than a screenful.

This fixes https://savannah.gnu.org/bugs/?59982.

Bug existed since version 2.6.0, but existed also before 2.4.3.
master
Benno Schulenberg 2021-02-03 16:27:51 +01:00
parent 5ea930e25f
commit 1fdd23d347
3 changed files with 11 additions and 3 deletions

View File

@ -289,8 +289,7 @@ void precalc_multicolorinfo(void)
regmatch_t startmatch, endmatch;
linestruct *line, *tailline;
if (openfile->syntax == NULL || openfile->syntax->nmultis == 0 ||
openfile->filetop->multidata || ISSET(NO_SYNTAX))
if (!openfile->syntax || openfile->syntax->nmultis == 0 || ISSET(NO_SYNTAX))
return;
//#define TIMEPRECALC 123

View File

@ -734,6 +734,10 @@ void paste_text(void)
/* If we pasted less than a screenful, don't center the cursor. */
if (less_than_a_screenful(was_lineno, was_leftedge))
focusing = FALSE;
#ifdef ENABLE_COLOR
else
precalc_multicolorinfo();
#endif
/* Set the desired x position to where the pasted text ends. */
openfile->placewewant = xplustabs();

View File

@ -498,6 +498,7 @@ void prepare_for_display(void)
#ifdef ENABLE_COLOR
/* Precalculate the data for any multiline coloring regexes. */
if (!openfile->filetop->multidata)
precalc_multicolorinfo();
have_palette = FALSE;
#endif
@ -818,6 +819,10 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable)
/* If we inserted less than a screenful, don't center the cursor. */
if (undoable && less_than_a_screenful(was_lineno, was_leftedge))
focusing = FALSE;
#ifdef ENABLE_COLOR
else if (undoable)
precalc_multicolorinfo();
#endif
#ifndef NANO_TINY
if (undoable)