summaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorNathan Vegdahl2021-07-17 17:49:03 +0000
committerNathan Vegdahl2021-07-17 17:49:03 +0000
commita77274e8bb33ff08f5411ec4df168b576c0c8fa5 (patch)
tree1a1c3735e1f9ea46e87f7fe60b1f81fdb2e5df5b /helix-view
parentb4c59b444cc4963f95a95fe10f166e58ef857288 (diff)
parent6cba62b49917fde7c5876a1cce9d3883c6bef6c9 (diff)
Merge branch 'master' into great_line_ending_and_cursor_range_cleanup
Diffstat (limited to 'helix-view')
-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);