indicator: recompute the extra rows also when justifying and resizing

And when the margin changes (when line numbers are switched on or off,
or when the buffer grows or shrinks), and when a piece of text from a
different buffer with a different margin is pasted.

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

Bug existed since commit 9a9f36fc from yesterday.
master
Benno Schulenberg 2020-06-07 11:51:14 +02:00
parent 786d2221e1
commit a2b85e0c12
4 changed files with 16 additions and 13 deletions

View File

@ -381,6 +381,9 @@ void ingraft_buffer(linestruct *topline)
}
if (topline != botline) {
/* First compute the softwrapped chunks for each line in the graft. */
compute_the_extra_rows_per_line_from(topline);
/* When inserting at end-of-buffer, update the relevant pointer. */
if (line->next == NULL)
openfile->filebot = botline;

View File

@ -357,12 +357,12 @@ bool has_valid_path(const char *filename)
}
/* Compute and store how many extra rows each line needs when softwrapping. */
void compute_the_extra_rows_per_line(void)
void compute_the_extra_rows_per_line_from(linestruct *fromline)
{
#ifndef NANO_TINY
if (ISSET(SOFTWRAP))
for (linestruct *ln = openfile->filetop; ln != NULL; ln = ln->next)
ln->extrarows = extra_chunks_in(ln);
for (linestruct *line = fromline; line != NULL; line = line->next)
line->extrarows = extra_chunks_in(line);
#endif
}
@ -463,8 +463,6 @@ bool open_buffer(const char *filename, bool new_one)
openfile->placewewant = 0;
}
compute_the_extra_rows_per_line();
#ifdef ENABLE_COLOR
/* If a new buffer was opened, check whether a syntax can be applied. */
if (new_one)
@ -535,12 +533,11 @@ void redecorate_after_switch(void)
}
#ifndef NANO_TINY
/* While in a different buffer, the screen may have been resized
* or softwrap mode may have been toggled, so make sure that the
* starting column for the first row gets an appropriate value. */
/* While in a different buffer, the effective width of the screen may
* have changed, so make sure that the softwrapped chunks per line and
* the starting column for the first row get corresponding values. */
compute_the_extra_rows_per_line_from(openfile->filetop);
ensure_firstcolumn_is_aligned();
compute_the_extra_rows_per_line();
#endif
/* Update title bar and multiline info to match the current buffer. */

View File

@ -1049,6 +1049,7 @@ void regenerate_screen(void)
/* If we have an open buffer, redraw the contents of the subwindows. */
if (openfile) {
compute_the_extra_rows_per_line_from(openfile->filetop);
ensure_firstcolumn_is_aligned();
draw_all_subwindows();
}
@ -1080,7 +1081,7 @@ void do_toggle(int flag)
break;
case SOFTWRAP:
if (ISSET(SOFTWRAP))
compute_the_extra_rows_per_line();
compute_the_extra_rows_per_line_from(openfile->filetop);
else
openfile->firstcolumn = 0;
refresh_needed = TRUE;
@ -1248,7 +1249,9 @@ void confirm_margin(void)
editwincols = COLS - margin - thebar;
#ifndef NANO_TINY
/* Ensure that firstcolumn is the starting column of its chunk. */
/* Recompute the softwrapped chunks for each line in the buffer,
* and ensure a proper starting column for the first screen row. */
compute_the_extra_rows_per_line_from(openfile->filetop);
ensure_firstcolumn_is_aligned();
#endif
/* The margin has changed -- schedule a full refresh. */

View File

@ -283,7 +283,7 @@ void make_new_buffer(void);
#ifndef NANO_TINY
bool delete_lockfile(const char *lockfilename);
#endif
void compute_the_extra_rows_per_line(void);
void compute_the_extra_rows_per_line_from(linestruct *fromline);
bool open_buffer(const char *filename, bool new_buffer);
void set_modified(void);
void prepare_for_display(void);