Introduce Motion concept in core::text::editor

This commit is contained in:
Héctor Ramón Jiménez 2023-09-13 16:11:43 +02:00
parent 52b36a9574
commit f4c51a96d5
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
3 changed files with 157 additions and 66 deletions

View file

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