diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index eab9397ca..5c1021e10 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -930,17 +930,14 @@ pub fn buffer_picker(cx: &mut Context) { path.into() } } - None => "[NEW]".into(), + None => "[scratch buffer]".into(), } }, - |editor: &mut Editor, (_, path): &(DocumentId, Option), _action| match path { - Some(path) => { - use helix_view::editor::Action; - editor - .open(path.into(), Action::Replace) - .expect("editor.open failed"); - } - None => (), + |editor: &mut Editor, (id, _path): &(DocumentId, Option), _action| { + use helix_view::editor::Action; + editor + .switch(*id, Action::Replace) + .expect("editor.open failed"); }, ); cx.push_layer(Box::new(picker)); diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 84d499e30..256e0e83a 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -66,7 +66,7 @@ fn _refresh(&mut self) { } } - fn _open(&mut self, id: DocumentId, action: Action) -> Result { + pub fn switch(&mut self, id: DocumentId, action: Action) -> Result { use crate::tree::Layout; use helix_core::Selection; match action { @@ -115,7 +115,7 @@ pub fn new_file(&mut self, action: Action) -> Result { let doc = Document::new(Rope::from("\n")); let id = self.documents.insert(doc); self.documents[id].id = id; - self._open(id, action) + self.switch(id, action) } pub fn open(&mut self, path: PathBuf, action: Action) -> Result { @@ -159,7 +159,7 @@ pub fn open(&mut self, path: PathBuf, action: Action) -> Result