diff --git a/src/terminal/Screen.zig b/src/terminal/Screen.zig index fd0436b6e..7185255ec 100644 --- a/src/terminal/Screen.zig +++ b/src/terminal/Screen.zig @@ -868,8 +868,7 @@ pub fn manualStyleUpdate(self: *Screen) !void { /// is always tracked. pub fn select(self: *Screen, sel_: ?Selection) !void { const sel = sel_ orelse { - if (self.selection) |*old| old.deinit(self); - self.selection = null; + self.clearSelection(); return; }; @@ -882,6 +881,12 @@ pub fn select(self: *Screen, sel_: ?Selection) !void { self.selection = tracked_sel; } +/// Same as select(null) but can't fail. +pub fn clearSelection(self: *Screen) void { + if (self.selection) |*sel| sel.deinit(self); + self.selection = null; +} + /// Returns the raw text associated with a selection. This will unwrap /// soft-wrapped edges. The returned slice is owned by the caller and allocated /// using alloc, not the allocator associated with the screen (unless they match). diff --git a/src/terminal/Terminal.zig b/src/terminal/Terminal.zig index c4c570d38..9145517f7 100644 --- a/src/terminal/Terminal.zig +++ b/src/terminal/Terminal.zig @@ -2139,7 +2139,7 @@ pub fn alternateScreen( self.screen.charset = old.charset; // Clear our selection - self.screen.selection = null; + self.screen.clearSelection(); // Mark kitty images as dirty so they redraw self.screen.kitty_images.dirty = true; @@ -2174,7 +2174,7 @@ pub fn primaryScreen( self.active_screen = .primary; // Clear our selection - self.screen.selection = null; + self.screen.clearSelection(); // Mark kitty images as dirty so they redraw self.screen.kitty_images.dirty = true; @@ -2203,7 +2203,7 @@ pub fn fullReset(self: *Terminal) void { self.flags = .{}; self.tabstops.reset(TABSTOP_INTERVAL); self.screen.saved_cursor = null; - self.screen.selection = null; + self.screen.clearSelection(); self.screen.kitty_keyboard = .{}; self.screen.protected_mode = .off; self.scrolling_region = .{