Allow opening of non-existant files, fixes #434
This commit is contained in:
parent
d795b1fca4
commit
bce1d2aebc
3 changed files with 130 additions and 146 deletions
13
src/main.rs
13
src/main.rs
|
|
@ -31,7 +31,7 @@ use std::{
|
|||
any::TypeId,
|
||||
collections::HashMap,
|
||||
env, fs, io,
|
||||
path::{Path, PathBuf},
|
||||
path::{self, Path, PathBuf},
|
||||
process,
|
||||
sync::{Mutex, OnceLock},
|
||||
};
|
||||
|
|
@ -648,10 +648,13 @@ impl App {
|
|||
Some(path) => {
|
||||
let canonical = match fs::canonicalize(&path) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => {
|
||||
log::error!("failed to canonicalize {:?}: {}", path, err);
|
||||
return None;
|
||||
}
|
||||
Err(err) => match path::absolute(&path) {
|
||||
Ok(ok) => ok,
|
||||
Err(_) => {
|
||||
log::error!("failed to canonicalize {:?}: {}", path, err);
|
||||
return None;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
//TODO: allow files to be open multiple times
|
||||
|
|
|
|||
36
src/tab.rs
36
src/tab.rs
|
|
@ -10,8 +10,8 @@ use notify::Watcher;
|
|||
use regex::Regex;
|
||||
use std::{
|
||||
fs,
|
||||
io::Write,
|
||||
path::PathBuf,
|
||||
io::{self, Write},
|
||||
path::{self, PathBuf},
|
||||
process::{Command, Stdio},
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
|
@ -101,20 +101,30 @@ impl EditorTab {
|
|||
let mut editor = self.editor.lock().unwrap();
|
||||
let mut font_system = font_system().write().unwrap();
|
||||
let mut editor = editor.borrow_with(font_system.raw());
|
||||
match editor.load_text(&path, self.attrs.clone()) {
|
||||
let absolute = match fs::canonicalize(&path) {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => match path::absolute(&path) {
|
||||
Ok(ok) => ok,
|
||||
Err(_) => {
|
||||
log::error!("failed to canonicalize {:?}: {}", path, err);
|
||||
path
|
||||
}
|
||||
},
|
||||
};
|
||||
match editor.load_text(&absolute, self.attrs.clone()) {
|
||||
Ok(()) => {
|
||||
log::info!("opened {:?}", path);
|
||||
self.path_opt = match fs::canonicalize(&path) {
|
||||
Ok(ok) => Some(ok),
|
||||
Err(err) => {
|
||||
log::error!("failed to canonicalize {:?}: {}", path, err);
|
||||
Some(path)
|
||||
}
|
||||
};
|
||||
log::info!("opened {:?}", absolute);
|
||||
self.path_opt = Some(absolute);
|
||||
}
|
||||
Err(err) => {
|
||||
log::error!("failed to open {:?}: {}", path, err);
|
||||
self.path_opt = None;
|
||||
if err.kind() == io::ErrorKind::NotFound {
|
||||
log::warn!("opened non-existant file {:?}", absolute);
|
||||
self.path_opt = Some(absolute);
|
||||
editor.set_changed(true);
|
||||
} else {
|
||||
log::error!("failed to open {:?}: {}", absolute, err);
|
||||
self.path_opt = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue