diff --git a/src/nano.c b/src/nano.c index 4b2462c1..be0a818e 100644 --- a/src/nano.c +++ b/src/nano.c @@ -353,8 +353,11 @@ void window_init(void) delwin(topwin); delwin(edit); delwin(bottomwin); - if (scrollbarwin) + if (scrollbarwin) { + werase(scrollbarwin); + wrefresh(scrollbarwin); delwin(scrollbarwin); + } } /* If the terminal is very flat, don't set up a title bar. */ @@ -378,7 +381,7 @@ void window_init(void) toprows, 0); bottomwin = newwin(bottomrows, COLS, toprows + editwinrows, 0); /* If the terminal is too thin, don't set up a scrollbar. */ - if (ISSET(SHOW_SCROLLBAR) && COLS >= 3) + if (ISSET(SHOW_SCROLLBAR) && editwinrows >= 3 && COLS >= 3) scrollbarwin = newwin(editwinrows, 1, toprows, COLS - 1); else scrollbarwin = NULL; diff --git a/src/winio.c b/src/winio.c index 5578a856..681ec3f5 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2371,26 +2371,31 @@ void place_the_cursor(void) void draw_scrollbar(void) { int style; - int last_lineno = openfile->filebot->lineno; - int inf = (openfile->edittop->lineno * editwinrows) / (last_lineno + 1); - int sup = inf + (editwinrows * editwinrows) / (last_lineno + 1); + int height = editwinrows - 2; + int top = openfile->edittop->lineno - 1; + int nr_lines = openfile->filebot->lineno + 1; + int below = height - nr_lines + top; + if (below > 0) nr_lines += below; + if (nr_lines < height) nr_lines = height; + int inf = (top * height) / nr_lines; + int sup = inf + (height * height) / nr_lines; /* Consider that we'll have no scrollbar if window is too thin. */ if (scrollbarwin == NULL) return; - if (editwinrows >= last_lineno) { - inf = 0; - sup = last_lineno - 1; - } + if (inf == 0 && sup == height) inf = sup; - for (int current_lineno = 0; current_lineno < editwinrows; current_lineno++) { + mvwaddch(scrollbarwin, 0, 0, (top == 0 ? ' ' : '+')); + for (int current_lineno = 0; current_lineno < height; current_lineno++) { style = (current_lineno >= inf && current_lineno <= sup) ? A_REVERSE : A_REVERSE|A_DIM; wattron(scrollbarwin, style); - mvwaddch(scrollbarwin, current_lineno, 0, ' '); + mvwaddch(scrollbarwin, current_lineno + 1, 0, ' '); wattroff(scrollbarwin, style); } + mvwaddch(scrollbarwin, height + 1, 0, + (openfile->filebot->lineno > top + editwinrows ? '+' : ' ')); wrefresh(scrollbarwin); }