Introduce Motion concept in core::text::editor
This commit is contained in:
parent
52b36a9574
commit
f4c51a96d5
3 changed files with 157 additions and 66 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue