linter: make sure that the margin is updated before displaying a buffer

This fixes https://savannah.gnu.org/bugs/?53977.
Reported-by: Marco Diego Aurélio Mesquita <marcodiegomesquita@gmail.com>
This commit is contained in:
Benno Schulenberg 2018-05-25 17:57:04 +02:00
parent 119a6f0de3
commit 86c08560ad
3 changed files with 31 additions and 17 deletions

View File

@ -1541,6 +1541,30 @@ int get_keycode(const char *keyname, const int standard)
return standard;
}
#ifdef ENABLE_LINENUMBERS
/* Ensure that the margin can accomodate the buffer's highest line number. */
void check_margin(void)
{
int needed_margin = digits(openfile->filebot->lineno) + 1;
/* When not requested or space is too tight, suppress line numbers. */
if (!ISSET(LINE_NUMBERS) || needed_margin > COLS - 4)
needed_margin = 0;
if (needed_margin != margin) {
margin = needed_margin;
editwincols = COLS - margin;
#ifndef NANO_TINY
/* Ensure that firstcolumn is the starting column of its chunk. */
ensure_firstcolumn_is_aligned();
#endif
/* The margin has changed -- schedule a full refresh. */
refresh_needed = TRUE;
}
}
#endif /* ENABLE_LINENUMBERS */
/* Say that an unbound key was struck, and if possible which one. */
void unbound_key(int code)
{
@ -2643,23 +2667,7 @@ int main(int argc, char **argv)
while (TRUE) {
#ifdef ENABLE_LINENUMBERS
int needed_margin = digits(openfile->filebot->lineno) + 1;
/* Suppress line numbers when there is not enough room for them. */
if (!ISSET(LINE_NUMBERS) || needed_margin > COLS - 4)
needed_margin = 0;
if (needed_margin != margin) {
margin = needed_margin;
editwincols = COLS - margin;
#ifndef NANO_TINY
/* Ensure that firstcolumn is the starting column of its chunk. */
ensure_firstcolumn_is_aligned();
#endif
/* The margin has changed -- schedule a full refresh. */
refresh_needed = TRUE;
}
check_margin();
#endif
if (currmenu != MMAIN)
display_main_list();

View File

@ -442,6 +442,9 @@ void enable_signals(void);
void disable_flow_control(void);
void enable_flow_control(void);
void terminal_init(void);
#ifdef ENABLE_LINENUMBERS
void check_margin(void);
#endif
void unbound_key(int code);
bool okay_for_view(const sc *shortcut);
int do_input(bool allow_funcs);

View File

@ -3335,6 +3335,9 @@ void do_linter(void)
goto_line_posx(curlint->lineno, curlint->colno - 1);
titlebar(NULL);
adjust_viewport(CENTERING);
#ifdef ENABLE_LINENUMBERS
check_margin();
#endif
edit_refresh();
statusbar(curlint->msg);
bottombars(MLINTER);