drop a couple function calls and optimize scrolling a bit

This commit is contained in:
Mitchell Hashimoto
2022-11-08 18:35:19 -08:00
parent 306ab947e7
commit a471eaf980
2 changed files with 13 additions and 9 deletions

View File

@ -861,6 +861,9 @@ pub fn copyRow(self: *Screen, dst: RowIndex, src: RowIndex) !void {
///
/// This can be used to implement terminal scroll regions efficiently.
pub fn scrollRegionUp(self: *Screen, top: RowIndex, bottom: RowIndex, count: usize) void {
const tracy = trace(@src());
defer tracy.end();
// Avoid a lot of work if we're doing nothing.
if (count == 0) return;

View File

@ -732,8 +732,11 @@ pub fn index(self: *Terminal) !void {
{
try self.screen.scroll(.{ .delta = 1 });
} else {
// TODO: test
try self.scrollUp(1);
self.screen.scrollRegionUp(
.{ .active = self.scrolling_region.top },
.{ .active = self.scrolling_region.bottom },
1,
);
}
return;
@ -1251,13 +1254,11 @@ pub fn scrollDown(self: *Terminal, count: usize) !void {
/// Does not change the (absolute) cursor position.
// TODO: test
pub fn scrollUp(self: *Terminal, count: usize) !void {
// Preserve the cursor
const cursor = self.screen.cursor;
defer self.screen.cursor = cursor;
// Move to the top of the scroll region
self.screen.cursor.y = self.scrolling_region.top;
try self.deleteLines(count);
self.screen.scrollRegionUp(
.{ .active = self.scrolling_region.top },
.{ .active = self.scrolling_region.bottom },
count,
);
}
/// Options for scrolling the viewport of the terminal grid.