diff --git a/src/widgets/virtual_list/state.zig b/src/widgets/virtual_list/state.zig index 325849c..be47ed9 100644 --- a/src/widgets/virtual_list/state.zig +++ b/src/widgets/virtual_list/state.zig @@ -200,16 +200,30 @@ pub const VirtualListState = struct { /// Mueve la selección hacia arriba pub fn moveUp(self: *Self) void { + const window_offset = self.scroll_offset -| self.window_start; + if (self.findSelectedInWindow()) |window_idx| { + // Calcular posición en pantalla actual + const screen_pos = window_idx -| window_offset; + if (window_idx > 0) { + // Hay item anterior en buffer, seleccionarlo self.selectByWindowIndex(window_idx - 1); - } else if (self.window_start > 0) { - // Necesita scroll up - el widget debe manejar esto - self.scroll_offset = if (self.scroll_offset > 0) self.scroll_offset - 1 else 0; + + // Si estábamos en la primera fila visible, hacer scroll + if (screen_pos == 0 and self.scroll_offset > 0) { + self.scroll_offset -= 1; + } + } else { + // Estamos en el inicio del buffer + // Scroll up para cargar más datos (si es posible) + if (self.scroll_offset > 0) { + self.scroll_offset -= 1; + } } } else if (self.current_window.len > 0) { // Sin selección: seleccionar primera fila visible - self.selectByWindowIndex(0); + self.selectByWindowIndex(window_offset); } } diff --git a/src/widgets/virtual_list/virtual_list.zig b/src/widgets/virtual_list/virtual_list.zig index fc1d47c..eaa0d1e 100644 --- a/src/widgets/virtual_list/virtual_list.zig +++ b/src/widgets/virtual_list/virtual_list.zig @@ -116,7 +116,7 @@ pub fn virtualListRect( // Calculate dimensions const header_h: u32 = config.row_height; - const footer_h: u32 = if (config.show_count) 20 else 0; + const footer_h: u32 = if (config.show_count) 16 else 0; // 16px para footer compacto const content_h = bounds.h -| header_h -| footer_h; const visible_rows: usize = @intCast(content_h / config.row_height);