screen: move the margin determination to the main loop

There is no need to look at this for every painted line, because
the margin can only change when some key is struck.
master
Benno Schulenberg 2016-10-21 14:31:37 +02:00
parent 2789bb0813
commit 023edffe3d
2 changed files with 19 additions and 16 deletions

View File

@ -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();

View File

@ -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