commit 77dd24f44c127286214d10f3059827f1453f0783 from: Omar Polo date: Mon Jul 05 17:27:20 2021 UTC fix top_line/current_line wrt L_HIDDEN this fixes some infinite loops that may happen if the first line is hidden, or things happens. The idea is to move the line forward/backward until a non-hidden one is found. commit - 60e8771930c10a9d8820102108342f0a53eda424 commit + 77dd24f44c127286214d10f3059827f1453f0783 blob - ccedaa8e62420b77214b4475aff8f6ef22da0464 blob + e8aa4f0a5a8bb9205f2f9116ec2fb1d8059df8f6 --- ui.c +++ ui.c @@ -782,7 +782,38 @@ redraw_tabline(void) mvwprintw(tabline, 0, COLS-1, ">"); wattr_off(tabline, tab_face.background, NULL); } + +/* + * Compute the first visible line around vl. Try to search forward + * until the end of the buffer; if a visible line is not found, search + * backward. Return NULL if no viable line was found. + */ +static inline struct vline * +adjust_line(struct vline *vl, struct buffer *buffer) +{ + struct vline *t; + if (!(vl->parent->flags & L_HIDDEN)) + return vl; + + /* search forward */ + for (t = vl; + t != NULL && t->parent->flags & L_HIDDEN; + t = TAILQ_NEXT(t, vlines)) + ; /* nop */ + + if (t != NULL) + return t; + + /* search backward */ + for (t = vl; + t != NULL && t->parent->flags & L_HIDDEN; + t = TAILQ_PREV(t, vhead, vlines)) + ; /* nop */ + + return t; +} + static void redraw_window(WINDOW *win, int height, int width, struct buffer *buffer) { @@ -804,8 +835,14 @@ again: buffer->curs_y = 0; if (TAILQ_EMPTY(&buffer->head)) + goto end; + + buffer->top_line = adjust_line(buffer->top_line, buffer); + if (buffer->top_line == NULL) goto end; + buffer->current_line = adjust_line(buffer->current_line, buffer); + l = 0; onscreen = 0; for (vl = buffer->top_line; vl != NULL; vl = TAILQ_NEXT(vl, vlines)) {