widgets(textinput): add toOwnedSlice

Add a way to get the contents of the TextInput
This commit is contained in:
Tim Culverhouse 2024-03-19 13:25:03 -05:00
parent d40fb7cbdb
commit b0944234c6

View file

@ -147,6 +147,12 @@ pub fn clearRetainingCapacity(self: *TextInput) void {
self.grapheme_count = 0; self.grapheme_count = 0;
} }
pub fn toOwnedSlice(self: *TextInput) ![]const u8 {
self.cursor_idx = 0;
self.grapheme_count = 0;
return self.buf.toOwnedSlice();
}
// 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)