Skip to content

Commit e8f120e

Browse files
author
BillionClaw
committed
fix(dataframe): prevent freeze when selecting cell with Ctrl key
When selecting a cell in gr.DataFrame by clicking (mousedown), then pressing Ctrl, then releasing the mouse (mouseup), the interface would freeze. This happened because: 1. On mousedown without Ctrl: handle_cell_click was called, selecting the cell 2. On mouseup with Ctrl pressed: handle_cell_click was called again due to the drag_state tracking, but with ctrlKey=true in the event 3. This caused toggle behavior (deselect) and inconsistent state The fix adds a handled_cell_click flag to track when handle_cell_click has already been invoked during start_drag, preventing duplicate calls in end_drag that could lead to the freeze. Fixes #13020
1 parent 356db5c commit e8f120e

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

js/dataframe/shared/Table.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,11 +768,13 @@
768768
let is_dragging = false;
769769
let drag_start: [number, number] | null = null;
770770
let mouse_down_pos: { x: number; y: number } | null = null;
771+
let handled_cell_click = false;
771772
772773
const drag_state: DragState = {
773774
is_dragging,
774775
drag_start,
775-
mouse_down_pos
776+
mouse_down_pos,
777+
handled_cell_click
776778
};
777779
778780
$: {

js/dataframe/shared/utils/drag_utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type DragState = {
55
is_dragging: boolean;
66
drag_start: CellCoordinate | null;
77
mouse_down_pos: { x: number; y: number } | null;
8+
handled_cell_click: boolean;
89
};
910

1011
export type DragHandlers = {
@@ -41,11 +42,13 @@ export function create_drag_handlers(
4142

4243
state.mouse_down_pos = { x: event.clientX, y: event.clientY };
4344
state.drag_start = [row, col];
45+
state.handled_cell_click = false;
4446

4547
if (!event.shiftKey && !event.metaKey && !event.ctrlKey) {
4648
set_selected_cells([[row, col]]);
4749
set_selected([row, col]);
4850
handle_cell_click(event, row, col);
51+
state.handled_cell_click = true;
4952
}
5053
};
5154

@@ -64,7 +67,7 @@ export function create_drag_handlers(
6467
};
6568

6669
const end_drag = (event: MouseEvent): void => {
67-
if (!state.is_dragging && state.drag_start) {
70+
if (!state.is_dragging && state.drag_start && !state.handled_cell_click) {
6871
handle_cell_click(event, state.drag_start[0], state.drag_start[1]);
6972
} else if (state.is_dragging && parent_element) {
7073
parent_element.focus();
@@ -74,6 +77,7 @@ export function create_drag_handlers(
7477
set_is_dragging(false);
7578
state.drag_start = null;
7679
state.mouse_down_pos = null;
80+
state.handled_cell_click = false;
7781
};
7882

7983
return {

0 commit comments

Comments
 (0)