Added yank editor commands
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Yank, yank line, and paste were added to normal mode keybinds
This commit is contained in:
parent
3b6f7cdbf4
commit
5943876569
|
@ -35,6 +35,10 @@ In normal mode the cursor is a block and functional keybinds can be used for mov
|
||||||
| dd | Delete the current line |
|
| dd | Delete the current line |
|
||||||
| cw | Change word forward |
|
| cw | Change word forward |
|
||||||
| cb | Change word backward |
|
| cb | Change word backward |
|
||||||
|
| y | Yank selection |
|
||||||
|
| Y | Yank line |
|
||||||
|
| p | Paste line at cursor |
|
||||||
|
| P | Paste line below |
|
||||||
|
|
||||||
** Insert mode
|
** Insert mode
|
||||||
In insert mode the cursor is a line and text can be edited. To return to normal mode use the ESC key.
|
In insert mode the cursor is a line and text can be edited. To return to normal mode use the ESC key.
|
||||||
|
|
|
@ -38,6 +38,10 @@ mod keymap {
|
||||||
pub const SELECT_MODE: &str = "v";
|
pub const SELECT_MODE: &str = "v";
|
||||||
pub const CHANGE_WORD_FORWARD: &str = "cw";
|
pub const CHANGE_WORD_FORWARD: &str = "cw";
|
||||||
pub const CHANGE_WORD_BACKWARD: &str = "cb";
|
pub const CHANGE_WORD_BACKWARD: &str = "cb";
|
||||||
|
pub const YANK: &str = "y";
|
||||||
|
pub const YANK_LINE: &str = "Y";
|
||||||
|
pub const PASTE: &str = "p";
|
||||||
|
pub const PASTE_LINE: &str = "P";
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct KeyList {
|
pub struct KeyList {
|
||||||
|
@ -67,6 +71,10 @@ mod keymap {
|
||||||
SELECT_MODE,
|
SELECT_MODE,
|
||||||
CHANGE_WORD_FORWARD,
|
CHANGE_WORD_FORWARD,
|
||||||
CHANGE_WORD_BACKWARD,
|
CHANGE_WORD_BACKWARD,
|
||||||
|
YANK,
|
||||||
|
YANK_LINE,
|
||||||
|
PASTE,
|
||||||
|
PASTE_LINE,
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,7 +161,7 @@ impl AbacusEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
if data.mode == EditMode::Normal {
|
if data.mode == EditMode::Normal {
|
||||||
let char_rect = if data.content.len_chars() == 0 {
|
let char_rect = if data.cursor_pos == 0 {
|
||||||
let rects = layout.rects_for_range(0..1);
|
let rects = layout.rects_for_range(0..1);
|
||||||
rects.first().cloned()
|
rects.first().cloned()
|
||||||
} else if data.current_char() == Some('\n')
|
} else if data.current_char() == Some('\n')
|
||||||
|
@ -362,7 +370,9 @@ impl Widget<EditorData> for AbacusEditor {
|
||||||
data.word_scan_backward();
|
data.word_scan_backward();
|
||||||
}
|
}
|
||||||
Some(keymap::SELECT_MODE) => {
|
Some(keymap::SELECT_MODE) => {
|
||||||
data.selection_pos = Some(data.cursor_pos);
|
data.cursor_to_end_of_line();
|
||||||
|
data.start_selection();
|
||||||
|
data.cursor_to_start_of_line();
|
||||||
}
|
}
|
||||||
Some(keymap::CHANGE_WORD_FORWARD) => {
|
Some(keymap::CHANGE_WORD_FORWARD) => {
|
||||||
data.delete_word_forward();
|
data.delete_word_forward();
|
||||||
|
@ -372,6 +382,48 @@ impl Widget<EditorData> for AbacusEditor {
|
||||||
data.delete_word_backward();
|
data.delete_word_backward();
|
||||||
data.insert_mode();
|
data.insert_mode();
|
||||||
}
|
}
|
||||||
|
Some(keymap::YANK) => {
|
||||||
|
if data.selection_pos.is_some() {
|
||||||
|
let mut cb: clipboard::ClipboardContext =
|
||||||
|
clipboard::ClipboardProvider::new().unwrap();
|
||||||
|
if let Some(slice) = data.content.get_slice(data.select_range())
|
||||||
|
{
|
||||||
|
let _ = cb.set_contents(slice.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.deselect();
|
||||||
|
}
|
||||||
|
Some(keymap::YANK_LINE) => {
|
||||||
|
data.cursor_to_start_of_line();
|
||||||
|
data.start_selection();
|
||||||
|
data.cursor_to_end_of_line();
|
||||||
|
if data.selection_pos.is_some() {
|
||||||
|
let mut cb: clipboard::ClipboardContext =
|
||||||
|
clipboard::ClipboardProvider::new().unwrap();
|
||||||
|
if let Some(slice) = data.content.get_slice(data.select_range())
|
||||||
|
{
|
||||||
|
let _ = cb.set_contents(slice.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data.deselect();
|
||||||
|
}
|
||||||
|
Some(keymap::PASTE) => {
|
||||||
|
let mut cb: clipboard::ClipboardContext =
|
||||||
|
clipboard::ClipboardProvider::new().unwrap();
|
||||||
|
data.push_str(&cb.get_contents().unwrap_or_default());
|
||||||
|
ctx.request_layout();
|
||||||
|
}
|
||||||
|
Some(keymap::PASTE_LINE) => {
|
||||||
|
if data.selection_pos.is_some() {
|
||||||
|
data.delete_char_back();
|
||||||
|
}
|
||||||
|
let mut cb: clipboard::ClipboardContext =
|
||||||
|
clipboard::ClipboardProvider::new().unwrap();
|
||||||
|
data.cursor_to_end_of_line();
|
||||||
|
data.push_str("\n");
|
||||||
|
data.push_str(&cb.get_contents().unwrap_or_default());
|
||||||
|
ctx.request_layout();
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue