core: Add copy/paste context menu for EditText

This menu is shown when the EditText is focused and the mouse hovers over it.
It has the following elements, which may be disabled
when e.g. the field is not editable / selectable:
* Cut,
* Copy,
* Paste,
* Delete,
* Select All.
This commit is contained in:
Kamil Jarosz 2024-06-06 21:26:01 +02:00 committed by Nathan Adams
parent 0910104c3b
commit 6117c3c68e
2 changed files with 20 additions and 2 deletions

View File

@ -7,8 +7,9 @@
use crate::avm1;
use crate::avm2;
use crate::context::UpdateContext;
use crate::display_object::Stage;
use crate::display_object::TDisplayObject;
use crate::display_object::{EditText, Stage};
use crate::display_object::{InteractiveObject, TDisplayObject};
use crate::events::TextControlCode;
use crate::i18n::core_text;
use gc_arena::Collect;
use ruffle_render::quality::StageQuality;
@ -48,6 +49,15 @@ impl<'gc> ContextMenuState<'gc> {
let stage = context.stage;
let language = &context.ui.language();
// When a text field is focused and the mouse is hovering it,
// show the copy/paste menu.
if let Some(text) = context.focus_tracker.get_as_edit_text() {
if InteractiveObject::option_ptr_eq(context.mouse_data.hovered, text.as_interactive()) {
self.build_text_items(text, context);
return;
}
}
let Some(root_mc) = stage.root_clip().and_then(|c| c.as_movie_clip()) else {
return;
};
@ -222,6 +232,11 @@ pub enum ContextMenuCallback<'gc> {
Avm2 {
item: avm2::Object<'gc>,
},
TextControl {
#[collect(require_static)]
code: TextControlCode,
text: EditText<'gc>,
},
}
pub struct BuiltInItemFlags {

View File

@ -675,6 +675,9 @@ impl Player {
ContextMenuCallback::QualityHigh => {
context.stage.set_quality(context, StageQuality::High)
}
ContextMenuCallback::TextControl { code, text } => {
text.text_control_input(*code, context)
}
_ => {}
}
Self::run_actions(context);