From 1e5560cc093a0b2486a2221ad3615024401bb16f Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 12 Mar 2024 07:35:35 -0500 Subject: [PATCH] textinput: add clear methods Add clear methods to reset the underlying GapBuffer and reset cursor positions Signed-off-by: Tim Culverhouse --- src/widgets/TextInput.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/widgets/TextInput.zig b/src/widgets/TextInput.zig index 6e7f250..30e32a8 100644 --- a/src/widgets/TextInput.zig +++ b/src/widgets/TextInput.zig @@ -97,6 +97,18 @@ pub fn draw(self: *TextInput, win: Window) void { win.showCursor(cursor_idx, 0); } +pub fn clearAndFree(self: *TextInput) void { + self.buf.clearAndFree(); + self.cursor_idx = 0; + self.grapheme_count = 0; +} + +pub fn clearRetainingCapacity(self: *TextInput) void { + self.buf.clearRetainingCapacity(); + self.cursor_idx = 0; + self.grapheme_count = 0; +} + // returns the number of bytes before the cursor // (since GapBuffers are strictly speaking not contiguous, this is a number in 0..realLength() // which would need to be fed to realIndex() to get an actual offset into self.buf.items.ptr)