aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/ui/mod.rs
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-03-23 08:47:40 +0000
committerBlaž Hrastnik2021-03-23 09:14:35 +0000
commit8328fe926d34d12031cb50db47a9dd39ed681a84 (patch)
treeacea128c5a3c2276f7ad553666a6572a5ba7d62d /helix-term/src/ui/mod.rs
parent3f9a94fd4364fe277f11668b0bfab4f2735c4daf (diff)
Drop refcell use, make view simply ref doc.id.
Diffstat (limited to 'helix-term/src/ui/mod.rs')
-rw-r--r--helix-term/src/ui/mod.rs71
1 files changed, 35 insertions, 36 deletions
diff --git a/helix-term/src/ui/mod.rs b/helix-term/src/ui/mod.rs
index cb1b36fa..f91a9f35 100644
--- a/helix-term/src/ui/mod.rs
+++ b/helix-term/src/ui/mod.rs
@@ -40,7 +40,8 @@ pub fn regex_prompt(
match event {
PromptEvent::Abort => {
// TODO: also revert text
- let doc = &mut editor.view().doc.borrow_mut();
+ let id = editor.view().doc;
+ let doc = &mut editor.documents[id];
doc.set_selection(snapshot.clone());
}
PromptEvent::Validate => {
@@ -54,18 +55,17 @@ pub fn regex_prompt(
match Regex::new(input) {
Ok(regex) => {
- let view = &mut editor.view_mut();
- let mut doc = view.doc.borrow_mut();
+ // let view = &mut editor.view_mut();
+ let id = editor.view().doc;
+ let doc = &mut editor.documents[id];
// revert state to what it was before the last update
// TODO: also revert text
doc.set_selection(snapshot.clone());
- fun(&mut doc, regex);
+ fun(doc, regex);
- drop(doc);
-
- view.ensure_cursor_in_view();
+ editor.ensure_cursor_in_view(editor.view().id);
}
Err(_err) => (), // TODO: mark command line as error
}
@@ -101,40 +101,39 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> {
path.strip_prefix("./").unwrap().to_str().unwrap().into()
},
move |editor: &mut Editor, path: &PathBuf| {
- editor.open(path.into());
+ let document_id = editor.open(path.into()).expect("editor.open failed");
},
)
}
use helix_view::View;
-pub fn buffer_picker(views: &[View], current: usize) -> Picker<(Option<PathBuf>, usize)> {
- unimplemented!();
- // use helix_view::Editor;
- // Picker::new(
- // views
- // .iter()
- // .enumerate()
- // .map(|(i, view)| (view.doc.relative_path().map(Path::to_path_buf), i))
- // .collect(),
- // move |(path, index): &(Option<PathBuf>, usize)| {
- // // format_fn
- // match path {
- // Some(path) => {
- // if *index == current {
- // format!("{} (*)", path.to_str().unwrap()).into()
- // } else {
- // path.to_str().unwrap().into()
- // }
- // }
- // None => "[NEW]".into(),
- // }
- // },
- // |editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
- // if index < editor.views.len() {
- // editor.focus = index;
- // }
- // },
- // )
+pub fn buffer_picker(buffers: &[Document], current: usize) -> Picker<(Option<PathBuf>, usize)> {
+ use helix_view::Editor;
+ Picker::new(
+ buffers
+ .iter()
+ .enumerate()
+ .map(|(i, doc)| (doc.relative_path().map(Path::to_path_buf), i))
+ .collect(),
+ move |(path, index): &(Option<PathBuf>, usize)| {
+ // format_fn
+ match path {
+ Some(path) => {
+ if *index == current {
+ format!("{} (*)", path.to_str().unwrap()).into()
+ } else {
+ path.to_str().unwrap().into()
+ }
+ }
+ None => "[NEW]".into(),
+ }
+ },
+ |editor: &mut Editor, &(_, index): &(Option<PathBuf>, usize)| {
+ // if index < editor.views.len() {
+ // editor.focus = index;
+ // }
+ },
+ )
}
pub mod completers {