fix: Cell editor bugs - buffer corrupción + desincronización

Bug 1: text_input bytes corruptos al editar celda con texto pre-seleccionado
- Causa: slice getTextInput() se corrompía tras deleteSelection
- Fix: Copiar a buffer local antes de modificar edit_buffer

Bug 2: Editor permanecía visible al hacer clic en otra fila
- Causa: Falta commit implícito al abandonar fila
- Fix: handleMouseClick detecta clic en fila diferente → commitEdit()

Diagnóstico: Gemini | Implementación: Claude

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
R.Eugenio 2025-12-29 14:31:49 +01:00
parent ae1cfba33b
commit bb2d6a7be1
2 changed files with 22 additions and 1 deletions

View file

@ -197,8 +197,15 @@ pub fn handleEditingKeyboard(
} }
// Procesar texto ingresado (caracteres imprimibles) // Procesar texto ingresado (caracteres imprimibles)
// FIX: Copiar a buffer local ANTES de modificar edit_buffer (evita corrupción de slice)
const text_input = ctx.input.getTextInput(); const text_input = ctx.input.getTextInput();
if (text_input.len > 0) { if (text_input.len > 0) {
// Copiar input a buffer local seguro (en stack)
var local_input: [32]u8 = undefined;
const input_len = @min(text_input.len, local_input.len);
@memcpy(local_input[0..input_len], text_input[0..input_len]);
const safe_input = local_input[0..input_len];
// Si hay selección, borrarla primero (comportamiento Excel/Word) // Si hay selección, borrarla primero (comportamiento Excel/Word)
if (selection_start != null and selection_end != null) { if (selection_start != null and selection_end != null) {
if (selection_start.?.* != selection_end.?.*) { if (selection_start.?.* != selection_end.?.*) {
@ -206,7 +213,7 @@ pub fn handleEditingKeyboard(
} }
} }
for (text_input) |ch| { for (safe_input) |ch| {
if (edit_len.* < edit_buffer.len - 1) { if (edit_len.* < edit_buffer.len - 1) {
// Hacer espacio moviendo caracteres hacia la derecha // Hacer espacio moviendo caracteres hacia la derecha
if (edit_cursor.* < edit_len.*) { if (edit_cursor.* < edit_len.*) {

View file

@ -193,6 +193,20 @@ pub fn handleMouseClick(
if (data_idx < list_state.current_window.len) { if (data_idx < list_state.current_window.len) {
const global_row = list_state.nav.scroll_row + screen_row; const global_row = list_state.nav.scroll_row + screen_row;
// FIX Bug 2: Si estamos editando y clic en otra fila, hacer commit implícito
if (list_state.isEditing()) {
const editing_row = list_state.cell_edit.edit_row;
if (global_row != editing_row) {
// Commit implícito: clic fuera de la fila en edición
if (list_state.commitEdit()) {
result.cell_committed = true;
result.row_committed = true;
} else {
list_state.cancelEdit();
}
}
}
// Detect column // Detect column
var clicked_col: usize = 0; var clicked_col: usize = 0;
const relative_x = mouse.x - bounds.x + list_state.nav.scroll_x; const relative_x = mouse.x - bounds.x + list_state.nav.scroll_x;