aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorOmnikar2021-10-28 01:23:46 +0000
committerGitHub2021-10-28 01:23:46 +0000
commite2ed6915373adf27881325ebc4e2c6b98e207af3 (patch)
tree85c89248d6ff0cc76f52f7edfed9495fb8cd2da9 /helix-view
parent3b0c5e993a18a2d59582855784189995c7960d6f (diff)
Implement `hx --tutor` and `:tutor` to load `tutor.txt` (#898)
* Implement `hx --tutor` and `:tutor` to load `tutor.txt` * Document `hx --tutor` and `:tutor` * Change `Document::set_path` to take an `Option` * `Document::set_path` accepts an `Option<&Path>` instead of `&Path`. * Remove `Editor::open_tutor` and make tutor-open functionality use `Editor::open` and `Document::set_path`. * Use `PathBuf::join` Co-authored-by: Ivan Tham <pickfire@riseup.net> * Add comments explaining unsetting tutor path Co-authored-by: Ivan Tham <pickfire@riseup.net>
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/document.rs12
1 files changed, 8 insertions, 4 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index b0257f03..4d779656 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -368,7 +368,7 @@ impl Document {
let mut doc = Self::from(rope, Some(encoding));
// set the path and try detecting the language
- doc.set_path(path)?;
+ doc.set_path(Some(path))?;
if let Some(loader) = config_loader {
doc.detect_language(theme, loader);
}
@@ -553,12 +553,16 @@ impl Document {
self.encoding
}
- pub fn set_path(&mut self, path: &Path) -> Result<(), std::io::Error> {
- let path = helix_core::path::get_canonicalized_path(path)?;
+ pub fn set_path(&mut self, path: Option<&Path>) -> Result<(), std::io::Error> {
+ let path = if let Some(p) = path {
+ Some(helix_core::path::get_canonicalized_path(p)?)
+ } else {
+ path.map(|p| p.into())
+ };
// if parent doesn't exist we still want to open the document
// and error out when document is saved
- self.path = Some(path);
+ self.path = path;
Ok(())
}