From 6a94f4f5f0132d870b8b1d481bf4ba3e3c110019 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 29 Jan 2024 18:06:32 +0100 Subject: [PATCH] Fix input lag in drag-to-select o labels (#3917) Introduced in the recent drag-vs-click stuff --- .../egui/src/text_selection/label_text_selection.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/egui/src/text_selection/label_text_selection.rs b/crates/egui/src/text_selection/label_text_selection.rs index 5685bd8b..af9e3039 100644 --- a/crates/egui/src/text_selection/label_text_selection.rs +++ b/crates/egui/src/text_selection/label_text_selection.rs @@ -372,16 +372,18 @@ impl LabelSelectionState { selection.primary = WidgetTextCursor::new(response.id, new_primary, galley_pos, galley); - if response.drag_started() { + // We don't want the latency of `drag_started`. + let drag_started = ui.input(|i| i.pointer.any_pressed()); + if drag_started { if selection.layer_id == response.layer_id { if ui.input(|i| i.modifiers.shift) { - // A continuation of a previous selection? + // A continuation of a previous selection. } else { - // A new selection. + // A new selection in the same layer. selection.secondary = selection.primary; } } else { - // A new selection. + // A new selection in a new layer. selection.layer_id = response.layer_id; selection.secondary = selection.primary; } @@ -474,7 +476,7 @@ impl LabelSelectionState { } self.any_hovered |= response.hovered(); - self.is_dragging |= response.dragged(); + self.is_dragging |= response.is_pointer_button_down_on(); // we don't want the initial latency of drag vs click decision let old_selection = self.selection;