diff --git a/README.md b/README.md index b62b827..8159a08 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,8 @@ and switch into the other modes. | W | Move the cursor to the previous word | | \ | Move the cursor one page above | | \ | Move the cursor one page below | +| \ | Move the cursor to beginning of line | +| \ | Move the cursor to the end of the line | | v | Switch to Visual Mode | | i | Switch to Insert Mode | | \ | Switch to Action Mode | @@ -75,14 +77,16 @@ and switch into the other modes. The Insert mode is used to insert some content. -| **Key** | **Description** | -|:------------:|:------------------------------:| -| ←↑→↓ | Move the cursor | -| \ | Move the cursor one page above | -| \ | Move the cursor one page below | -| \ | Switch to the normal mode | -| \ | Remove a character backward | -| \ | Remove a character forward | +| **Key** | **Description** | +|:------------:|:--------------------------------------:| +| ←↑→↓ | Move the cursor | +| \ | Move the cursor one page above | +| \ | Move the cursor one page below | +| \ | Move the cursor to beginning of line | +| \ | Move the cursor to the end of the line | +| \ | Switch to the normal mode | +| \ | Remove a character backward | +| \ | Remove a character forward | #### Visual mode @@ -95,6 +99,8 @@ The Visual mode is used to select some text and manipulate it. | hjkl | Move the cursor | | w | Move the cursor to the next word | | W | Move the cursor to the previous word | +| \ | Move the cursor to beginning of line | +| \ | Move the cursor to the end of the line | | \ | Switch to Normal Mode | | q | Switch to Normal Mode | | \ | Switch to Action Mode | diff --git a/src/input_controller/actions/mod.rs b/src/input_controller/actions/mod.rs index eb7755e..65d49bc 100644 --- a/src/input_controller/actions/mod.rs +++ b/src/input_controller/actions/mod.rs @@ -18,7 +18,7 @@ pub enum Response { #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum Action { WriteToFile, - Quite, + Quit, SwitchToInsertMode, SwitchToVisualMode, @@ -29,9 +29,12 @@ pub enum Action { MoveDown, MoveLeft, MoveRight, - MoveWordRight, MoveWordLeft, + MoveToLeftEndOfLine, + MoveToRightEndOfLine, + MoveToLeftEndOfLineAndSelect, + MoveToRightEndOfLineAndSelect, PageUp, PageDown, @@ -71,7 +74,7 @@ impl Action { ) -> Response { match self { Action::WriteToFile => rpc::write_to_file(view_id, front_event_writer), - Action::Quite => rpc::quite(view_id, core), + Action::Quit => rpc::quit(view_id, core), Action::SwitchToInsertMode => Response::SwitchToInsertMode, Action::SwitchToVisualMode => Response::SwitchToVisualMode, @@ -88,6 +91,11 @@ impl Action { Action::PageUp => rpc::page_up(view_id, core), Action::PageDown => rpc::page_down(view_id, core), + Action::MoveToLeftEndOfLine => rpc::move_to_left_end_of_line(view_id, core), + Action::MoveToRightEndOfLine => rpc::move_to_right_end_of_line(view_id, core), + Action::MoveToLeftEndOfLineAndSelect => rpc::move_to_left_end_of_line_and_select(view_id, core), + Action::MoveToRightEndOfLineAndSelect => rpc::move_to_right_end_of_line_and_select(view_id, core), + Action::MoveUpAndSelect => rpc::move_up_and_select(view_id, core), Action::MoveDownAndSelect => rpc::move_down_and_select(view_id, core), @@ -97,8 +105,8 @@ impl Action { Action::MoveWordLeftAndSelect => rpc::move_word_left_and_select(view_id, core), Action::YankSelection => rpc::yank_selection(view_id, core), - Action::DeleteSelection => rpc::cute_selection(view_id, core), - Action::DeleteSelectionAndPaste => rpc::cute_selection_and_paste(view_id, core), + Action::DeleteSelection => rpc::cut_selection(view_id, core), + Action::DeleteSelectionAndPaste => rpc::cut_selection_and_paste(view_id, core), Action::Paste => rpc::paste(view_id, core), @@ -117,7 +125,7 @@ impl Action { pub fn from_description(desc: &str) -> Option { match desc { "write_to_file" => Some(Action::WriteToFile), - "quit" => Some(Action::Quite), + "quit" => Some(Action::Quit), "switch_to_insert_mode" => Some(Action::SwitchToInsertMode), "switch_to_visual_mode" => Some(Action::SwitchToVisualMode), @@ -131,6 +139,8 @@ impl Action { "page_up" => Some(Action::PageUp), "page_down" => Some(Action::PageDown), + "move_to_left_end_of_line" => Some(Action::MoveToLeftEndOfLine), + "move_to_right_end_of_line" => Some(Action::MoveToRightEndOfLine), "move_up_and_select" => Some(Action::MoveUpAndSelect), "move_down_and_select" => Some(Action::MoveDownAndSelect), "move_left_and_select" => Some(Action::MoveLeftAndSelect), @@ -138,7 +148,7 @@ impl Action { "yank_selection" => Some(Action::YankSelection), "delete_selection" => Some(Action::DeleteSelection), - "delete_selection_and_past" => Some(Action::DeleteSelectionAndPaste), + "delete_selection_and_paste" => Some(Action::DeleteSelectionAndPaste), "paste" => Some(Action::Paste), diff --git a/src/input_controller/actions/rpc.rs b/src/input_controller/actions/rpc.rs index d2f823c..68c5ce0 100644 --- a/src/input_controller/actions/rpc.rs +++ b/src/input_controller/actions/rpc.rs @@ -24,7 +24,7 @@ pub fn insert_keystroke(view_id: &str, key: KeyStroke, core: &dyn Peer) -> Respo Response::Continue } -pub fn quite(view_id: &str, core: &dyn Peer) -> Response { +pub fn quit(view_id: &str, core: &dyn Peer) -> Response { core.send_rpc_notification("close_view", &json!({ "view_id": view_id })); core.send_rpc_notification("exit", &json!({})); @@ -92,6 +92,38 @@ pub fn page_down(view_id: &str, core: &dyn Peer) -> Response { Response::Continue } +pub fn move_to_left_end_of_line(view_id: &str, core: &dyn Peer) -> Response { + core.send_rpc_notification( + "edit", + &json!({ "method": "move_to_left_end_of_line", "view_id": view_id }), + ); + Response::Continue +} + +pub fn move_to_right_end_of_line(view_id: &str, core: &dyn Peer) -> Response { + core.send_rpc_notification( + "edit", + &json!({ "method": "move_to_right_end_of_line", "view_id": view_id }), + ); + Response::Continue +} + +pub fn move_to_left_end_of_line_and_select(view_id: &str, core: &dyn Peer) -> Response { + core.send_rpc_notification( + "edit", + &json!({ "method": "move_to_left_end_of_line_and_modify_selection", "view_id": view_id }), + ); + Response::Continue +} + +pub fn move_to_right_end_of_line_and_select(view_id: &str, core: &dyn Peer) -> Response { + core.send_rpc_notification( + "edit", + &json!({ "method": "move_to_right_end_of_line_and_modify_selection", "view_id": view_id }), + ); + Response::Continue +} + pub fn move_word_right(view_id: &str, core: &dyn Peer) -> Response { core.send_rpc_notification( "edit", @@ -182,7 +214,7 @@ pub fn yank_selection(view_id: &str, core: &dyn Peer) -> Response { Response::SwitchToNormalMode } -pub fn cute_selection(view_id: &str, core: &dyn Peer) -> Response { +pub fn cut_selection(view_id: &str, core: &dyn Peer) -> Response { let cut_res = core.send_rpc_request("edit", &json!({ "method": "cut", "view_id": view_id})); if cut_res.is_err() { error!("failed to cut the selection: {:?}", cut_res); @@ -200,7 +232,7 @@ pub fn cute_selection(view_id: &str, core: &dyn Peer) -> Response { Response::SwitchToNormalMode } -pub fn cute_selection_and_paste(view_id: &str, core: &dyn Peer) -> Response { +pub fn cut_selection_and_paste(view_id: &str, core: &dyn Peer) -> Response { let cut_res = core.send_rpc_request("edit", &json!({ "method": "cut", "view_id": view_id})); if cut_res.is_err() { error!("failed to cut the selection: {:?}", cut_res); diff --git a/src/input_controller/keyboard/mod.rs b/src/input_controller/keyboard/mod.rs index 6d381df..5b42ed1 100644 --- a/src/input_controller/keyboard/mod.rs +++ b/src/input_controller/keyboard/mod.rs @@ -21,6 +21,8 @@ pub enum KeyStroke { KeyBackSpace, KeyDelete, KeySpace, + KeyHome, + KeyEnd, } impl KeyStroke { @@ -37,6 +39,8 @@ impl KeyStroke { "" => Some(KeyStroke::KeyRight), "" => Some(KeyStroke::KeyPreviousPage), "" => Some(KeyStroke::KeyNextPage), + "" => Some(KeyStroke::KeyHome), + "" => Some(KeyStroke::KeyEnd), "" => Some(KeyStroke::KeyBackSpace), "" => Some(KeyStroke::KeyDelete), "" => Some(KeyStroke::KeySpace), diff --git a/src/input_controller/keyboard/termion.rs b/src/input_controller/keyboard/termion.rs index 88bb436..bbe75c1 100644 --- a/src/input_controller/keyboard/termion.rs +++ b/src/input_controller/keyboard/termion.rs @@ -27,10 +27,10 @@ impl Keyboard for TermionKeyboard { Key::Right => Some(KeyStroke::KeyRight), Key::Up => Some(KeyStroke::KeyUp), Key::Down => Some(KeyStroke::KeyDown), - Key::Home => None, - Key::End => None, Key::PageUp => Some(KeyStroke::KeyPreviousPage), Key::PageDown => Some(KeyStroke::KeyNextPage), + Key::Home => Some(KeyStroke::KeyHome), + Key::End => Some(KeyStroke::KeyEnd), Key::Delete => Some(KeyStroke::KeyDelete), Key::Insert => None, Key::F(n) => Some(KeyStroke::KeyF(n)), diff --git a/src/input_controller/mode_actions.rs b/src/input_controller/mode_actions.rs index 9affba6..3caab45 100644 --- a/src/input_controller/mode_actions.rs +++ b/src/input_controller/mode_actions.rs @@ -46,13 +46,15 @@ pub mod defaults { lazy_static! { pub static ref DEFAULT_NORMAL_MODE_ACTIONS: HashMap = { - let mut actions = HashMap::with_capacity(12); + let mut actions = HashMap::with_capacity(21); // The classic arrow keys. actions.insert(KeyStroke::KeyUp, Action::MoveUp); actions.insert(KeyStroke::KeyDown, Action::MoveDown); actions.insert(KeyStroke::KeyLeft, Action::MoveLeft); actions.insert(KeyStroke::KeyRight, Action::MoveRight); + actions.insert(KeyStroke::KeyHome, Action::MoveToLeftEndOfLine); + actions.insert(KeyStroke::KeyEnd, Action::MoveToRightEndOfLine); // The "vim like" keys. actions.insert(KeyStroke::Char('k'), Action::MoveUp); @@ -61,7 +63,7 @@ pub mod defaults { actions.insert(KeyStroke::Char('l'), Action::MoveRight); actions.insert(KeyStroke::Char('p'), Action::Paste); - actions.insert(KeyStroke::Char('q'), Action::Quite); + actions.insert(KeyStroke::Char('q'), Action::Quit); actions.insert(KeyStroke::Char('i'), Action::SwitchToInsertMode); actions.insert(KeyStroke::Char('v'), Action::SwitchToVisualMode); actions.insert(KeyStroke::KeySpace, Action::SwitchToActionMode); @@ -85,11 +87,11 @@ pub mod defaults { let mut actions = HashMap::with_capacity(3); actions.insert(KeyStroke::KeyEscape, Action::SwitchToNormalMode); - actions.insert(KeyStroke::Char('q'), Action::Quite); + actions.insert(KeyStroke::Char('q'), Action::Quit); actions.insert(KeyStroke::Char('w'), Action::WriteToFile); actions - }; + }; pub static ref DEFAULT_INSERT_MODE_ACTIONS: HashMap = { let mut actions = HashMap::with_capacity(12); @@ -103,11 +105,14 @@ pub mod defaults { actions.insert(KeyStroke::KeyDown, Action::MoveDown); actions.insert(KeyStroke::KeyLeft, Action::MoveLeft); actions.insert(KeyStroke::KeyRight, Action::MoveRight); + actions.insert(KeyStroke::KeyPreviousPage, Action::PageUp); actions.insert(KeyStroke::KeyNextPage, Action::PageDown); + actions.insert(KeyStroke::KeyHome, Action::MoveToLeftEndOfLine); + actions.insert(KeyStroke::KeyEnd, Action::MoveToRightEndOfLine); actions - }; + }; pub static ref DEFAULT_VISUAL_MODE_ACTIONS: HashMap = { let mut actions = HashMap::with_capacity(1); @@ -124,6 +129,11 @@ pub mod defaults { actions.insert(KeyStroke::KeyLeft, Action::MoveLeftAndSelect); actions.insert(KeyStroke::KeyRight, Action::MoveRightAndSelect); + actions.insert(KeyStroke::KeyPreviousPage, Action::PageUp); + actions.insert(KeyStroke::KeyNextPage, Action::PageDown); + actions.insert(KeyStroke::KeyHome, Action::MoveToLeftEndOfLineAndSelect); + actions.insert(KeyStroke::KeyEnd, Action::MoveToRightEndOfLineAndSelect); + // The "vim like" keys. actions.insert(KeyStroke::Char('k'), Action::MoveUpAndSelect); actions.insert(KeyStroke::Char('j'), Action::MoveDownAndSelect); @@ -134,6 +144,6 @@ pub mod defaults { actions.insert(KeyStroke::Char('W'), Action::MoveWordLeftAndSelect); actions - }; + }; } }