static void view_remove_line(TEXT_BUFFER_VIEW_REC *view, LINE_REC *line, int linecount) { int realcount; view_bookmarks_check(view, line); if (view->buffer->cur_line == line) { /* the last line is being removed */ LINE_REC *prevline; prevline = view->buffer->first_line == line ? NULL : textbuffer_line_last(view->buffer); view->cache->last_linecount = prevline == NULL ? 0 : view_get_linecount(view, prevline); } if (view->buffer->first_line == line) { /* first line in the buffer - this is the most commonly removed line.. */ if (view->bottom_startline == line) { /* very small scrollback.. */ view->bottom_startline = view->bottom_startline->next; view->bottom_subline = 0; } if (view->startline == line) { /* removing the first line in screen */ int is_last = view->startline->next == NULL; realcount = view_scroll(view, &view->startline, &view->subline, linecount, FALSE); view->ypos -= realcount; view->empty_linecount += linecount-realcount; if (is_last == 1) view->startline = NULL; } } else { if (textbuffer_line_exists_after(view->bottom_startline, line)) { realcount = view_scroll(view, &view->bottom_startline, &view->bottom_subline, -linecount, FALSE); view->empty_linecount += linecount-realcount; } if (textbuffer_line_exists_after(view->startline, line)) { view_remove_line_update_startline(view, line, linecount); } } view->bottom = view_is_bottom(view); if (view->bottom) view->more_text = FALSE; if (view->window != NULL) term_refresh(view->window); }
/* Set a bookmark in view to the bottom line */ void textbuffer_view_set_bookmark_bottom(TEXT_BUFFER_VIEW_REC *view, const char *name) { LINE_REC *line; g_return_if_fail(view != NULL); g_return_if_fail(name != NULL); if (view->bottom_startline != NULL) { line = textbuffer_line_last(view->buffer); textbuffer_view_set_bookmark(view, name, line); } }
/* Clear the view, don't actually remove any lines from buffer. */ void textbuffer_view_clear(TEXT_BUFFER_VIEW_REC *view) { g_return_if_fail(view != NULL); view->ypos = -1; view->bottom_startline = view->startline = textbuffer_line_last(view->buffer); view->bottom_subline = view->subline = view->buffer->cur_line == NULL ? 0 : view_get_linecount(view, view->buffer->cur_line); view->empty_linecount = view->height; view->bottom = TRUE; view->more_text = FALSE; textbuffer_view_redraw(view); }
/* Recalculate view's bottom line information - try to keep the original if possible */ static void textbuffer_view_init_bottom(TEXT_BUFFER_VIEW_REC *view) { LINE_REC *line; int linecount, total; if (view->empty_linecount == 0) { /* no empty lines in screen, no need to try to keep the old bottom startline */ view->bottom_startline = NULL; } total = 0; line = textbuffer_line_last(view->buffer); for (; line != NULL; line = line->prev) { linecount = view_get_linecount(view, line); if (line == view->bottom_startline) { /* keep the old one, make sure that subline is ok */ if (view->bottom_subline > linecount) view->bottom_subline = linecount; view->empty_linecount = view->height - total - (linecount-view->bottom_subline); return; } total += linecount; if (total >= view->height) { view->bottom_startline = line; view->bottom_subline = total - view->height; view->empty_linecount = 0; return; } } /* not enough lines so we must be at the beginning of the buffer */ view->bottom_startline = view->buffer->first_line; view->bottom_subline = 0; view->empty_linecount = view->height - total; }