Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'helix-term/src/application.rs')
-rw-r--r--helix-term/src/application.rs38
1 files changed, 25 insertions, 13 deletions
diff --git a/helix-term/src/application.rs b/helix-term/src/application.rs
index f71eed20..9adc764c 100644
--- a/helix-term/src/application.rs
+++ b/helix-term/src/application.rs
@@ -9,7 +9,7 @@ use helix_lsp::{
use helix_stdx::path::get_relative_path;
use helix_view::{
align_view,
- document::DocumentSavedEventResult,
+ document::{DocumentOpenError, DocumentSavedEventResult},
editor::{ConfigEvent, EditorEvent},
graphics::Rect,
theme,
@@ -186,9 +186,15 @@ impl Application {
Some(Layout::Horizontal) => Action::HorizontalSplit,
None => Action::Load,
};
- let doc_id = editor
- .open(&file, action)
- .context(format!("open '{}'", file.to_string_lossy()))?;
+ let doc_id = match editor.open(&file, action) {
+ // Ignore irregular files during application init.
+ Err(DocumentOpenError::IrregularFile) => {
+ nr_of_files -= 1;
+ continue;
+ }
+ Err(err) => return Err(anyhow::anyhow!(err)),
+ Ok(doc_id) => doc_id,
+ };
// with Action::Load all documents have the same view
// NOTE: this isn't necessarily true anymore. If
// `--vsplit` or `--hsplit` are used, the file which is
@@ -199,15 +205,21 @@ impl Application {
doc.set_selection(view_id, pos);
}
}
- editor.set_status(format!(
- "Loaded {} file{}.",
- nr_of_files,
- if nr_of_files == 1 { "" } else { "s" } // avoid "Loaded 1 files." grammo
- ));
- // align the view to center after all files are loaded,
- // does not affect views without pos since it is at the top
- let (view, doc) = current!(editor);
- align_view(doc, view, Align::Center);
+
+ // if all files were invalid, replace with empty buffer
+ if nr_of_files == 0 {
+ editor.new_file(Action::VerticalSplit);
+ } else {
+ editor.set_status(format!(
+ "Loaded {} file{}.",
+ nr_of_files,
+ if nr_of_files == 1 { "" } else { "s" } // avoid "Loaded 1 files." grammo
+ ));
+ // align the view to center after all files are loaded,
+ // does not affect views without pos since it is at the top
+ let (view, doc) = current!(editor);
+ align_view(doc, view, Align::Center);
+ }
} else {
editor.new_file(Action::VerticalSplit);
}