Allow switching views back to scratch buffers.

This commit is contained in:
Blaž Hrastnik 2021-05-07 14:36:06 +09:00
parent 418ee17b86
commit f2c79e245b
2 changed files with 9 additions and 12 deletions

View file

@ -930,17 +930,14 @@ pub fn buffer_picker(cx: &mut Context) {
path.into() path.into()
} }
} }
None => "[NEW]".into(), None => "[scratch buffer]".into(),
} }
}, },
|editor: &mut Editor, (_, path): &(DocumentId, Option<PathBuf>), _action| match path { |editor: &mut Editor, (id, _path): &(DocumentId, Option<PathBuf>), _action| {
Some(path) => { use helix_view::editor::Action;
use helix_view::editor::Action; editor
editor .switch(*id, Action::Replace)
.open(path.into(), Action::Replace) .expect("editor.open failed");
.expect("editor.open failed");
}
None => (),
}, },
); );
cx.push_layer(Box::new(picker)); cx.push_layer(Box::new(picker));

View file

@ -66,7 +66,7 @@ impl Editor {
} }
} }
fn _open(&mut self, id: DocumentId, action: Action) -> Result<DocumentId, Error> { pub fn switch(&mut self, id: DocumentId, action: Action) -> Result<DocumentId, Error> {
use crate::tree::Layout; use crate::tree::Layout;
use helix_core::Selection; use helix_core::Selection;
match action { match action {
@ -115,7 +115,7 @@ impl Editor {
let doc = Document::new(Rope::from("\n")); let doc = Document::new(Rope::from("\n"));
let id = self.documents.insert(doc); let id = self.documents.insert(doc);
self.documents[id].id = id; self.documents[id].id = id;
self._open(id, action) self.switch(id, action)
} }
pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> { pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Error> {
@ -159,7 +159,7 @@ impl Editor {
id id
}; };
self._open(id, action) self.switch(id, action)
} }
pub fn close(&mut self, id: ViewId) { pub fn close(&mut self, id: ViewId) {