Skip to main content

sui_widgets/
text_command.rs

1use sui_runtime::{Command, CommandKey};
2
3/// Standard clipboard/selection command understood by text editing widgets.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum TextCommand {
6    Cut,
7    Copy,
8    Paste,
9    SelectAll,
10}
11
12/// Typed command key used for target-only text command delivery.
13pub const TEXT_COMMAND: CommandKey<TextCommand> = CommandKey::new("sui.text-command");
14
15impl TextCommand {
16    pub fn from_command(command: &Command<'_>) -> Option<Self> {
17        command.get(TEXT_COMMAND).copied()
18    }
19}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24
25    #[test]
26    fn text_command_key_has_a_stable_diagnostic_name() {
27        assert_eq!(TEXT_COMMAND.name(), "sui.text-command");
28    }
29}