Skip to content

Commit

Permalink
add SelectAll to TextEditor
Browse files Browse the repository at this point in the history
  • Loading branch information
PgBiel committed Mar 10, 2024
1 parent f00e7c4 commit 2fab7f7
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/text/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`].
Expand Down
21 changes: 21 additions & 0 deletions graphics/src/text/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,27 @@ impl editor::Editor for Editor {
}));
}
}
Action::SelectAll => {
if editor.buffer().lines.len() > 1
|| editor
.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) => {
Expand Down
5 changes: 5 additions & 0 deletions widget/src/text_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,11 @@ impl Update {
{
return Some(Self::Paste);
}
keyboard::Key::Character("a")
if modifiers.command() =>
{
return Some(Self::Action(Action::SelectAll));
}
_ => {}
}

Expand Down

0 comments on commit 2fab7f7

Please sign in to comment.