From b9e7434ef73cb9e16d8bfce3896d873ceed9cc44 Mon Sep 17 00:00:00 2001 From: "R.Eugenio" Date: Tue, 23 Dec 2025 14:11:12 +0100 Subject: [PATCH] fix(virtual_list): Scroll visual y click con offset correcto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - drawRows: Calcular window_offset para dibujar desde scroll_offset - handleMouseClick: Convertir screen_row a data_idx con offset - Antes siempre dibujaba desde índice 0 del buffer 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- src/widgets/virtual_list/virtual_list.zig | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/widgets/virtual_list/virtual_list.zig b/src/widgets/virtual_list/virtual_list.zig index 85197ad..fc1d47c 100644 --- a/src/widgets/virtual_list/virtual_list.zig +++ b/src/widgets/virtual_list/virtual_list.zig @@ -321,12 +321,19 @@ fn drawRows( const row_h = config.row_height; + // Calculate offset within the window buffer + // scroll_offset es la posición global, window_start es donde empieza el buffer + const window_offset = list_state.scroll_offset -| list_state.window_start; + // Draw each visible row var row_idx: usize = 0; - while (row_idx < visible_rows and row_idx < list_state.current_window.len) : (row_idx += 1) { + while (row_idx < visible_rows) : (row_idx += 1) { + const data_idx = window_offset + row_idx; + if (data_idx >= list_state.current_window.len) break; + const row_y = content_bounds.y + @as(i32, @intCast(row_idx * row_h)); - const global_idx = list_state.windowToGlobalIndex(row_idx); - const row = list_state.current_window[row_idx]; + const global_idx = list_state.scroll_offset + row_idx; // Índice global real + const row = list_state.current_window[data_idx]; // Determine row background const is_selected = list_state.selected_id != null and row.id == list_state.selected_id.?; @@ -498,10 +505,14 @@ fn handleMouseClick( // Check if click is in content area (not header) if (mouse.y >= content_y) { const relative_y = mouse.y - content_y; - const row_idx = @as(usize, @intCast(relative_y)) / config.row_height; + const screen_row = @as(usize, @intCast(relative_y)) / config.row_height; - if (row_idx < list_state.current_window.len) { - list_state.selectByWindowIndex(row_idx); + // Convert screen row to buffer index (accounting for scroll) + const window_offset = list_state.scroll_offset -| list_state.window_start; + const data_idx = window_offset + screen_row; + + if (data_idx < list_state.current_window.len) { + list_state.selectById(list_state.current_window[data_idx].id); // Check for double click // TODO: implement double click detection with timing