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:
parent
0798182012
commit
1e5560cc09
1 changed files with 12 additions and 0 deletions
|
@ -97,6 +97,18 @@ pub fn draw(self: *TextInput, win: Window) void {
|
||||||
win.showCursor(cursor_idx, 0);
|
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
|
// returns the number of bytes before the cursor
|
||||||
// (since GapBuffers are strictly speaking not contiguous, this is a number in 0..realLength()
|
// (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)
|
// which would need to be fed to realIndex() to get an actual offset into self.buf.items.ptr)
|
||||||
|
|
Loading…
Reference in a new issue