diff --git a/src/nano.c b/src/nano.c index 8944909d..b96b1dad 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2554,8 +2554,6 @@ int main(int argc, char **argv) * dimensions. */ window_init(); - editwincols = COLS - margin; - /* Set up the signal handlers. */ signal_init(); @@ -2694,6 +2692,22 @@ int main(int argc, char **argv) display_buffer(); while (TRUE) { +#ifdef ENABLE_LINENUMBERS + int needed_margin = digits(openfile->filebot->lineno) + 1; + + /* Only enable line numbers when there is enough room for them. */ + if (ISSET(LINE_NUMBERS) && needed_margin < COLS - 3) { + if (needed_margin != margin) { + margin = needed_margin; + editwincols = COLS - margin; + /* The margin has changed -- schedule a full refresh. */ + refresh_needed = TRUE; + } + } else { + margin = 0; + editwincols = COLS; + } +#endif if (currmenu != MMAIN) display_main_list(); diff --git a/src/winio.c b/src/winio.c index 61681f4e..381e114a 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2269,26 +2269,15 @@ void edit_draw(filestruct *fileptr, const char *converted, int assert(strlenpt(converted) <= editwincols); #ifdef ENABLE_LINENUMBERS - int needed_margin = digits(openfile->filebot->lineno) + 1; - - if (ISSET(LINE_NUMBERS) && needed_margin < COLS - 3) { - /* If the line numbers now require more room, schedule a refresh. */ - if (needed_margin != margin) { - margin = needed_margin; - editwincols = COLS - margin; - refresh_needed = TRUE; - } - - /* Show the line number only for the non-softwrapped parts. */ + /* If line numbering is switched on, show a line number in front of + * the text -- but only for the parts that are not softwrapped. */ + if (margin > 0) { wattron(edit, interface_color_pair[LINE_NUMBER]); if (last_drawn_line != fileptr->lineno || last_line_y >= line) mvwprintw(edit, line, 0, "%*i", margin - 1, fileptr->lineno); else mvwprintw(edit, line, 0, "%*s", margin - 1, " "); wattroff(edit, interface_color_pair[LINE_NUMBER]); - } else { - margin = 0; - editwincols = COLS; } #endif