@@ -11,7 +11,7 @@ use once_cell::sync::Lazy;
1111
1212use crate::{
1313 compositor::{Callback, Compositor},
14− ui::{self, Popup, Prompt, PromptEvent},
14+ ui::{self, Picker, Popup, Prompt, PromptEvent},
1515};
1616
1717use std::path::PathBuf;
@@ -19,7 +19,7 @@ use std::path::PathBuf;
1919use helix_view::{
2020 document::Mode,
2121 view::{View, PADDING},
22− Document, Editor,
22+ Document, DocumentId, Editor,
2323};
2424
2525use crossterm::event::{KeyCode, KeyEvent};
@@ -820,10 +820,39 @@ pub fn file_picker(cx: &mut Context) {
820820}
821821
822822pub fn buffer_picker(cx: &mut Context) {
823− // let documents = cx.editor.documents.iter().map(||).collect();
824− // (document_id, relative_path/name) mappings
825− // let picker = ui::buffer_picker(&documents, editor.focus);
826− // cx.push_layer(Box::new(picker));
823+ use std::path::{Path, PathBuf};
824+ let current = cx.editor.view().doc;
825+
826+ let picker = Picker::new(
827+ cx.editor
828+ .documents
829+ .iter()
830+ .map(|(id, doc)| (id, doc.relative_path().map(Path::to_path_buf)))
831+ .collect(),
832+ move |(id, path): &(DocumentId, Option<PathBuf>)| {
833+ // format_fn
834+ match path {
835+ Some(path) => {
836+ if *id == current {
837+ format!("{} (*)", path.to_str().unwrap()).into()
838+ } else {
839+ path.to_str().unwrap().into()
840+ }
841+ }
842+ None => "[NEW]".into(),
843+ }
844+ },
845+ |editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>)| match path {
846+ Some(path) => {
847+ use helix_view::editor::Action;
848+ editor
849+ .open(path.into(), Action::Replace)
850+ .expect("editor.open failed");
851+ }
852+ None => (),
853+ },
854+ );
855+ cx.push_layer(Box::new(picker));
827856}
828857
829858// calculate line numbers for each selection range