commit f9560742eabf2ce27a6204047984be113db92642 from: Omar Polo date: Sun Jun 20 14:22:58 2021 UTC disentangle cmd_scroll_line_up/down and ncurses cmd_scroll_line_up and down are the fundamental functions called every time there's a need to scroll the window. cmd_scroll_up/down calls them in a loop, cmd_next_line and cmd_previous_line calls them too. And so on. These two functions, historically predates some of the abstractions of the `struct buffer', and handle ncurses directly using wscrl and print_line. However, since dispatch_stdio calls redraw_tab anyway, there's no need to update the window content here. (Well, wscrl + one print_vline *may* be a bit faster than the loop over print_vline in redraw_window, but we can optimise the latter later.) This also (should) dis-entangle the cmd_* functions and ncurses completely \o/ commit - 676794769a5aafd21ed8d1136dc98c42a538ae96 commit + f9560742eabf2ce27a6204047984be113db92642 blob - d374bf181856428c29126bd1ae89cb9dc7e699dd blob + dd9149bc39d552f9f124461aee85788c9ef010ad --- ui.c +++ ui.c @@ -449,15 +449,14 @@ cmd_scroll_line_up(struct buffer *buffer) { struct vline *vl; - if (buffer->line_off == 0) + if (buffer->current_line == NULL) return; - vl = nth_line(buffer, --buffer->line_off); - wscrl(body, -1); - wmove(body, 0, 0); - print_vline(body, vl); + if ((vl = TAILQ_PREV(buffer->current_line, vhead, vlines)) == NULL) + return; - buffer->current_line = TAILQ_PREV(buffer->current_line, vhead, vlines); + buffer->current_line = vl; + buffer->line_off--; restore_cursor(buffer); } @@ -466,21 +465,14 @@ cmd_scroll_line_down(struct buffer *buffer) { struct vline *vl; - vl = buffer->current_line; - if ((vl = TAILQ_NEXT(vl, vlines)) == NULL) - return; - buffer->current_line = vl; + if (buffer->current_line == NULL) + return; - buffer->line_off++; - wscrl(body, 1); - - if (buffer->line_max - buffer->line_off < (size_t)body_lines) + if ((vl = TAILQ_NEXT(buffer->current_line, vlines)) == NULL) return; - vl = nth_line(buffer, buffer->line_off + body_lines-1); - wmove(body, body_lines-1, 0); - print_vline(body, vl); - + buffer->current_line = vl; + buffer->line_off++; restore_cursor(buffer); }