Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Render EditText's selection when filters are present #16422

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions core/src/display_object/edit_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1256,12 +1256,18 @@ impl<'gc> EditText<'gc> {

pub fn set_selection(self, selection: Option<TextSelection>, gc_context: &Mutation<'gc>) {
let mut text = self.0.write(gc_context);
let old_selection = text.selection;
if let Some(mut selection) = selection {
selection.clamp(text.text_spans.text().len());
text.selection = Some(selection);
} else {
text.selection = None;
}

if old_selection != text.selection {
drop(text);
self.invalidate_cached_bitmap(gc_context);
}
}

pub fn reset_selection_blinking(self, gc_context: &Mutation<'gc>) {
Expand Down Expand Up @@ -2342,8 +2348,7 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
let mut link_to_open = None;

if let Some(position) = self.screen_position_to_index(*context.mouse_position) {
self.0.write(context.gc_context).selection =
Some(TextSelection::for_position(position));
self.set_selection(Some(TextSelection::for_position(position)), context.gc());

if let Some((span_index, _)) =
self.0.read().text_spans.resolve_position_as_span(position)
Expand All @@ -2356,8 +2361,10 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
.map(|s| (s.url.clone(), s.target.clone()));
}
} else {
self.0.write(context.gc_context).selection =
Some(TextSelection::for_position(self.text_length()));
self.set_selection(
Some(TextSelection::for_position(self.text_length())),
context.gc(),
);
}

if let Some((url, target)) = link_to_open {
Expand Down Expand Up @@ -2442,7 +2449,7 @@ impl<'gc> TInteractiveObject<'gc> for EditText<'gc> {
) {
let is_avm1 = !self.movie().is_action_script_3();
if !focused && is_avm1 {
self.0.write(context.gc_context).selection = None;
self.set_selection(None, context.gc_context);
}
}

Expand Down Expand Up @@ -2504,6 +2511,14 @@ pub struct TextSelection {
blink_epoch: DateTime<Utc>,
}

impl PartialEq for TextSelection {
fn eq(&self, other: &Self) -> bool {
self.from == other.from && self.to == other.to
}
}

impl Eq for TextSelection {}

/// Information about the start and end y-coordinates of a given line of text
#[derive(Copy, Clone, Debug)]
pub struct LineData {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{ "type": "Wait" },
{ "type": "Wait" },
{ "type": "TextControl", "code": "MoveLeft" },
{ "type": "TextControl", "code": "MoveRight" },
{ "type": "TextControl", "code": "MoveRight" },
{ "type": "Wait" }
]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
num_ticks = 3

[image_comparisons."output.01"]
trigger = 1
max_outliers = 5

[image_comparisons."output.02"]
trigger = 2
max_outliers = 5

[image_comparisons."output.03"]
trigger = 3
max_outliers = 5

[player_options]
with_renderer = { optional = false, sample_count = 1 }