From feb1c4f48dad9fcb0c9a2dbc185aa1e1dcb8d6be Mon Sep 17 00:00:00 2001 From: reugenio Date: Wed, 10 Dec 2025 01:39:26 +0100 Subject: [PATCH] feat(TextInput): Manejar teclas especiales internamente MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit El widget TextInput ahora procesa internamente: - Backspace/Delete: borrar caracteres - Flechas izq/der: mover cursor - Home/End: inicio/fin del texto - Shift+movimiento: selección - Ctrl+A: seleccionar todo - Enter: submit Esto hace que el widget sea auto-contenido y reutilizable, sin requerir manejo de teclas en la aplicación. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/widgets/text_input.zig | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/widgets/text_input.zig b/src/widgets/text_input.zig index b052b3a..b376042 100644 --- a/src/widgets/text_input.zig +++ b/src/widgets/text_input.zig @@ -278,8 +278,39 @@ pub fn textInputRect( const inner = bounds.shrink(config.padding); if (inner.isEmpty()) return result; - // Handle text input if focused + // Handle keyboard input if focused if (state.focused and !config.readonly) { + // Handle special keys (navigation, deletion) + for (ctx.input.key_events[0..ctx.input.key_event_count]) |key_event| { + if (key_event.pressed) { + const shift = key_event.modifiers.shift; + switch (key_event.key) { + .backspace => { + state.deleteBack(); + result.changed = true; + }, + .delete => { + state.deleteForward(); + result.changed = true; + }, + .left => state.cursorLeft(shift), + .right => state.cursorRight(shift), + .home => state.cursorHome(shift), + .end => state.cursorEnd(shift), + .enter => { + result.submitted = true; + }, + .a => { + // Ctrl+A = Select All + if (key_event.modifiers.ctrl) { + state.selectAll(); + } + }, + else => {}, + } + } + } + // Handle typed text const text_in = ctx.input.getTextInput(); if (text_in.len > 0) {