From aefafc25cd235183261efa2d59265855e0e992e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Mon, 29 Mar 2021 15:04:29 +0900 Subject: [PATCH] Replace Mode::Goto with just using on_next_key. --- helix-term/src/commands.rs | 29 +++++++++++++++++++++++------ helix-term/src/keymap.rs | 12 ------------ helix-term/src/ui/editor.rs | 2 +- helix-view/src/document.rs | 1 - 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index bc1019d5..e1a03ee1 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1032,7 +1032,24 @@ pub fn normal_mode(cx: &mut Context) { } pub fn goto_mode(cx: &mut Context) { - cx.doc().mode = Mode::Goto; + cx.on_next_key(move |cx, event| { + if let KeyEvent { + code: KeyCode::Char(ch), + .. + } = event + { + // TODO: temporarily show GOTO in the mode list + match ch { + 'g' => move_file_start(cx), + 'e' => move_file_end(cx), + 'd' => goto_definition(cx), + 't' => goto_type_definition(cx), + 'r' => goto_reference(cx), + 'i' => goto_implementation(cx), + _ => (), + } + } + }) } pub fn select_mode(cx: &mut Context) { @@ -1043,7 +1060,7 @@ pub fn exit_select_mode(cx: &mut Context) { cx.doc().mode = Mode::Normal; } -fn goto(cx: &mut Context, locations: Vec) { +fn _goto(cx: &mut Context, locations: Vec) { use helix_view::editor::Action; cx.doc().mode = Mode::Normal; @@ -1093,7 +1110,7 @@ pub fn goto_definition(cx: &mut Context) { // TODO: handle fails let res = smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default(); - goto(cx, res); + _goto(cx, res); } pub fn goto_type_definition(cx: &mut Context) { @@ -1109,7 +1126,7 @@ pub fn goto_type_definition(cx: &mut Context) { // TODO: handle fails let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos)) .unwrap_or_default(); - goto(cx, res); + _goto(cx, res); } pub fn goto_implementation(cx: &mut Context) { @@ -1125,7 +1142,7 @@ pub fn goto_implementation(cx: &mut Context) { // TODO: handle fails let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos)) .unwrap_or_default(); - goto(cx, res); + _goto(cx, res); } pub fn goto_reference(cx: &mut Context) { @@ -1141,7 +1158,7 @@ pub fn goto_reference(cx: &mut Context) { // TODO: handle fails let res = smol::block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default(); - goto(cx, res); + _goto(cx, res); } pub fn signature_help(cx: &mut Context) { diff --git a/helix-term/src/keymap.rs b/helix-term/src/keymap.rs index aa1f8cce..f401f0f9 100644 --- a/helix-term/src/keymap.rs +++ b/helix-term/src/keymap.rs @@ -316,17 +316,5 @@ pub fn default() -> Keymaps { ctrl!('x') => commands::completion, ), - Mode::Goto => hashmap!( - Key { - code: KeyCode::Esc, - modifiers: Modifiers::NONE - } => commands::normal_mode as Command, - key!('g') => commands::move_file_start, - key!('e') => commands::move_file_end, - key!('d') => commands::goto_definition, - key!('t') => commands::goto_type_definition, - key!('r') => commands::goto_reference, - key!('i') => commands::goto_implementation, - ), ) } diff --git a/helix-term/src/ui/editor.rs b/helix-term/src/ui/editor.rs index f55411b8..bd0398a2 100644 --- a/helix-term/src/ui/editor.rs +++ b/helix-term/src/ui/editor.rs @@ -37,6 +37,7 @@ impl EditorView { on_next_key: None, } } + pub fn render_view( &self, doc: &Document, @@ -385,7 +386,6 @@ impl EditorView { Mode::Insert => "INS", Mode::Select => "SEL", Mode::Normal => "NOR", - Mode::Goto => "GOTO", }; // TODO: share text_color styles inside theme let text_color = if is_focused { diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 0ab8abbb..231c10bc 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -15,7 +15,6 @@ pub enum Mode { Normal, Select, Insert, - Goto, } pub struct Document {