From 47c884da536bc03e18521a95f9f164dce927f147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 4 Oct 2020 19:11:40 +0200 Subject: [PATCH] =?UTF-8?q?sixel:=20scroll-up:=20don=E2=80=99t=20break=20o?= =?UTF-8?q?ut=20early=20of=20loop?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function loops the list of sixels, and discards those that would be scrolled out if the grid offset is moved forward by the specified number of rows. The criteria is when the rebased row value is less than the number of rows to scroll. A rebased row number is a zero-based number starting at the beginning of the scrollback. Thus, when scrolling 5 rows, rows with a rebased row number between 0-4 will be scrolled out. For performance reasons, we used to break out of the loop as soon as a row number *larger* than the scroll count. This however does not work. The sixels are sorted by their *end* row. While this works in most cases (think images outputted in the shell in the normal screen), it doesn’t always. In the alt screen, where applications can print images just about anywhere, it is possible to have *any* start row number anywhere in the sixel list. Just as long as their *end* row numbers are sorted. For example, a huuuge sixel that covers the entire scrollback. This sixel will naturally be first in the list (and thus sixel_scroll_up() will visit it *last*, since it iterates the list in reverse), but should still be destroyed when scrolling. --- sixel.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/sixel.c b/sixel.c index 07b16031..e584d677 100644 --- a/sixel.c +++ b/sixel.c @@ -246,11 +246,21 @@ sixel_scroll_up(struct terminal *term, int rows) struct sixel *six = &it->item; int six_start = rebase_row(term, six->pos.row); + if (six_start < rows) { sixel_erase(term, six); tll_remove(term->grid->sixel_images, it); - } else - break; + } else { + /* + * Unfortunately, we cannot break here. + * + * The sixels are sorted on their *end* row. This means + * there may be a sixel with a top row that will be + * scrolled out *anywhere* in the list (think of a huuuuge + * sixel that covers the entire scrollback) + */ + //break; + } } verify_sixels(term);