Skip to content

Commit

Permalink
Fix SelectAll action in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jul 14, 2024
1 parent 632c8ed commit 61ee50c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions graphics/src/text/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,23 +309,29 @@ impl editor::Editor for Editor {
editor.set_selection(cosmic_text::Selection::Line(cursor));
}
Action::SelectAll => {
let buffer = editor.buffer();
let buffer = buffer_from_editor(editor);

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.set_selection(cosmic_text::Selection::Normal(
cosmic_text::Cursor {
line: 0,
index: 0,
..cursor
},
));

editor.action(
font_system.raw(),
motion_to_action(Motion::DocumentEnd),
cosmic_text::Action::Motion(
cosmic_text::Motion::BufferEnd,
),
);
}
}
Expand Down

0 comments on commit 61ee50c

Please sign in to comment.