Merge pull request #2321 from PgBiel/select-all

Add "Select All" functionality on Ctrl+A to TextEditor
This commit is contained in:
Héctor Ramón 2024-07-08 01:25:41 +02:00 committed by GitHub
commit acf6daff46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 0 deletions

View file

@ -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`].

View file

@ -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) => {

View file

@ -762,6 +762,11 @@ impl Update {
{
return Some(Self::Paste);
}
keyboard::Key::Character("a")
if modifiers.command() =>
{
return Some(Self::Action(Action::SelectAll));
}
_ => {}
}