-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
What is the intended use of text_input::State::cursor()? #443
Comments
|
Ah, so it supports cases where you're working directly with the Would you be open to adding methods to |
Maybe! What are the use cases you have in mind? |
Might be unrelated, but when working with input field tabbing I noticed a |
My particular use case is that I'm using a Subscription to implement my own copy/cut/undo/redo shortcuts (I'd like to figure out how to contribute them back if possible, but for now I just need to get something working). For copy/cut, I need to know what's currently selected, and for cut, I also need to delete the selected part of the text and clear the selection: // in update()
match shortcut {
// backup_target_input is a text_input::State, and backup_target_history is my own TextHistory
Shortcut::ClipboardCut => {
self.config.backup.path = crate::shortcuts::cut_to_clipboard_from_iced(&self.config.backup.path, &self.backup_screen.backup_target_input.cursor());
self.backup_screen.backup_target_history.push(&self.config.backup.path);
},
} pub fn cut_to_clipboard_from_iced(text: &str, cursor: &iced_native::text_input::Cursor) -> String {
let value = iced_native::text_input::Value::new(text);
match cursor.state(&value) {
iced_native::text_input::cursor::State::Selection { start, end } => {
match cut_to_clipboard(&text, std::cmp::min(start, end), std::cmp::max(start, end)) {
Ok(remaining) => {
// TODO: Clear the selection?
remaining.to_owned(),
}
Err(_) => text.to_owned(),
}
}
_ => text.to_owned(),
}
} Incidentally, cutting and then immediately pasting causes a panic in
|
Now that copy/paste/cut are supported in Let's open a new issue for undo / redo support! |
I'm trying to get the selection of a
TextInput
. I see that there is a publictext_input::State::cursor()
returning aCursor
, which has a publicstate()
method. However, I can't callCursor::state()
because it takes atext_input::value::Value
, which doesn't seem to be exposed, and even if I could call it, I don't thinktext_input::cursor::State
is exposed in order to match on the return value. I can understand whycursor::State
andValue
would be kept private if users are supposed to go throughtext_input::State
as a wrapper around them, but then I'm not sure whytext_input::State::cursor()
would ever be used as a public method, since everything else onCursor
is private. Am I missing something?The text was updated successfully, but these errors were encountered: