aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/document.rs10
-rw-r--r--helix-view/src/editor.rs13
-rw-r--r--helix-view/src/view.rs2
3 files changed, 19 insertions, 6 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs
index 99faebec..8730bef2 100644
--- a/helix-view/src/document.rs
+++ b/helix-view/src/document.rs
@@ -432,14 +432,14 @@ impl Document {
/// Create a new document from `path`. Encoding is auto-detected, but it can be manually
/// overwritten with the `encoding` parameter.
pub fn open(
- path: PathBuf,
+ path: &Path,
encoding: Option<&'static encoding_rs::Encoding>,
theme: Option<&Theme>,
config_loader: Option<&syntax::Loader>,
) -> Result<Self, Error> {
let (rope, encoding) = if path.exists() {
let mut file =
- std::fs::File::open(&path).context(format!("unable to open {:?}", path))?;
+ 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);
@@ -449,7 +449,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(path)?;
if let Some(loader) = config_loader {
doc.detect_language(theme, loader);
}
@@ -904,6 +904,10 @@ impl Document {
&self.selections[&view_id]
}
+ pub fn selections(&self) -> &HashMap<ViewId, Selection> {
+ &self.selections
+ }
+
pub fn relative_path(&self) -> Option<PathBuf> {
let cwdir = std::env::current_dir().expect("couldn't determine current directory");
diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs
index 9b7f8429..413b7913 100644
--- a/helix-view/src/editor.rs
+++ b/helix-view/src/editor.rs
@@ -7,7 +7,11 @@ use crate::{
};
use futures_util::future;
-use std::{path::PathBuf, sync::Arc, time::Duration};
+use std::{
+ path::{Path, PathBuf},
+ sync::Arc,
+ time::Duration,
+};
use slotmap::SlotMap;
@@ -222,7 +226,7 @@ impl Editor {
let id = if let Some(id) = id {
id
} else {
- let mut doc = Document::open(path, None, Some(&self.theme), Some(&self.syn_loader))?;
+ let mut doc = Document::open(&path, None, Some(&self.theme), Some(&self.syn_loader))?;
// try to find a language server based on the language name
let language_server = doc
@@ -316,6 +320,11 @@ impl Editor {
self.documents.iter_mut().map(|(_id, doc)| doc)
}
+ pub fn document_by_path<P: AsRef<Path>>(&self, path: P) -> Option<&Document> {
+ self.documents()
+ .find(|doc| doc.path().map(|p| p == path.as_ref()).unwrap_or(false))
+ }
+
// pub fn current_document(&self) -> Document {
// let id = self.view().doc;
// let doc = &mut editor.documents[id];
diff --git a/helix-view/src/view.rs b/helix-view/src/view.rs
index 265f7df8..c7309fe9 100644
--- a/helix-view/src/view.rs
+++ b/helix-view/src/view.rs
@@ -10,7 +10,7 @@ use helix_core::{
type Jump = (DocumentId, Selection);
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub struct JumpList {
jumps: Vec<Jump>,
current: usize,