diff --git a/src/lib.rs b/src/lib.rs index 3c1331d414fd0ebf018f8530b6127a4db81ae0bf..dbbaa6557796dfa369f10d8a05025c545c52748d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,6 +88,7 @@ mod input; mod password; mod placeholder; mod render; +mod user_select; mod util; mod widget; @@ -109,6 +110,7 @@ pub use input::*; pub use password::*; pub use placeholder::*; pub use render::*; +pub use user_select::*; pub use util::*; pub use widget::*; @@ -132,6 +134,7 @@ impl Plugin for CosmicEditPlugin { PlaceholderPlugin, PasswordPlugin, EventsPlugin, + UserSelectPlugin, )) .insert_resource(CosmicFontSystem(font_system)); diff --git a/src/user_select.rs b/src/user_select.rs new file mode 100644 index 0000000000000000000000000000000000000000..4569397c51a0a5fb449c1cd7289aef8c6207be78 --- /dev/null +++ b/src/user_select.rs @@ -0,0 +1,21 @@ +use crate::*; +use bevy::prelude::*; + +pub(crate) struct UserSelectPlugin; + +impl Plugin for UserSelectPlugin { + fn build(&self, app: &mut App) { + app.add_systems(Update, clear_selection.after(InputSet)); + } +} + +/// Tag component to disable user selection +/// Like CSS `user-select: none` https://developer.mozilla.org/en-US/docs/Web/CSS/user-select +#[derive(Component)] +pub struct UserSelectNone; + +fn clear_selection(mut q: Query<&mut CosmicEditor, With<UserSelectNone>>) { + for mut editor in q.iter_mut() { + editor.set_selection(cosmic_text::Selection::None); + } +} diff --git a/src/util.rs b/src/util.rs index e51860883568460be40f13a4316d8869e9e1444a..7158db5c35fcb2b6fc0d68d75cd691d99a65e0d3 100644 --- a/src/util.rs +++ b/src/util.rs @@ -126,7 +126,7 @@ pub fn print_editor_text( if current_text == *previous_value { return; } - *previous_value = current_text.clone(); + previous_value.clone_from(¤t_text); info!("Widget text: {:?}", current_text); } }