From 4fae29ff13b64dc22aee3c97a3a8ee449d7f3301 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 14 Dec 2022 21:43:47 -0800 Subject: [PATCH] terminal: scrollRegionUp outside of range does nothing --- src/terminal/Screen.zig | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index c9e2f61f5..c6e4020cf 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -940,7 +940,10 @@ pub fn scrollRegionUp(self: *Screen, top: RowIndex, bottom: RowIndex, count: usi // in the entire screen buffer. const top_y = top.toScreen(self).screen; const bot_y = bottom.toScreen(self).screen; - assert(bot_y > top_y); + + // If top is outside of the range of bot, we do nothing. + if (top_y >= bot_y) return; + assert(count <= (bot_y - top_y)); // Get the storage pointer for the full scroll region. We're going to @@ -2982,6 +2985,23 @@ test "Screen: scrollRegionUp single" { } } +test "Screen: scrollRegionUp same line" { + const testing = std.testing; + const alloc = testing.allocator; + + var s = try init(alloc, 4, 5, 0); + defer s.deinit(); + try s.testWriteString("1ABCD\n2EFGH\n3IJKL\n4ABCD"); + + s.scrollRegionUp(.{ .active = 1 }, .{ .active = 1 }, 1); + { + // Test our contents rotated + var contents = try s.testString(alloc, .screen); + defer alloc.free(contents); + try testing.expectEqualStrings("1ABCD\n2EFGH\n3IJKL\n4ABCD", contents); + } +} + test "Screen: scrollRegionUp single with pen" { const testing = std.testing; const alloc = testing.allocator;