Skip to content

Commit a7a456b

Browse files
authored
EditableText drag selection fix (#24260)
# Objective `on_pointer_drag` queues `MoveToPoint` as well as `ExtendSelectionToPoint` when dragging. So each time the mouse moves during a drag, the current selection is cleared and a new selection is created. As long as the local drag start position is constant this is seamless, but if you scroll the text input view, the start of the drag is now at a different position relative to the text layout, and the start of the selection range changes. ## Solution Don't queue the `MoveToPoint` edit. ## Testing Enter enough text to overflow the input's view, then select and drag so it scrolls. ``` cargo run --example multiline_text_input ```
1 parent dc3a6cb commit a7a456b

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

crates/bevy_ui_widgets/src/text_input.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -285,23 +285,18 @@ fn on_pointer_drag(
285285
return;
286286
}
287287

288-
let Some((drag_start_local_pos, current_local_pos)) = transform.try_inverse().map(|inverse| {
289-
let transform_pos = |pointer_pos| {
290-
inverse.transform_point2(pointer_pos * target.scale_factor() / ui_scale.0)
291-
- node.content_box().min
292-
+ text_scroll.0
293-
};
294-
let current_pos = drag.pointer_location.position;
295-
let drag_start_pos = current_pos - drag.distance;
296-
(transform_pos(drag_start_pos), transform_pos(current_pos))
288+
let Some(current_local_pos) = transform.try_inverse().map(|inverse| {
289+
inverse
290+
.transform_point2(drag.pointer_location.position * target.scale_factor() / ui_scale.0)
291+
- node.content_box().min
292+
+ text_scroll.0
297293
}) else {
298294
return;
299295
};
300296

301-
editable_text.pending_edits.extend([
302-
TextEdit::MoveToPoint(drag_start_local_pos),
303-
TextEdit::ExtendSelectionToPoint(current_local_pos),
304-
]);
297+
editable_text
298+
.pending_edits
299+
.push(TextEdit::ExtendSelectionToPoint(current_local_pos));
305300

306301
drag.propagate(false);
307302
}

0 commit comments

Comments
 (0)