diff options
author | 2024-03-10 15:47:38 -0300 | |
---|---|---|
committer | 2024-07-08 01:16:31 +0200 | |
commit | 76f5bc2ccebb4c8b76ef81856c52da5b5e7c8960 (patch) | |
tree | 22673d11b6878a19eda279ef24add1de11dc3d16 | |
parent | 23d9497e7ff54f48a4c07247d7f1f68270b510d2 (diff) | |
download | iced-76f5bc2ccebb4c8b76ef81856c52da5b5e7c8960.tar.gz iced-76f5bc2ccebb4c8b76ef81856c52da5b5e7c8960.tar.bz2 iced-76f5bc2ccebb4c8b76ef81856c52da5b5e7c8960.zip |
add SelectAll to TextEditor
-rw-r--r-- | core/src/text/editor.rs | 2 | ||||
-rw-r--r-- | graphics/src/text/editor.rs | 21 | ||||
-rw-r--r-- | widget/src/text_editor.rs | 5 |
3 files changed, 28 insertions, 0 deletions
diff --git a/core/src/text/editor.rs b/core/src/text/editor.rs index fbf60696..aea00921 100644 --- a/core/src/text/editor.rs +++ b/core/src/text/editor.rs @@ -70,6 +70,8 @@ pub enum Action { SelectWord, /// Select the line at the current cursor. SelectLine, + /// Select the entire buffer. + SelectAll, /// Perform an [`Edit`]. Edit(Edit), /// Click the [`Editor`] at the given [`Point`]. diff --git a/graphics/src/text/editor.rs b/graphics/src/text/editor.rs index c488a51c..36b4ca6e 100644 --- a/graphics/src/text/editor.rs +++ b/graphics/src/text/editor.rs @@ -385,6 +385,27 @@ impl editor::Editor for Editor { })); } } + Action::SelectAll => { + let buffer = editor.buffer(); + if buffer.lines.len() > 1 + || buffer + .lines + .first() + .is_some_and(|line| !line.text().is_empty()) + { + let cursor = editor.cursor(); + editor.set_select_opt(Some(cosmic_text::Cursor { + line: 0, + index: 0, + ..cursor + })); + + editor.action( + font_system.raw(), + motion_to_action(Motion::DocumentEnd), + ); + } + } // Editing events Action::Edit(edit) => { diff --git a/widget/src/text_editor.rs b/widget/src/text_editor.rs index fc2ade43..0156b960 100644 --- a/widget/src/text_editor.rs +++ b/widget/src/text_editor.rs @@ -762,6 +762,11 @@ impl Update { { return Some(Self::Paste); } + keyboard::Key::Character("a") + if modifiers.command() => + { + return Some(Self::Action(Action::SelectAll)); + } _ => {} } |