From e3ec5e31ec005e33da4c848b4272e81a6d21a5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bla=C5=BE=20Hrastnik?= Date: Tue, 16 Mar 2021 23:05:43 +0900 Subject: [PATCH] Fix goto code before merging. --- helix-term/src/commands.rs | 4 +--- helix-view/src/editor.rs | 10 +++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 45e8cd013..3e90fb635 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -15,8 +15,6 @@ use crate::ui::{self, Popup, Prompt, PromptEvent}; use std::path::PathBuf; -use smol::Executor; - use helix_view::{ document::Mode, view::{View, PADDING}, @@ -853,6 +851,7 @@ pub fn exit_select_mode(cx: &mut Context) { } fn goto(cx: &mut Context, locations: Vec) { + let executor = cx.executor; let doc = cx.doc(); doc.mode = Mode::Normal; @@ -876,7 +875,6 @@ fn goto(cx: &mut Context, locations: Vec) { format!("{}:{}", file, line).into() }, move |editor: &mut Editor, item| { - let executor = smol::Executor::new(); editor.open(PathBuf::from(item.uri.path()), &executor); let mut doc = &mut editor.view_mut().doc; let definition_pos = item.range.start; diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 99c0398f7..5c94df274 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -33,13 +33,13 @@ impl Editor { } pub fn open(&mut self, path: PathBuf, executor: &smol::Executor) -> Result<(), Error> { - // TODO: try to find an open view/buffer first - let existing_view_option = self + let existing_view = self .tree .views() - .find(|v| path.to_str().unwrap() == v.0.doc.path().unwrap().to_str().unwrap()); - if let Some(existing_view) = existing_view_option { - self.tree.focus = existing_view.0.id; + .find(|(view, _)| view.doc.path() == Some(&path)); + + if let Some((view, _)) = existing_view { + self.tree.focus = view.id; return Ok(()); }