From 6483e3bf5aa2405368ca5e1349abff3a418a0084 Mon Sep 17 00:00:00 2001 From: crumblingstatue Date: Thu, 1 Aug 2024 18:02:51 +0200 Subject: [PATCH] Use WString instead of String to avoid lossy utf8 conversion --- core/src/debug_ui/avm1.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/debug_ui/avm1.rs b/core/src/debug_ui/avm1.rs index b7cda01fcba6b..928514733a2ba 100644 --- a/core/src/debug_ui/avm1.rs +++ b/core/src/debug_ui/avm1.rs @@ -5,12 +5,13 @@ use crate::debug_ui::handle::{AVM1ObjectHandle, DisplayObjectHandle}; use crate::debug_ui::Message; use crate::string::AvmString; use egui::{Grid, Id, TextBuffer, TextEdit, Ui, Window}; +use ruffle_wstr::WString; #[derive(Debug, Default)] pub struct Avm1ObjectWindow { hovered_debug_rect: Option, key_filter_string: String, - edited_key: Option, + edited_key: Option, value_edit_buf: String, /// True if the active text edit should be focused (after clicking 'edit', etc.) focus_text_edit: bool, @@ -143,7 +144,7 @@ impl Avm1ObjectWindow { if self .edited_key .as_ref() - .is_some_and(|edit_key| *edit_key == key.to_utf8_lossy()) + .is_some_and(|edit_key| *edit_key == key.as_wstr()) { ui.horizontal(|ui| { let re = ui @@ -175,7 +176,7 @@ impl Avm1ObjectWindow { let num_str = num.to_string(); ui.label(&num_str); if ui.edit_button().clicked() { - self.edited_key = Some(key.to_utf8_lossy().into_owned()); + self.edited_key = Some(key.as_wstr().to_owned()); self.value_edit_buf = num_str; self.focus_text_edit = true; } @@ -194,7 +195,7 @@ impl Avm1ObjectWindow { if self .edited_key .as_ref() - .is_some_and(|edit_key| *edit_key == key.to_utf8_lossy()) + .is_some_and(|edit_key| *edit_key == key.as_wstr()) { let re = ui.add(TextEdit::singleline(&mut self.value_edit_buf).desired_width(96.0)); if self.focus_text_edit { @@ -212,7 +213,7 @@ impl Avm1ObjectWindow { ui.label(string.to_utf8_lossy()); if ui.edit_button().clicked() { self.value_edit_buf = string.to_string(); - self.edited_key = Some(key.to_string()); + self.edited_key = Some(key.as_wstr().to_owned()); self.focus_text_edit = true; } }