Skip to content

Commit 87a9c36

Browse files
committed
text: Allow selecting text by dragging
This patch allows selecting text by pressing and dragging the mouse.
1 parent 671be1a commit 87a9c36

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

core/src/display_object/edit_text.rs

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,7 +2308,9 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
23082308
event: ClipEvent,
23092309
) -> ClipEventResult {
23102310
match event {
2311-
ClipEvent::Press | ClipEvent::MouseWheel { .. } => ClipEventResult::Handled,
2311+
ClipEvent::Press | ClipEvent::MouseWheel { .. } | ClipEvent::MouseMove => {
2312+
ClipEventResult::Handled
2313+
}
23122314
_ => ClipEventResult::NotHandled,
23132315
}
23142316
}
@@ -2333,43 +2335,58 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
23332335
return ClipEventResult::Handled;
23342336
}
23352337

2336-
if self.is_editable() || self.is_selectable() {
2337-
let tracker = context.focus_tracker;
2338-
tracker.set(Some(self.into()), context);
2339-
}
2338+
if let ClipEvent::Press = event {
2339+
if self.is_editable() || self.is_selectable() {
2340+
let tracker = context.focus_tracker;
2341+
tracker.set(Some(self.into()), context);
2342+
}
23402343

2341-
// We can't hold self as any link may end up modifying this object, so pull the info out
2342-
let mut link_to_open = None;
2344+
// We can't hold self as any link may end up modifying this object, so pull the info out
2345+
let mut link_to_open = None;
23432346

2344-
if let Some(position) = self.screen_position_to_index(*context.mouse_position) {
2345-
self.0.write(context.gc_context).selection =
2346-
Some(TextSelection::for_position(position));
2347+
if let Some(position) = self.screen_position_to_index(*context.mouse_position) {
2348+
self.0.write(context.gc_context).selection =
2349+
Some(TextSelection::for_position(position));
23472350

2348-
if let Some((span_index, _)) =
2349-
self.0.read().text_spans.resolve_position_as_span(position)
2350-
{
2351-
link_to_open = self
2352-
.0
2353-
.read()
2354-
.text_spans
2355-
.span(span_index)
2356-
.map(|s| (s.url.clone(), s.target.clone()));
2351+
if let Some((span_index, _)) =
2352+
self.0.read().text_spans.resolve_position_as_span(position)
2353+
{
2354+
link_to_open = self
2355+
.0
2356+
.read()
2357+
.text_spans
2358+
.span(span_index)
2359+
.map(|s| (s.url.clone(), s.target.clone()));
2360+
}
2361+
} else {
2362+
self.0.write(context.gc_context).selection =
2363+
Some(TextSelection::for_position(self.text_length()));
23572364
}
2358-
} else {
2359-
self.0.write(context.gc_context).selection =
2360-
Some(TextSelection::for_position(self.text_length()));
2365+
2366+
if let Some((url, target)) = link_to_open {
2367+
if !url.is_empty() {
2368+
// TODO: This fires on mouse DOWN but it should be mouse UP...
2369+
// but only if it went down in the same span.
2370+
// Needs more advanced focus handling than we have at time of writing this comment.
2371+
self.open_url(context, &url, &target);
2372+
}
2373+
}
2374+
2375+
return ClipEventResult::Handled;
23612376
}
23622377

2363-
if let Some((url, target)) = link_to_open {
2364-
if !url.is_empty() {
2365-
// TODO: This fires on mouse DOWN but it should be mouse UP...
2366-
// but only if it went down in the same span.
2367-
// Needs more advanced focus handling than we have at time of writing this comment.
2368-
self.open_url(context, &url, &target);
2378+
if let ClipEvent::MouseMove = event {
2379+
// If a move has moved and this EditTest is pressed, we need to update the selection.
2380+
if InteractiveObject::option_ptr_eq(context.mouse_data.pressed, self.as_interactive()) {
2381+
if let Some(position) = self.screen_position_to_index(*context.mouse_position) {
2382+
if let Some(ref mut selection) = self.0.write(context.gc_context).selection {
2383+
selection.to = position;
2384+
}
2385+
}
23692386
}
23702387
}
23712388

2372-
ClipEventResult::Handled
2389+
ClipEventResult::NotHandled
23732390
}
23742391

23752392
fn mouse_pick_avm1(

0 commit comments

Comments
 (0)