diff --git a/src/app.rs b/src/app.rs index a69edb64..a7891e92 100644 --- a/src/app.rs +++ b/src/app.rs @@ -18,8 +18,7 @@ use anyhow::{anyhow, Result}; use asyncgit::{sync, AsyncNotification, CWD}; use crossbeam_channel::Sender; use crossterm::event::{Event, KeyEvent}; -use std::path::PathBuf; -use std::{cell::Cell, cell::RefCell, rc::Rc}; +use std::{cell::Cell, cell::RefCell, path::Path, rc::Rc}; use tui::{ backend::Backend, layout::{Constraint, Direction, Layout, Margin, Rect}, @@ -49,7 +48,7 @@ pub struct App { // "Flags" requires_redraw: Cell, - file_to_open: Option>, + file_to_open: Option, } // public interface @@ -202,7 +201,7 @@ impl App { let result = match self.file_to_open.take() { Some(path) => { ExternalEditorComponent::open_file_in_editor( - &path, + Path::new(&path), ) } None => self.commit.show_editor(), diff --git a/src/components/externaleditor.rs b/src/components/externaleditor.rs index 14c370ee..f580acd4 100644 --- a/src/components/externaleditor.rs +++ b/src/components/externaleditor.rs @@ -38,6 +38,10 @@ impl ExternalEditorComponent { /// opens file at given `path` in an available editor pub fn open_file_in_editor(path: &Path) -> Result<()> { + if !path.exists() { + return Err(anyhow!("file not found: {:?}", path)); + } + io::stdout().execute(LeaveAlternateScreen)?; defer! { io::stdout().execute(EnterAlternateScreen).expect("reset terminal"); diff --git a/src/queue.rs b/src/queue.rs index a4dc921a..6d1d2d46 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -1,7 +1,6 @@ use crate::tabs::StashingOptions; use asyncgit::sync::CommitId; use bitflags::bitflags; -use std::path::PathBuf; use std::{cell::RefCell, collections::VecDeque, rc::Rc}; bitflags! { @@ -50,7 +49,7 @@ pub enum InternalEvent { /// InspectCommit(CommitId), /// - OpenExternalEditor(Option>), + OpenExternalEditor(Option), } /// diff --git a/src/tabs/status.rs b/src/tabs/status.rs index bd123be2..4e3e8e17 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -18,7 +18,6 @@ use asyncgit::{ }; use crossbeam_channel::Sender; use crossterm::event::Event; -use std::path::PathBuf; use tui::layout::{Constraint, Direction, Layout}; /// @@ -389,9 +388,7 @@ impl Component for Status { { self.queue.borrow_mut().push_back( InternalEvent::OpenExternalEditor( - Some(Box::new(PathBuf::from( - path, - ))), + Some(path), ), ); }