this repo has no description
13
fork

Configure Feed

Select the types of activity you want to include in your feed.

widgets(textinput): move key handling to ifelse block

Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>

+7 -11
+7 -11
src/widgets/TextInput.zig
··· 35 35 pub fn update(self: *TextInput, event: Event) !void { 36 36 switch (event) { 37 37 .key_press => |key| { 38 - if (key.text) |text| { 39 - try self.buf.insertSlice(self.byteOffsetToCursor(), text); 40 - self.cursor_idx += 1; 41 - self.grapheme_count += 1; 42 - } 43 38 if (key.matches(Key.backspace, .{})) { 44 39 if (self.cursor_idx == 0) return; 45 40 self.deleteBeforeCursor(); 46 - } 47 - if (key.matches(Key.delete, .{})) { 41 + } else if (key.matches(Key.delete, .{})) { 48 42 if (self.cursor_idx == self.grapheme_count) return; 49 43 self.deleteAtCursor(); 50 - } 51 - if (key.matches(Key.left, .{})) { 44 + } else if (key.matches(Key.left, .{})) { 52 45 if (self.cursor_idx > 0) self.cursor_idx -= 1; 53 - } 54 - if (key.matches(Key.right, .{})) { 46 + } else if (key.matches(Key.right, .{})) { 55 47 if (self.cursor_idx < self.grapheme_count) self.cursor_idx += 1; 48 + } else if (key.text) |text| { 49 + try self.buf.insertSlice(self.byteOffsetToCursor(), text); 50 + self.cursor_idx += 1; 51 + self.grapheme_count += 1; 56 52 } 57 53 // TODO: readline bindings 58 54 },