Add more vi commands
This commit is contained in:
parent
e6df88f698
commit
2342bf0eae
4 changed files with 54 additions and 0 deletions
|
|
@ -75,6 +75,13 @@ impl<'a> Edit<'a> for Editor<'a> {
|
||||||
self.select_opt
|
self.select_opt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_select_opt(&mut self, select_opt: Option<Cursor>) {
|
||||||
|
if self.select_opt != select_opt {
|
||||||
|
self.select_opt = select_opt;
|
||||||
|
self.buffer.set_redraw(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn shape_as_needed(&mut self) {
|
fn shape_as_needed(&mut self) {
|
||||||
if self.cursor_moved {
|
if self.cursor_moved {
|
||||||
self.buffer.shape_until_cursor(self.cursor);
|
self.buffer.shape_until_cursor(self.cursor);
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,9 @@ pub trait Edit<'a> {
|
||||||
/// Get the current selection position
|
/// Get the current selection position
|
||||||
fn select_opt(&self) -> Option<Cursor>;
|
fn select_opt(&self) -> Option<Cursor>;
|
||||||
|
|
||||||
|
/// Set the current selection position
|
||||||
|
fn set_select_opt(&mut self, select_opt: Option<Cursor>);
|
||||||
|
|
||||||
/// Shape lines until scroll, after adjusting scroll if the cursor moved
|
/// Shape lines until scroll, after adjusting scroll if the cursor moved
|
||||||
fn shape_as_needed(&mut self);
|
fn shape_as_needed(&mut self);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -160,6 +160,10 @@ impl<'a> Edit<'a> for SyntaxEditor<'a> {
|
||||||
fn select_opt(&self) -> Option<Cursor> {
|
fn select_opt(&self) -> Option<Cursor> {
|
||||||
self.editor.select_opt()
|
self.editor.select_opt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_select_opt(&mut self, select_opt: Option<Cursor>) {
|
||||||
|
self.editor.set_select_opt(select_opt);
|
||||||
|
}
|
||||||
|
|
||||||
fn shape_as_needed(&mut self) {
|
fn shape_as_needed(&mut self) {
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,10 @@ impl<'a> Edit<'a> for ViEditor<'a> {
|
||||||
self.editor.select_opt()
|
self.editor.select_opt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_select_opt(&mut self, select_opt: Option<Cursor>) {
|
||||||
|
self.editor.set_select_opt(select_opt);
|
||||||
|
}
|
||||||
|
|
||||||
fn shape_as_needed(&mut self) {
|
fn shape_as_needed(&mut self) {
|
||||||
self.editor.shape_as_needed()
|
self.editor.shape_as_needed()
|
||||||
}
|
}
|
||||||
|
|
@ -95,6 +99,23 @@ impl<'a> Edit<'a> for ViEditor<'a> {
|
||||||
self.editor.action(Action::End);
|
self.editor.action(Action::End);
|
||||||
self.mode = Mode::Insert;
|
self.mode = Mode::Insert;
|
||||||
},
|
},
|
||||||
|
// Change mode
|
||||||
|
'c' => {
|
||||||
|
if self.editor.select_opt().is_some() {
|
||||||
|
self.editor.action(Action::Delete);
|
||||||
|
self.mode = Mode::Insert;
|
||||||
|
} else {
|
||||||
|
//TODO: change to next cursor movement
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Delete mode
|
||||||
|
'd' => {
|
||||||
|
if self.editor.select_opt().is_some() {
|
||||||
|
self.editor.action(Action::Delete);
|
||||||
|
} else {
|
||||||
|
//TODO: delete to next cursor movement
|
||||||
|
}
|
||||||
|
},
|
||||||
// Enter insert mode at cursor
|
// Enter insert mode at cursor
|
||||||
'i' => {
|
'i' => {
|
||||||
self.mode = Mode::Insert;
|
self.mode = Mode::Insert;
|
||||||
|
|
@ -133,6 +154,25 @@ impl<'a> Edit<'a> for ViEditor<'a> {
|
||||||
//TODO: 'L' => self.editor.action(Action::ScreenLow),
|
//TODO: 'L' => self.editor.action(Action::ScreenLow),
|
||||||
// Middle of screen
|
// Middle of screen
|
||||||
//TODO: 'M' => self.editor.action(Action::ScreenMiddle),
|
//TODO: 'M' => self.editor.action(Action::ScreenMiddle),
|
||||||
|
// Enter visual mode
|
||||||
|
'v' => {
|
||||||
|
if self.editor.select_opt().is_some() {
|
||||||
|
self.editor.set_select_opt(None);
|
||||||
|
} else {
|
||||||
|
self.editor.set_select_opt(Some(self.editor.cursor()));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// Enter line visual mode
|
||||||
|
'V' => {
|
||||||
|
if self.editor.select_opt().is_some() {
|
||||||
|
self.editor.set_select_opt(None);
|
||||||
|
} else {
|
||||||
|
self.editor.action(Action::Home);
|
||||||
|
self.editor.set_select_opt(Some(self.editor.cursor()));
|
||||||
|
//TODO: set cursor_x_opt to max
|
||||||
|
self.editor.action(Action::End);
|
||||||
|
}
|
||||||
|
},
|
||||||
// Remove character at cursor
|
// Remove character at cursor
|
||||||
'x' => self.editor.action(Action::Delete),
|
'x' => self.editor.action(Action::Delete),
|
||||||
// Remove character before cursor
|
// Remove character before cursor
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue