mirror of
https://github.com/helix-editor/helix.git
synced 2024-11-22 17:36:19 +04:00
Allow switching views back to scratch buffers.
This commit is contained in:
parent
418ee17b86
commit
f2c79e245b
@ -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<PathBuf>), _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<PathBuf>), _action| {
|
||||
use helix_view::editor::Action;
|
||||
editor
|
||||
.switch(*id, Action::Replace)
|
||||
.expect("editor.open failed");
|
||||
},
|
||||
);
|
||||
cx.push_layer(Box::new(picker));
|
||||
|
@ -66,7 +66,7 @@ fn _refresh(&mut self) {
|
||||
}
|
||||
}
|
||||
|
||||
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 helix_core::Selection;
|
||||
match action {
|
||||
@ -115,7 +115,7 @@ pub fn new_file(&mut self, action: Action) -> Result<DocumentId, Error> {
|
||||
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<DocumentId, Error> {
|
||||
@ -159,7 +159,7 @@ pub fn open(&mut self, path: PathBuf, action: Action) -> Result<DocumentId, Erro
|
||||
id
|
||||
};
|
||||
|
||||
self._open(id, action)
|
||||
self.switch(id, action)
|
||||
}
|
||||
|
||||
pub fn close(&mut self, id: ViewId) {
|
||||
|
Loading…
Reference in New Issue
Block a user