Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ctrl+X should cut the selected text to the clipboard #2155

Open
2 tasks done
jgcodes2020 opened this issue Dec 1, 2023 · 1 comment
Open
2 tasks done

Ctrl+X should cut the selected text to the clipboard #2155

jgcodes2020 opened this issue Dec 1, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@jgcodes2020
Copy link

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

This issue is similar to #2153. Try pressing Ctrl + X.

use iced::{Settings, Sandbox, window};
use iced::widget::{text_editor, container};

fn main() -> iced::Result {
    App::run(Settings {
        window: window::Settings {
            size: (640, 480),
            ..Default::default()
        },
        ..Default::default()
    })?;
    
    Ok(())
}

struct App {
    content: text_editor::Content,
}

#[derive(Debug, Clone)]
enum AppMessage {
    Edit(text_editor::Action)
}


impl Sandbox for App {
    type Message = AppMessage;

    fn new() -> Self {
        Self {
            content: text_editor::Content::new()
        }
    }

    fn title(&self) -> String {
        String::from("example")
    }

    fn update(&mut self, message: Self::Message) {
        match message {
            AppMessage::Edit(action) => {
                self.content.perform(action);
            },
        }
    }

    fn view(&self) -> iced::Element<'_, Self::Message> {
        let edit_box = text_editor(&self.content).on_action(AppMessage::Edit);
        
        container(edit_box).padding(10).into()
    }
}

What is the expected behavior?

Ctrl + X should cut text to the clipboard. It does nothing right now.

Version

master

Operating System

Linux

Do you have any log output?

No response

@jgcodes2020 jgcodes2020 added the bug Something isn't working label Dec 1, 2023
@crisci
Copy link

crisci commented Dec 14, 2023

Hey there, have you considered to add a subscription to the keyboard event?
When the key combination is recognized you can copy the text into the clipboard and than reset the content.

I've implemented a similar feature, but with the images, inside my project using also additional crates to handle the clipboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants