handle case where cursor is past where content is on col shrink

This commit is contained in:
Mitchell Hashimoto
2022-08-08 14:08:01 -07:00
parent 9493561159
commit f3d3d255fb

View File

@ -689,14 +689,6 @@ pub fn resize(self: *Screen, alloc: Allocator, rows: usize, cols: usize) !void {
i -= 1; i -= 1;
} }
// If our cursor was past the end of this line, move it
// to the end of the contentful area.
if (cursor_pos.y == iter.value - 1 and
cursor_pos.x >= i)
{
cursor_pos.x = i - 1;
}
break :trim row[0..i]; break :trim row[0..i];
}; };
@ -734,6 +726,18 @@ pub fn resize(self: *Screen, alloc: Allocator, rows: usize, cols: usize) !void {
x += 1; x += 1;
} }
// If our cursor is on this line but not in a content area,
// then we just set it to be at the end.
if (cursor_pos.y == iter.value - 1 and
cursor_pos.x >= trimmed_row.len)
{
assert(new_cursor == null);
new_cursor = .{
.x = @minimum(cursor_pos.x, self.cols - 1),
.y = y,
};
}
// If we aren't wrapping, then move to the next row // If we aren't wrapping, then move to the next row
if (trimmed_row.len == 0 or if (trimmed_row.len == 0 or
trimmed_row[trimmed_row.len - 1].attrs.wrap == 0) trimmed_row[trimmed_row.len - 1].attrs.wrap == 0)