Skip to content

Commit 7c4da6b

Browse files
committed
text: Allow selecting text by dragging
This patch allows selecting text by pressing and dragging the mouse.
1 parent 1080c8b commit 7c4da6b

File tree

1 file changed

+49
-30
lines changed

1 file changed

+49
-30
lines changed

core/src/display_object/edit_text.rs

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,9 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
23142314
event: ClipEvent,
23152315
) -> ClipEventResult {
23162316
match event {
2317-
ClipEvent::Press | ClipEvent::MouseWheel { .. } => ClipEventResult::Handled,
2317+
ClipEvent::Press | ClipEvent::MouseWheel { .. } | ClipEvent::MouseMove => {
2318+
ClipEventResult::Handled
2319+
}
23182320
_ => ClipEventResult::NotHandled,
23192321
}
23202322
}
@@ -2339,44 +2341,61 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
23392341
return ClipEventResult::Handled;
23402342
}
23412343

2342-
if self.is_editable() || self.is_selectable() {
2343-
let tracker = context.focus_tracker;
2344-
tracker.set(Some(self.into()), context);
2345-
}
2344+
if let ClipEvent::Press = event {
2345+
if self.is_editable() || self.is_selectable() {
2346+
let tracker = context.focus_tracker;
2347+
tracker.set(Some(self.into()), context);
2348+
}
23462349

2347-
// We can't hold self as any link may end up modifying this object, so pull the info out
2348-
let mut link_to_open = None;
2350+
// We can't hold self as any link may end up modifying this object, so pull the info out
2351+
let mut link_to_open = None;
23492352

2350-
if let Some(position) = self.screen_position_to_index(*context.mouse_position) {
2351-
self.set_selection(Some(TextSelection::for_position(position)), context.gc());
2353+
if let Some(position) = self.screen_position_to_index(*context.mouse_position) {
2354+
self.set_selection(
2355+
Some(TextSelection::for_position(position)), context.gc());
23522356

2353-
if let Some((span_index, _)) =
2354-
self.0.read().text_spans.resolve_position_as_span(position)
2355-
{
2356-
link_to_open = self
2357-
.0
2358-
.read()
2359-
.text_spans
2360-
.span(span_index)
2361-
.map(|s| (s.url.clone(), s.target.clone()));
2362-
}
2363-
} else {
2364-
self.set_selection(
2365-
Some(TextSelection::for_position(self.text_length())),
2366-
context.gc(),
2357+
if let Some((span_index, _)) =
2358+
self.0.read().text_spans.resolve_position_as_span(position)
2359+
{
2360+
link_to_open = self
2361+
.0
2362+
.read()
2363+
.text_spans
2364+
.span(span_index)
2365+
.map(|s| (s.url.clone(), s.target.clone()));
2366+
}
2367+
} else {
2368+
self.set_selection(
2369+
Some(TextSelection::for_position(self.text_length())),
2370+
context.gc(),
23672371
);
23682372
}
23692373

2370-
if let Some((url, target)) = link_to_open {
2371-
if !url.is_empty() {
2372-
// TODO: This fires on mouse DOWN but it should be mouse UP...
2373-
// but only if it went down in the same span.
2374-
// Needs more advanced focus handling than we have at time of writing this comment.
2375-
self.open_url(context, &url, &target);
2374+
if let Some((url, target)) = link_to_open {
2375+
if !url.is_empty() {
2376+
// TODO: This fires on mouse DOWN but it should be mouse UP...
2377+
// but only if it went down in the same span.
2378+
// Needs more advanced focus handling than we have at time of writing this comment.
2379+
self.open_url(context, &url, &target);
2380+
}
2381+
}
2382+
2383+
return ClipEventResult::Handled;
2384+
}
2385+
2386+
if let ClipEvent::MouseMove = event {
2387+
// If a mouse has moved and this EditTest is pressed, we need to update the selection.
2388+
if InteractiveObject::option_ptr_eq(context.mouse_data.pressed, self.as_interactive()) {
2389+
if let Some(mut selection) = self.selection() {
2390+
if let Some(position) = self.screen_position_to_index(*context.mouse_position) {
2391+
selection.to = position;
2392+
self.set_selection(Some(selection), context.gc());
2393+
}
2394+
}
23762395
}
23772396
}
23782397

2379-
ClipEventResult::Handled
2398+
ClipEventResult::NotHandled
23802399
}
23812400

23822401
fn mouse_pick_avm1(

0 commit comments

Comments
 (0)