mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
fix(terminal): proper style cleanup in cursorCopy
Old implementation sometimes resulted in an attempt to free the style from a different page than it originates. This way is also generally cleaner.
This commit is contained in:
@ -78,7 +78,7 @@ pub const Dirty = packed struct {
|
|||||||
hyperlink_hover: bool = false,
|
hyperlink_hover: bool = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The cursor position.
|
/// The cursor position and style.
|
||||||
pub const Cursor = struct {
|
pub const Cursor = struct {
|
||||||
// The x/y position within the viewport.
|
// The x/y position within the viewport.
|
||||||
x: size.CellCountInt,
|
x: size.CellCountInt,
|
||||||
@ -761,26 +761,23 @@ pub fn cursorCopy(self: *Screen, other: Cursor) !void {
|
|||||||
self.cursor = other;
|
self.cursor = other;
|
||||||
errdefer self.cursor = old;
|
errdefer self.cursor = old;
|
||||||
|
|
||||||
// Clear our style information initially so runtime safety integrity
|
// Keep our old style ID so it can be properly cleaned up below.
|
||||||
// checks pass since there is a period below where the cursor is
|
self.cursor.style_id = old.style_id;
|
||||||
// invalid.
|
|
||||||
self.cursor.style = .{};
|
|
||||||
self.cursor.style_id = 0;
|
|
||||||
|
|
||||||
// We need to keep our old x/y because that is our cursorAbsolute
|
// Keep our old page pin and X/Y because:
|
||||||
// will fix up our pointers.
|
// 1. The old style will need to be cleaned up from the page it's from.
|
||||||
//
|
// 2. The new position navigated to by `cursorAbsolute` needs to be in our
|
||||||
// We keep our old page pin because we expect to be in the active
|
// own screen.
|
||||||
// page relative to our own screen.
|
|
||||||
self.cursor.page_pin = old.page_pin;
|
self.cursor.page_pin = old.page_pin;
|
||||||
self.cursor.x = old.x;
|
self.cursor.x = old.x;
|
||||||
self.cursor.y = old.y;
|
self.cursor.y = old.y;
|
||||||
self.cursorAbsolute(other.x, other.y);
|
|
||||||
|
|
||||||
// We keep the old style ref so manualStyleUpdate can clean our old style up.
|
// Call manual style update in order to clean up our old style, if we have
|
||||||
self.cursor.style = other.style;
|
// one, and also to load the style from the other cursor, if it had one.
|
||||||
self.cursor.style_id = old.style_id;
|
|
||||||
try self.manualStyleUpdate();
|
try self.manualStyleUpdate();
|
||||||
|
|
||||||
|
// Move to the correct location to match the other cursor.
|
||||||
|
self.cursorAbsolute(other.x, other.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Always use this to write to cursor.page_pin.*.
|
/// Always use this to write to cursor.page_pin.*.
|
||||||
|
Reference in New Issue
Block a user