aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs14
-rw-r--r--helix-view/src/editor.rs20
2 files changed, 19 insertions, 15 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index b917b902..a04af94d 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -456,14 +456,16 @@ impl Document {
theme: Option<&Theme>,
config_loader: Option<&syntax::Loader>,
) -> Result<Self, Error> {
- if !path.exists() {
- return Ok(Self::default());
- }
+ let (mut rope, encoding) = if path.exists() {
+ let mut file =
+ std::fs::File::open(&path).context(format!("unable to open {:?}", path))?;
+ from_reader(&mut file, encoding)?
+ } else {
+ let encoding = encoding.unwrap_or(encoding_rs::UTF_8);
+ (Rope::from(DEFAULT_LINE_ENDING.as_str()), encoding)
+ };
- let mut file = std::fs::File::open(&path).context(format!("unable to open {:?}", path))?;
- let (mut rope, encoding) = from_reader(&mut file, encoding)?;
let line_ending = with_line_ending(&mut rope);
-
let mut doc = Self::from(rope, Some(encoding));
// set the path and try detecting the language
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 4f01cce4..cd9d0a92 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -39,6 +39,7 @@ pub struct Editor {
#[derive(Debug, Copy, Clone)]
pub enum Action {
+ Load,
Replace,
HorizontalSplit,
VerticalSplit,
@@ -97,16 +98,14 @@ impl Editor {
self._refresh();
}
- pub fn set_theme_from_name(&mut self, theme: &str) {
- let theme = match self.theme_loader.load(theme.as_ref()) {
- Ok(theme) => theme,
- Err(e) => {
- log::warn!("failed setting theme `{}` - {}", theme, e);
- return;
- }
- };
-
+ pub fn set_theme_from_name(&mut self, theme: &str) -> anyhow::Result<()> {
+ use anyhow::Context;
+ let theme = self
+ .theme_loader
+ .load(theme.as_ref())
+ .with_context(|| format!("failed setting theme `{}`", theme))?;
self.set_theme(theme);
+ Ok(())
}
fn _refresh(&mut self) {
@@ -153,6 +152,9 @@ impl Editor {
return;
}
+ Action::Load => {
+ return;
+ }
Action::HorizontalSplit => {
let view = View::new(id);
let view_id = self.tree.split(view, Layout::Horizontal);