@@ -34,6 +34,14 @@ impl Editor {
3434
3535 pub fn open(&mut self, path: PathBuf, executor: &smol::Executor) -> Result<(), Error> {
3636 // TODO: try to find an open view/buffer first
37+ let existing_view_option = self
38+ .tree
39+ .views()
40+ .find(|v| path.to_str().unwrap() == v.0.doc.path().unwrap().to_str().unwrap());
41+ if let Some(existing_view) = existing_view_option {
42+ self.tree.focus = existing_view.0.id;
43+ return Ok(());
44+ }
3745
3846 let mut doc = Document::load(path, self.theme.scopes())?;
3947
@@ -62,15 +70,7 @@ impl Editor {
6270 }
6371
6472 let view = View::new(doc)?;
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− }
73+ self.tree.insert(view);
7474 Ok(())
7575 }
7676