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. /// This can be used to implement terminal scroll regions efficiently.
pub fn scrollRegionUp(self: *Screen, top: RowIndex, bottom: RowIndex, count: usize) void { 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. // Avoid a lot of work if we're doing nothing.
if (count == 0) return; if (count == 0) return;

View File

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