on master help sign in
editor.open now checks if view already exists
commit4e461bea2f4cc19d0d25a62a4f278420c074b6e9 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateMon 15 Mar 2021, 21:12 (6 years ago) parent0828d1f
2 files changed+17−8
helix-term/src/commands.rs+8−7 helix-view/src/editor.rs+9−1
helix-term/src/commands.rs+8−7
@@ -852,7 +852,7 @@ pub fn exit_select_mode(cx: &mut Context) {
852852 cx.doc().mode = Mode::Normal;
853853}
854854
855−fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) {
855+fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
856856 let doc = cx.doc();
857857
858858 doc.mode = Mode::Normal;
@@ -878,8 +878,9 @@ fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) {
878878 format!("{}:{}", file, line).into()
879879 },
880880 move |editor: &mut Editor, item| {
881− cx.editor.open(PathBuf::from(item.uri.path()), cx.executor);
882− let doc = cx.doc();
881+ let executor = smol::Executor::new();
882+ editor.open(PathBuf::from(item.uri.path()), &executor);
883+ let mut doc = &mut editor.view_mut().doc;
883884 let definition_pos = item.range.start;
884885 let new_pos =
885886 helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
@@ -891,7 +892,7 @@ fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) {
891892 }
892893}
893894
894−pub fn goto_definition(cx: &'static mut Context<'static>) {
895+pub fn goto_definition(cx: &mut Context) {
895896 let doc = cx.doc();
896897 let language_server = match doc.language_server.as_ref() {
897898 Some(language_server) => language_server,
@@ -907,7 +908,7 @@ pub fn goto_definition(cx: &'static mut Context<'static>) {
907908 goto(cx, res);
908909}
909910
910−pub fn goto_type_definition(cx: &'static mut Context<'static>) {
911+pub fn goto_type_definition(cx: &mut Context) {
911912 let doc = cx.doc();
912913 let language_server = match doc.language_server.as_ref() {
913914 Some(language_server) => language_server,
@@ -923,7 +924,7 @@ pub fn goto_type_definition(cx: &'static mut Context<'static>) {
923924 goto(cx, res);
924925}
925926
926−pub fn goto_implementation(cx: &'static mut Context<'static>) {
927+pub fn goto_implementation(cx: &mut Context) {
927928 let doc = cx.doc();
928929 let language_server = match doc.language_server.as_ref() {
929930 Some(language_server) => language_server,
@@ -939,7 +940,7 @@ pub fn goto_implementation(cx: &'static mut Context<'static>) {
939940 goto(cx, res);
940941}
941942
942−pub fn goto_reference(cx: &'static mut Context<'static>) {
943+pub fn goto_reference(cx: &mut Context) {
943944 let doc = cx.doc();
944945 let language_server = match doc.language_server.as_ref() {
945946 Some(language_server) => language_server,
helix-view/src/editor.rs+9−1
@@ -62,7 +62,15 @@ impl Editor {
6262 }
6363
6464 let view = View::new(doc)?;
65− self.tree.insert(view);
65+ let existing_view_option = self
66+ .tree
67+ .views()
68+ .find(|v| view.doc.path().unwrap().to_str() == v.0.doc.path().unwrap().to_str());
69+ if let Some(existing_view) = existing_view_option {
70+ self.tree.focus = existing_view.0.id;
71+ } else {
72+ self.tree.insert(view);
73+ }
6674 Ok(())
6775 }
6876