1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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, Default)]
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);
    }
}