fix(virtual_list): Scroll visual y click con offset correcto
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
ab39830477
commit
b9e7434ef7
1 changed files with 17 additions and 6 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue