textinput: add clear methods

Add clear methods to reset the underlying GapBuffer and reset cursor
positions

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
This commit is contained in:
Tim Culverhouse 2024-03-12 07:35:35 -05:00
parent 0798182012
commit 1e5560cc09

View file

@ -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)