diff options
author | 2023-09-13 16:11:43 +0200 | |
---|---|---|
committer | 2023-09-13 16:11:43 +0200 | |
commit | f4c51a96d50953d5fb6e9eb62194f226e2cbfd3c (patch) | |
tree | 8f32e9741b23d7461604cfaaacb552f7ac97c9f4 /core/src/text | |
parent | 52b36a9574f45138363a4bfc6394c6da03baa433 (diff) | |
download | iced-f4c51a96d50953d5fb6e9eb62194f226e2cbfd3c.tar.gz iced-f4c51a96d50953d5fb6e9eb62194f226e2cbfd3c.tar.bz2 iced-f4c51a96d50953d5fb6e9eb62194f226e2cbfd3c.zip |
Introduce `Motion` concept in `core::text::editor`
Diffstat (limited to 'core/src/text')
-rw-r--r-- | core/src/text/editor.rs | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/core/src/text/editor.rs b/core/src/text/editor.rs index 09d4efde..f87e18f3 100644 --- a/core/src/text/editor.rs +++ b/core/src/text/editor.rs @@ -40,14 +40,8 @@ pub trait Editor: Sized + Default { #[derive(Debug, Clone, Copy, PartialEq)] pub enum Action { - MoveLeft, - MoveRight, - MoveUp, - MoveDown, - MoveLeftWord, - MoveRightWord, - MoveHome, - MoveEnd, + Move(Motion), + Select(Motion), SelectWord, SelectLine, Insert(char), @@ -58,6 +52,34 @@ pub enum Action { Drag(Point), } +#[derive(Debug, Clone, Copy, PartialEq)] +pub enum Motion { + Left, + Right, + Up, + Down, + WordLeft, + WordRight, + Home, + End, + PageUp, + PageDown, + DocumentStart, + DocumentEnd, +} + +impl Motion { + pub fn widen(self) -> Self { + match self { + Self::Left => Self::WordLeft, + Self::Right => Self::WordRight, + Self::Home => Self::DocumentStart, + Self::End => Self::DocumentEnd, + _ => self, + } + } +} + /// The cursor of an [`Editor`]. #[derive(Debug, Clone)] pub enum Cursor { |