mirror of https://github.com/helix-editor/helix
Replace Mode::Goto with just using on_next_key.
parent
1d96cbfbd2
commit
aefafc25cd
|
@ -1032,7 +1032,24 @@ pub fn normal_mode(cx: &mut Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn goto_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) {
|
pub fn select_mode(cx: &mut Context) {
|
||||||
|
@ -1043,7 +1060,7 @@ pub fn exit_select_mode(cx: &mut Context) {
|
||||||
cx.doc().mode = Mode::Normal;
|
cx.doc().mode = Mode::Normal;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
|
fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
|
||||||
use helix_view::editor::Action;
|
use helix_view::editor::Action;
|
||||||
cx.doc().mode = Mode::Normal;
|
cx.doc().mode = Mode::Normal;
|
||||||
|
|
||||||
|
@ -1093,7 +1110,7 @@ pub fn goto_definition(cx: &mut Context) {
|
||||||
// TODO: handle fails
|
// TODO: handle fails
|
||||||
let res =
|
let res =
|
||||||
smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
|
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) {
|
pub fn goto_type_definition(cx: &mut Context) {
|
||||||
|
@ -1109,7 +1126,7 @@ pub fn goto_type_definition(cx: &mut Context) {
|
||||||
// TODO: handle fails
|
// TODO: handle fails
|
||||||
let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
|
let res = smol::block_on(language_server.goto_type_definition(doc.identifier(), pos))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
goto(cx, res);
|
_goto(cx, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn goto_implementation(cx: &mut Context) {
|
pub fn goto_implementation(cx: &mut Context) {
|
||||||
|
@ -1125,7 +1142,7 @@ pub fn goto_implementation(cx: &mut Context) {
|
||||||
// TODO: handle fails
|
// TODO: handle fails
|
||||||
let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
|
let res = smol::block_on(language_server.goto_implementation(doc.identifier(), pos))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
goto(cx, res);
|
_goto(cx, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn goto_reference(cx: &mut Context) {
|
pub fn goto_reference(cx: &mut Context) {
|
||||||
|
@ -1141,7 +1158,7 @@ pub fn goto_reference(cx: &mut Context) {
|
||||||
// TODO: handle fails
|
// TODO: handle fails
|
||||||
let res =
|
let res =
|
||||||
smol::block_on(language_server.goto_reference(doc.identifier(), pos)).unwrap_or_default();
|
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) {
|
pub fn signature_help(cx: &mut Context) {
|
||||||
|
|
|
@ -316,17 +316,5 @@ pub fn default() -> Keymaps {
|
||||||
|
|
||||||
ctrl!('x') => commands::completion,
|
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,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ impl EditorView {
|
||||||
on_next_key: None,
|
on_next_key: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_view(
|
pub fn render_view(
|
||||||
&self,
|
&self,
|
||||||
doc: &Document,
|
doc: &Document,
|
||||||
|
@ -385,7 +386,6 @@ impl EditorView {
|
||||||
Mode::Insert => "INS",
|
Mode::Insert => "INS",
|
||||||
Mode::Select => "SEL",
|
Mode::Select => "SEL",
|
||||||
Mode::Normal => "NOR",
|
Mode::Normal => "NOR",
|
||||||
Mode::Goto => "GOTO",
|
|
||||||
};
|
};
|
||||||
// TODO: share text_color styles inside theme
|
// TODO: share text_color styles inside theme
|
||||||
let text_color = if is_focused {
|
let text_color = if is_focused {
|
||||||
|
|
|
@ -15,7 +15,6 @@ pub enum Mode {
|
||||||
Normal,
|
Normal,
|
||||||
Select,
|
Select,
|
||||||
Insert,
|
Insert,
|
||||||
Goto,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Document {
|
pub struct Document {
|
||||||
|
|
Loading…
Reference in New Issue