Skip to content

Commit

Permalink
textinput: add clear methods
Browse files Browse the repository at this point in the history
Add clear methods to reset the underlying GapBuffer and reset cursor
positions

Signed-off-by: Tim Culverhouse <[email protected]>
  • Loading branch information
rockorager committed Mar 12, 2024
1 parent 0798182 commit 1e5560c
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/widgets/TextInput.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1e5560c

Please sign in to comment.