Skip to content

Commit 540997c

Browse files
author
Stephan Dilly
committed
error if file to be opened in external editor will not be found (#184)
1 parent abe3b48 commit 540997c

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

Diff for: src/app.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use anyhow::{anyhow, Result};
1818
use asyncgit::{sync, AsyncNotification, CWD};
1919
use crossbeam_channel::Sender;
2020
use crossterm::event::{Event, KeyEvent};
21-
use std::path::PathBuf;
22-
use std::{cell::Cell, cell::RefCell, rc::Rc};
21+
use std::{cell::Cell, cell::RefCell, path::Path, rc::Rc};
2322
use tui::{
2423
backend::Backend,
2524
layout::{Constraint, Direction, Layout, Margin, Rect},
@@ -49,7 +48,7 @@ pub struct App {
4948

5049
// "Flags"
5150
requires_redraw: Cell<bool>,
52-
file_to_open: Option<Box<PathBuf>>,
51+
file_to_open: Option<String>,
5352
}
5453

5554
// public interface
@@ -202,7 +201,7 @@ impl App {
202201
let result = match self.file_to_open.take() {
203202
Some(path) => {
204203
ExternalEditorComponent::open_file_in_editor(
205-
&path,
204+
Path::new(&path),
206205
)
207206
}
208207
None => self.commit.show_editor(),

Diff for: src/components/externaleditor.rs

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ impl ExternalEditorComponent {
3838

3939
/// opens file at given `path` in an available editor
4040
pub fn open_file_in_editor(path: &Path) -> Result<()> {
41+
if !path.exists() {
42+
return Err(anyhow!("file not found: {:?}", path));
43+
}
44+
4145
io::stdout().execute(LeaveAlternateScreen)?;
4246
defer! {
4347
io::stdout().execute(EnterAlternateScreen).expect("reset terminal");

Diff for: src/queue.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::tabs::StashingOptions;
22
use asyncgit::sync::CommitId;
33
use bitflags::bitflags;
4-
use std::path::PathBuf;
54
use std::{cell::RefCell, collections::VecDeque, rc::Rc};
65

76
bitflags! {
@@ -50,7 +49,7 @@ pub enum InternalEvent {
5049
///
5150
InspectCommit(CommitId),
5251
///
53-
OpenExternalEditor(Option<Box<PathBuf>>),
52+
OpenExternalEditor(Option<String>),
5453
}
5554

5655
///

Diff for: src/tabs/status.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use asyncgit::{
1818
};
1919
use crossbeam_channel::Sender;
2020
use crossterm::event::Event;
21-
use std::path::PathBuf;
2221
use tui::layout::{Constraint, Direction, Layout};
2322

2423
///
@@ -389,9 +388,7 @@ impl Component for Status {
389388
{
390389
self.queue.borrow_mut().push_back(
391390
InternalEvent::OpenExternalEditor(
392-
Some(Box::new(PathBuf::from(
393-
path,
394-
))),
391+
Some(path),
395392
),
396393
);
397394
}

0 commit comments

Comments
 (0)