From b0944234c6ea1a542823b8b0a5c82960193e5748 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 19 Mar 2024 13:25:03 -0500 Subject: [PATCH] widgets(textinput): add toOwnedSlice Add a way to get the contents of the TextInput --- src/widgets/TextInput.zig | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/widgets/TextInput.zig b/src/widgets/TextInput.zig index 65a9b8b..c3d5d1b 100644 --- a/src/widgets/TextInput.zig +++ b/src/widgets/TextInput.zig @@ -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)