diff --git a/src/fe-text/textbuffer-view.c b/src/fe-text/textbuffer-view.c index 45035fa8..a9c2c01d 100644 --- a/src/fe-text/textbuffer-view.c +++ b/src/fe-text/textbuffer-view.c @@ -1171,26 +1171,83 @@ static void view_remove_line_update_startline(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, int linecount) { int scroll; + GString *line_text; + + line_text = g_string_new(NULL); + + if (view->startline != NULL) + textbuffer_line2text(view->startline, FALSE, line_text); + + fprintf(stderr, "view_remove_line_update_startline\n" + ".. height: %d\n" + ".. ypos: %d\n" + ".. subline: %d\n" + "..empty_linecount: %d\n" + ".. startline: %s\n", + view->height, view->ypos, view->subline, view->empty_linecount, line_text->str); + g_string_truncate(line_text, 0); + if (line != NULL) + textbuffer_line2text(line, FALSE, line_text); + fprintf(stderr, + ".. line: %s\n", line_text->str); + g_string_truncate(line_text, 0); if (view->startline == line) { view->startline = view->startline->prev != NULL ? view->startline->prev : view->startline->next; view->subline = 0; + + if (view->startline != NULL) + textbuffer_line2text(view->startline, FALSE, line_text); + fprintf(stderr, "... moving startline ...\n" + ".. subline: %d\n" + ".. startline: %s\n", + view->subline, line_text->str); + g_string_truncate(line_text, 0); } else { scroll = view->height - view_get_lines_height(view, view->startline, view->subline, line); - if (scroll > 0) { + fprintf(stderr, "... other line ...\n" + ".. scroll: %d\n", + scroll); + if (view->empty_linecount > 0) { + view->empty_linecount += scroll; + if (view->empty_linecount < 0) + view->empty_linecount = 0; + else if (view->empty_linecount > view->height) + view->empty_linecount = view->height; + fprintf(stderr, "... changing empty_linecount ...\n" + "..empty_linecount: %d\n", + view->empty_linecount); + } else if (scroll > 0) { view_scroll(view, &view->startline, &view->subline, -scroll, FALSE); + textbuffer_line2text(view->startline, FALSE, line_text); + fprintf(stderr, "... scrolling ...\n" + ".. subline: %d\n" + ".. startline: %s\n", + view->subline, line_text->str); + g_string_truncate(line_text, 0); } } + fprintf(stderr, + ".. linecount: %d\n", + linecount); /* FIXME: this is slow and unnecessary, but it's easy and really works :) */ textbuffer_view_init_ypos(view); - if (textbuffer_line_exists_after(view->startline, line)) + fprintf(stderr, "... init_ypos ...\n" + ".. ypos: %d\n", + view->ypos); + if (view->empty_linecount == 0 && textbuffer_line_exists_after(view->startline, line)) { view->ypos -= linecount; + fprintf(stderr, "... moving ypos by linecount ...\n" + ".. ypos: %d\n", + view->ypos); + } + fprintf(stderr, "\n"); } static void view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, @@ -1242,7 +1299,9 @@ static void view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, realcount = view_scroll(view, &view->bottom_startline, &view->bottom_subline, -linecount, FALSE); + fprintf(stderr, "adjusting empty_linecount [ %d -> ", view->empty_linecount); view->empty_linecount += linecount-realcount; + fprintf(stderr, "%d , linecount: %d, realcount: %d ]\n", view->empty_linecount, linecount, realcount); } if (view->bottom_startline == line) { @@ -1298,17 +1357,17 @@ void textbuffer_view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line) void textbuffer_view_remove_lines_by_level(TEXT_BUFFER_VIEW_REC *view, int level) { - LINE_REC *line, *next; + LINE_REC *line, *prev; term_refresh_freeze(); - line = textbuffer_view_get_lines(view); + line = textbuffer_line_last(view->buffer); while (line != NULL) { - next = line->next; + prev = line->prev; if (line->info.level & level) textbuffer_view_remove_line(view, line); - line = next; + line = prev; } textbuffer_view_redraw(view); term_refresh_thaw();