Restore buffer_picker.

pull/11/head
Blaž Hrastnik 3 years ago
parent 376232c543
commit 915fd9ebaf

@ -11,7 +11,7 @@ use once_cell::sync::Lazy;
use crate::{
compositor::{Callback, Compositor},
ui::{self, Popup, Prompt, PromptEvent},
ui::{self, Picker, Popup, Prompt, PromptEvent},
};
use std::path::PathBuf;
@ -19,7 +19,7 @@ use std::path::PathBuf;
use helix_view::{
document::Mode,
view::{View, PADDING},
Document, Editor,
Document, DocumentId, Editor,
};
use crossterm::event::{KeyCode, KeyEvent};
@ -820,10 +820,39 @@ pub fn file_picker(cx: &mut Context) {
}
pub fn buffer_picker(cx: &mut Context) {
// let documents = cx.editor.documents.iter().map(||).collect();
// (document_id, relative_path/name) mappings
// let picker = ui::buffer_picker(&documents, editor.focus);
// cx.push_layer(Box::new(picker));
use std::path::{Path, PathBuf};
let current = cx.editor.view().doc;
let picker = Picker::new(
cx.editor
.documents
.iter()
.map(|(id, doc)| (id, doc.relative_path().map(Path::to_path_buf)))
.collect(),
move |(id, path): &(DocumentId, Option<PathBuf>)| {
// format_fn
match path {
Some(path) => {
if *id == current {
format!("{} (*)", path.to_str().unwrap()).into()
} else {
path.to_str().unwrap().into()
}
}
None => "[NEW]".into(),
}
},
|editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>)| match path {
Some(path) => {
use helix_view::editor::Action;
editor
.open(path.into(), Action::Replace)
.expect("editor.open failed");
}
None => (),
},
);
cx.push_layer(Box::new(picker));
}
// calculate line numbers for each selection range

@ -20,6 +20,8 @@ pub use tui::style::{Color, Modifier, Style};
use helix_core::regex::Regex;
use helix_view::{Document, Editor};
use std::path::{Path, PathBuf};
// TODO: temp
#[inline(always)]
pub fn text_color() -> Style {
@ -75,7 +77,6 @@ pub fn regex_prompt(
)
}
use std::path::{Path, PathBuf};
pub fn file_picker(root: &str) -> Picker<PathBuf> {
use ignore::Walk;
// TODO: determine root based on git root
@ -109,36 +110,6 @@ pub fn file_picker(root: &str) -> Picker<PathBuf> {
)
}
use helix_view::View;
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 {
use crate::ui::prompt::Completion;
use std::borrow::Cow;

Loading…
Cancel
Save