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

Clipboard support? #295

Closed
Newbytee opened this issue Apr 14, 2020 · 5 comments · Fixed by #770
Closed

Clipboard support? #295

Newbytee opened this issue Apr 14, 2020 · 5 comments · Fixed by #770
Labels
feature New feature or request question Further information is requested
Milestone

Comments

@Newbytee
Copy link

I'm on Linux/X11, and clipboard support seems non-existent. Would definitely be great to have this.

I found this issue: #36, but it only seems to concern selecting text (which seems to work for me in Iced 0.1), not copying and pasting.

Is anyone working on this? I might take it on if not.

@hecrj hecrj added feature New feature or request question Further information is requested labels Apr 21, 2020
@hecrj
Copy link
Member

hecrj commented Apr 21, 2020

Currently, we only support pasting (i.e. reading) from a Clipboard. There are plans to support copying (i.e. writing) relatively soon.

I started a window_clipboard crate to experiment and unify different clipboard APIs for GUI applications. There are some on-going discussions there. Feel free to join!

@Newbytee
Copy link
Author

Currently, we only support pasting (i.e. reading) from a Clipboard.

Does this require the application using Iced to handle the clipboard itself, or can I somehow have a text field inherently support pasting (via the usual keyboard shortcuts)?

There are plans to support copying (i.e. writing) relatively soon.

Any rough estimate?

I started a window_clipboard crate to experiment and unify different clipboard APIs for GUI applications. There are some on-going discussions there. Feel free to join!

👍

@hecrj
Copy link
Member

hecrj commented Apr 21, 2020

can I somehow have a text field inherently support pasting

This should already work since #132.

Any rough estimate?

Once we figure out a nice, cross-platform API for writing to the clipboard.

@mtkennerly
Copy link
Contributor

mtkennerly commented Jul 10, 2020

@hecrj What if a custom iced_native::Clipboard implementation could be passed to a TextInput, like TextInput::new(...).clipboard(MyClipboard::new())? That way, Iced could support the copy/cut logic and keyboard shortcuts out of the box, but they would just be no-ops unless an app provides a custom clipboard (or until iced_winit's implementation offers write support). This should also allow for unique clipboards, like if you wanted multiple program-specific clipboards in addition to (or instead of) the system one and wanted to switch between them with hotkeys.

iced_native::Clipboard::content() is already specific to strings. I'm not sure how/if you'd envision supporting other data types in the future, but if we can just stick with strings for now, then perhaps the trait could be updated like this:

pub enum Error {
    UnsupportedOperation,
}

pub trait Clipboard {
    fn content(&self) -> Option<String>;
    fn write(&mut self, text: &str) -> Result<(), Error>;
}

iced_winit could just return Err(Error::UnsupportedOperation) for write, meaning the keyboard shortcuts would be no-ops.

For non-string types, perhaps a separate MultimediaClipboard trait could be added in the future if needed, without breaking compatibility for text-only widgets.

@python273
Copy link

@hecrj nice update!

Not sure if related, but if the cursor is on the right and I try to move cursor to the left, it tries to select from the cursor position or something

E.g if input content is: *long string*123456|cursor|789 and I click between 34, it tries to select 456

Screen.Recording.2021-03-10.at.23.21.59.mov

@hecrj hecrj added this to the 0.3.0 milestone Mar 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants