fix: Surface.selectionString should return sentinel slice

The underlying API call returns a sentinel slice so selectionString
should do the same or there are problems later trying to free the
allocated memory.
This commit is contained in:
Jeffrey C. Ollie
2024-09-10 17:22:29 -05:00
parent 67abd8804e
commit f1473a1464

View File

@ -932,7 +932,7 @@ pub fn hasSelection(self: *const Surface) bool {
} }
/// Returns the selected text. This is allocated. /// Returns the selected text. This is allocated.
pub fn selectionString(self: *Surface, alloc: Allocator) !?[]const u8 { pub fn selectionString(self: *Surface, alloc: Allocator) !?[:0]const u8 {
self.renderer_state.mutex.lock(); self.renderer_state.mutex.lock();
defer self.renderer_state.mutex.unlock(); defer self.renderer_state.mutex.unlock();
const sel = self.io.terminal.screen.selection orelse return null; const sel = self.io.terminal.screen.selection orelse return null;