Skip to content

Commit

Permalink
Merge pull request #2215 from jhannyj/editor-cut
Browse files Browse the repository at this point in the history
Add cut functionality to text editor
  • Loading branch information
hecrj authored Jan 27, 2024
2 parents a1114ca + feccf15 commit 8d21867
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions widget/src/text_editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ where
clipboard.write(selection);
}
}
Update::Cut => {
if let Some(selection) = self.content.selection() {
clipboard.write(selection.clone());
shell.publish(on_edit(Action::Edit(Edit::Delete)));
}
}
Update::Paste => {
if let Some(contents) = clipboard.read() {
shell.publish(on_edit(Action::Edit(Edit::Paste(
Expand Down Expand Up @@ -575,6 +581,7 @@ enum Update {
Release,
Action(Action),
Copy,
Cut,
Paste,
}

Expand Down Expand Up @@ -684,6 +691,11 @@ impl Update {
{
Some(Self::Copy)
}
keyboard::Key::Character("x")
if modifiers.command() =>
{
Some(Self::Cut)
}
keyboard::Key::Character("v")
if modifiers.command() && !modifiers.alt() =>
{
Expand Down

0 comments on commit 8d21867

Please sign in to comment.