Support modit::Key enum
This commit is contained in:
parent
9efcc41a5a
commit
e8dd8ec7d1
1 changed files with 205 additions and 217 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use alloc::string::String;
|
||||
use core::cmp;
|
||||
use modit::{Event, Motion, Parser, TextObject, WordIter};
|
||||
use modit::{Event, Key, Motion, Parser, TextObject, WordIter};
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -183,15 +183,15 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
fn action(&mut self, font_system: &mut FontSystem, action: Action) {
|
||||
let editor = &mut self.editor;
|
||||
log::info!("Action {:?}", action);
|
||||
let c = match action {
|
||||
Action::Escape => modit::ESCAPE,
|
||||
Action::Insert(c) => c,
|
||||
Action::Enter => modit::ENTER,
|
||||
Action::Backspace => modit::BACKSPACE,
|
||||
Action::Delete => modit::DELETE,
|
||||
let key = match action {
|
||||
Action::Backspace => Key::Backspace,
|
||||
Action::Delete => Key::Delete,
|
||||
Action::Enter => Key::Enter,
|
||||
Action::Escape => Key::Escape,
|
||||
Action::Insert(c) => Key::Char(c),
|
||||
_ => return editor.action(font_system, action),
|
||||
};
|
||||
self.parser.parse(c, false, |event| {
|
||||
self.parser.parse(key, false, |event| {
|
||||
log::info!(" Event {:?}", event);
|
||||
let action = match event {
|
||||
Event::AutoIndent => {
|
||||
|
|
@ -333,9 +333,8 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
log::info!("TODO");
|
||||
return;
|
||||
}
|
||||
Event::Motion(motion, count) => {
|
||||
for _ in 0..count {
|
||||
let action = match motion {
|
||||
Event::Motion(motion) => {
|
||||
match motion {
|
||||
Motion::Down => Action::Down,
|
||||
Motion::End => Action::End,
|
||||
Motion::GotoLine(line) => Action::GotoLine(line.saturating_sub(1)),
|
||||
|
|
@ -361,7 +360,7 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
None => {}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
Motion::NextCharTill(find_c) => {
|
||||
let mut cursor = editor.cursor();
|
||||
|
|
@ -379,7 +378,7 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
Motion::NextWordEnd(word) => {
|
||||
let mut cursor = editor.cursor();
|
||||
|
|
@ -389,11 +388,7 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
if cursor.index < text.len() {
|
||||
cursor.index = WordIter::new(text, word)
|
||||
.map(|(i, w)| {
|
||||
i + w
|
||||
.char_indices()
|
||||
.last()
|
||||
.map(|(i, _)| i)
|
||||
.unwrap_or(0)
|
||||
i + w.char_indices().last().map(|(i, _)| i).unwrap_or(0)
|
||||
})
|
||||
.find(|&i| i > cursor.index)
|
||||
.unwrap_or(text.len());
|
||||
|
|
@ -410,7 +405,7 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
break;
|
||||
}
|
||||
editor.set_cursor(cursor);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
Motion::NextWordStart(word) => {
|
||||
let mut cursor = editor.cursor();
|
||||
|
|
@ -435,7 +430,7 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
break;
|
||||
}
|
||||
editor.set_cursor(cursor);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
Motion::PreviousChar(find_c) => {
|
||||
let mut cursor = editor.cursor();
|
||||
|
|
@ -454,7 +449,7 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
None => {}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
Motion::PreviousCharTill(find_c) => {
|
||||
let mut cursor = editor.cursor();
|
||||
|
|
@ -481,7 +476,7 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
None => {}
|
||||
}
|
||||
}
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
Motion::PreviousWordEnd(word) => {
|
||||
let mut cursor = editor.cursor();
|
||||
|
|
@ -491,11 +486,7 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
if cursor.index > 0 {
|
||||
cursor.index = WordIter::new(text, word)
|
||||
.map(|(i, w)| {
|
||||
i + w
|
||||
.char_indices()
|
||||
.last()
|
||||
.map(|(i, _)| i)
|
||||
.unwrap_or(0)
|
||||
i + w.char_indices().last().map(|(i, _)| i).unwrap_or(0)
|
||||
})
|
||||
.filter(|&i| i < cursor.index)
|
||||
.last()
|
||||
|
|
@ -513,7 +504,7 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
break;
|
||||
}
|
||||
editor.set_cursor(cursor);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
Motion::PreviousWordStart(word) => {
|
||||
let mut cursor = editor.cursor();
|
||||
|
|
@ -539,20 +530,17 @@ impl<'a> Edit for ViEditor<'a> {
|
|||
break;
|
||||
}
|
||||
editor.set_cursor(cursor);
|
||||
continue;
|
||||
return;
|
||||
}
|
||||
Motion::Right => Action::Right,
|
||||
Motion::SoftHome => Action::SoftHome,
|
||||
Motion::Up => Action::Up,
|
||||
_ => {
|
||||
log::info!("TODO: {:?}", motion);
|
||||
break;
|
||||
}
|
||||
};
|
||||
editor.action(font_system, action);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
editor.action(font_system, action);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue