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