diff options
author | Gokul Soumya | 2021-08-12 07:00:42 +0000 |
---|---|---|
committer | GitHub | 2021-08-12 07:00:42 +0000 |
commit | d84f8b5fdef71da87ee108db07ba1167fc6a769b (patch) | |
tree | 057f87cb1107aae3eb966ff3e228b15d3e36ff2e /helix-view | |
parent | 7d51805e94a461834ce34e0829da5859d1f9db32 (diff) |
Show file preview in split pane in fuzzy finder (#534)
* Add preview pane for fuzzy finder
* Fix picker preview lag by caching
* Add picker preview for document symbols
* Cache picker preview per document instead of view
* Use line instead of range for preview doc
* Add picker preview for buffer picker
* Fix render bug and refactor picker
* Refactor picker preview rendering
* Split picker and preview and compose
The current selected item is cloned on every event, which is
undesirable
* Refactor out clones in previewed picker
* Retrieve doc from editor if possible in filepicker
* Disable syntax highlight for picker preview
Files already loaded in memory have syntax highlighting enabled
* Ignore directory symlinks in file picker
* Cleanup unnecessary pubs and derives
* Remove unnecessary highlight from file picker
* Reorganize buffer rendering
* Use normal picker for code actions
* Remove unnecessary generics and trait impls
* Remove prepare_for_render and make render mutable
* Skip picker preview if screen small, less padding
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/document.rs | 10 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 13 | ||||
-rw-r--r-- | helix-view/src/view.rs | 2 |
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, |