feat(TextInput): Manejar teclas especiales internamente
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 <noreply@anthropic.com>
This commit is contained in:
parent
f7a7b48c2c
commit
feb1c4f48d
1 changed files with 32 additions and 1 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue