diff --git a/docs/protocol-extensions.rst b/docs/protocol-extensions.rst index 8f89404a1..cdb9ad003 100644 --- a/docs/protocol-extensions.rst +++ b/docs/protocol-extensions.rst @@ -179,9 +179,7 @@ screen. This escape code allows that text to be restored. If the scrollback buffer is empty or there is no scrollback buffer, such as for the alternate screen, then the newly inserted lines must be empty, just as with the original ``SD`` escape code. The maximum number of lines that can be -scrolled down is the height of the screen, i.e. the number of lines on the screen. -If the escape code requests more than that number of lines, the terminal *must* -clip the request to the current screen size. +scrolled down is implementation defined, but must be at least one screen worth. The syntax of the escape code is identical to that of ``SD`` except that it has a trailing ``+`` modifier. This is legal under the `ECMA 48 standard diff --git a/kitty/screen.c b/kitty/screen.c index 536546aab..4aa868a47 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1140,9 +1140,12 @@ screen_reverse_index(Screen *self) { static void _reverse_scroll(Screen *self, unsigned int count, bool fill_from_scrollback) { // Scroll the screen down by count lines, not moving the cursor - count = MIN(self->lines, count); unsigned int top = self->margin_top, bottom = self->margin_bottom; fill_from_scrollback = fill_from_scrollback && self->linebuf == self->main_linebuf; + if (fill_from_scrollback) { + unsigned limit = MAX(self->lines, self->historybuf->count); + count = MIN(limit, count); + } else count = MIN(self->lines, count); while (count-- > 0) { bool copied = false; if (fill_from_scrollback) copied = historybuf_pop_line(self->historybuf, self->alt_linebuf->line);