Skip to content

Commit

Permalink
widgets(textinput): add toOwnedSlice
Browse files Browse the repository at this point in the history
Add a way to get the contents of the TextInput
  • Loading branch information
rockorager committed Mar 19, 2024
1 parent d40fb7c commit b094423
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/widgets/TextInput.zig
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ pub fn clearRetainingCapacity(self: *TextInput) void {
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
// (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 b094423

Please sign in to comment.