feat(virtual_table): Implement Ctrl+N local injection handler
- Ctrl+N creates injected row below current selection - Uses startInjection() to initialize injection state - Automatically starts editing first column - Updates selection to show injected row as selected - Adjusts visible row count when injection is active No longer emits insert_row_requested - injection is handled internally by the widget.
This commit is contained in:
parent
5800d01a67
commit
47146b75c9
1 changed files with 38 additions and 4 deletions
|
|
@ -925,16 +925,21 @@ fn drawRows(
|
|||
const table_ds = datasource.toDataSource();
|
||||
|
||||
// Convertir selected_id a selected_row (índice global)
|
||||
const selected_row: i32 = if (list_state.findSelectedInWindow()) |window_idx|
|
||||
// Si hay una fila inyectada activa, esa es la seleccionada
|
||||
const selected_row: i32 = if (list_state.injected_row_idx) |inj_idx|
|
||||
@intCast(inj_idx)
|
||||
else if (list_state.findSelectedInWindow()) |window_idx|
|
||||
@intCast(list_state.windowToGlobalIndex(window_idx))
|
||||
else
|
||||
-1;
|
||||
|
||||
// Calcular rango de filas a dibujar
|
||||
const first_row = list_state.nav.scroll_row;
|
||||
// Si hay inyección, hay una fila más en la ventana visual
|
||||
const window_rows = list_state.current_window.len + @as(usize, if (list_state.hasInjection()) 1 else 0);
|
||||
const last_row = @min(
|
||||
list_state.nav.scroll_row + visible_rows,
|
||||
list_state.window_start + list_state.current_window.len,
|
||||
list_state.window_start + window_rows,
|
||||
);
|
||||
|
||||
// Convertir columnas a ColumnRenderDef
|
||||
|
|
@ -1204,11 +1209,40 @@ fn handleKeyboard(
|
|||
}
|
||||
|
||||
// =========================================================================
|
||||
// Propagar acciones CRUD al result (el panel las manejará)
|
||||
// Ctrl+N: Inyección local (insertar fila debajo de la actual)
|
||||
// =========================================================================
|
||||
if (events.insert_row) {
|
||||
result.insert_row_requested = true;
|
||||
// Solo permitir si no hay ya una inyección activa
|
||||
if (!list_state.hasInjection()) {
|
||||
// Calcular índice de inyección (debajo de la fila actual)
|
||||
const current_row: usize = if (list_state.findSelectedInWindow()) |window_idx|
|
||||
list_state.windowToGlobalIndex(window_idx)
|
||||
else
|
||||
0;
|
||||
|
||||
const injection_idx = current_row + 1;
|
||||
|
||||
// Iniciar inyección
|
||||
list_state.startInjection(injection_idx);
|
||||
|
||||
// Mover selección a la fila inyectada
|
||||
list_state.selected_id = null; // La fila inyectada no tiene ID aún
|
||||
// La selección visual se maneja por injected_row_idx
|
||||
|
||||
// Señalar que hay una nueva inyección
|
||||
result.injection_row_idx = injection_idx;
|
||||
result.selection_changed = true;
|
||||
|
||||
// Iniciar edición automática en primera columna
|
||||
list_state.cell_edit.startEdit(injection_idx, 0, "");
|
||||
list_state.nav.active_col = 0;
|
||||
}
|
||||
// Nota: insert_row_requested ya NO se emite - la inyección es interna
|
||||
}
|
||||
|
||||
// =========================================================================
|
||||
// Ctrl+Delete/B: Eliminar fila
|
||||
// =========================================================================
|
||||
if (events.delete_row) {
|
||||
result.delete_row_requested = true;
|
||||
// Obtener el ID de la fila seleccionada
|
||||
|
|
|
|||
Loading…
Reference in a new issue