core: Make `EditText::set_text` accept a `&str`

This commit is contained in:
relrelb 2021-11-06 11:43:52 +02:00 committed by relrelb
parent c4b680fef9
commit 0787662079
3 changed files with 7 additions and 8 deletions

View File

@ -278,7 +278,7 @@ pub fn set_text<'gc>(
value: Value<'gc>,
) -> Result<(), Error<'gc>> {
if let Err(err) = this.set_text(
value.coerce_to_string(activation)?.to_string(),
&value.coerce_to_string(activation)?,
&mut activation.context,
) {
avm_error!(activation, "Error when setting TextField.text: {}", err);

View File

@ -466,12 +466,11 @@ pub fn set_text<'gc>(
{
let text = args
.get(0)
.cloned()
.unwrap_or(Value::Undefined)
.unwrap_or(&Value::Undefined)
.coerce_to_string(activation)?;
this.set_is_html(&mut activation.context, false);
this.set_text(text.to_string(), &mut activation.context)?;
this.set_text(&text, &mut activation.context)?;
}
Ok(Value::Undefined)

View File

@ -418,14 +418,14 @@ impl<'gc> EditText<'gc> {
pub fn set_text(
self,
text: String,
text: &str,
context: &mut UpdateContext<'_, 'gc, '_>,
) -> Result<(), Error> {
let mut edit_text = self.0.write(context.gc_context);
let len = edit_text.text_spans.text().len();
let tf = edit_text.text_spans.default_format().clone();
edit_text.text_spans.replace_text(0, len, &text, Some(&tf));
edit_text.text_spans.replace_text(0, len, text, Some(&tf));
drop(edit_text);
@ -471,7 +471,7 @@ impl<'gc> EditText<'gc> {
}
self.set_html_tree(document, context);
} else if let Err(err) = self.set_text(text, context) {
} else if let Err(err) = self.set_text(&text, context) {
log::error!("Error when setting TextField.htmlText: {}", err);
}
Ok(())
@ -732,7 +732,7 @@ impl<'gc> EditText<'gc> {
.initial_text
.clone()
.unwrap_or_default();
let _ = self.set_text(text, &mut activation.context);
let _ = self.set_text(&text, &mut activation.context);
self.0.write(activation.context.gc_context).variable = variable;
self.try_bind_text_field_variable(activation, true);