on master help sign in
commands: Simplify _goto.
0083a6cBlaž Hrastnik
helix-term/src/commands.rs+18−23
@@ -240,8 +240,6 @@ pub fn move_next_word_end(cx: &mut Context) {
240pub fn move_file_start(cx: &mut Context) {
240pub fn move_file_start(cx: &mut Context) {
241 let doc = cx.doc();
241 let doc = cx.doc();
242 doc.set_selection(Selection::point(0));
242 doc.set_selection(Selection::point(0));
243−
244− doc.mode = Mode::Normal;
245}
243}
246
244
247pub fn move_file_end(cx: &mut Context) {
245pub fn move_file_end(cx: &mut Context) {
@@ -249,8 +247,6 @@ pub fn move_file_end(cx: &mut Context) {
249 let text = doc.text();
247 let text = doc.text();
250 let last_line = text.line_to_char(text.len_lines().saturating_sub(2));
248 let last_line = text.line_to_char(text.len_lines().saturating_sub(2));
251 doc.set_selection(Selection::point(last_line));
249 doc.set_selection(Selection::point(last_line));
252−
253− doc.mode = Mode::Normal;
254}
250}
255
251
256pub fn extend_next_word_start(cx: &mut Context) {
252pub fn extend_next_word_start(cx: &mut Context) {
@@ -1072,35 +1068,31 @@ pub fn exit_select_mode(cx: &mut Context) {
1072
1068
1073fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
1069fn _goto(cx: &mut Context, locations: Vec<lsp::Location>) {
1074 use helix_view::editor::Action;
1070 use helix_view::editor::Action;
1075− cx.doc().mode = Mode::Normal;
1071+
1072+ fn jump_to(editor: &mut Editor, location: &lsp::Location, action: Action) {
1073+ let id = editor
1074+ .open(PathBuf::from(location.uri.path()), action)
1075+ .expect("editor.open failed");
1076+ let doc = &mut editor.documents[id];
1077+ let definition_pos = location.range.start;
1078+ let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);
1079+ doc.set_selection(Selection::point(new_pos));
1080+ }
1076
1081
1077 match locations.as_slice() {
1082 match locations.as_slice() {
1078 [location] => {
1083 [location] => {
1079− cx.editor
1080− .open(PathBuf::from(location.uri.path()), Action::Replace);
1084+ jump_to(cx.editor, location, Action::Replace);
1081− let doc = cx.doc();
1082− let definition_pos = location.range.start;
1083− let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);
1084− doc.set_selection(Selection::point(new_pos));
1085 }
1085 }
1086 [] => (), // maybe show user message that no definition was found?
1086 [] => (), // maybe show user message that no definition was found?
1087 _locations => {
1087 _locations => {
1088 let mut picker = ui::Picker::new(
1088 let mut picker = ui::Picker::new(
1089 locations,
1089 locations,
1090− |item| {
1090+ |location| {
1091− let file = item.uri.as_str();
1091+ let file = location.uri.as_str();
1092− let line = item.range.start.line;
1092+ let line = location.range.start.line;
1093 format!("{}:{}", file, line).into()
1093 format!("{}:{}", file, line).into()
1094 },
1094 },
1095− move |editor: &mut Editor, item, action| {
1095+ move |editor: &mut Editor, location, action| jump_to(editor, location, action),
1096− let id = editor
1097− .open(PathBuf::from(item.uri.path()), action)
1098− .expect("editor.open failed");
1099− let doc = &mut editor.documents[id];
1100− let definition_pos = item.range.start;
1101− let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text(), definition_pos);
1102− doc.set_selection(Selection::point(new_pos));
1103− },
1104 );
1096 );
1105 cx.push_layer(Box::new(picker));
1097 cx.push_layer(Box::new(picker));
1106 }
1098 }
@@ -1797,5 +1789,8 @@ pub fn jump_backward(cx: &mut Context) {
1797 if let Some((id, selection)) = view.jumps.backward(count) {
1789 if let Some((id, selection)) = view.jumps.backward(count) {
1798 view.first_line = 0;
1790 view.first_line = 0;
1799 view.doc = *id;
1791 view.doc = *id;
1792+ let selection = selection.clone();
1793+ let doc = cx.doc();
1794+ doc.set_selection(selection);
1800 };
1795 };
1801}
1796}