mirror of https://github.com/helix-editor/helix
better handling of the closed buffer history
parent
56a55d784f
commit
0b967fa5d9
|
@ -330,13 +330,10 @@ fn buffer_reopen(
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
if let Some(last_closed_doc_path) = cx.editor.document_history
|
||||
.iter()
|
||||
.filter(|path| cx.editor.document_by_path(path).is_none())
|
||||
.last()
|
||||
.cloned()
|
||||
if let Some(last_closed_doc_path) = cx.editor.closed_document_paths.pop()
|
||||
{
|
||||
cx.editor.open(&last_closed_doc_path, Action::Load)?;
|
||||
let id = cx.editor.open(&last_closed_doc_path, Action::Load)?;
|
||||
cx.editor.switch(id, Action::Load);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1060,7 +1060,7 @@ pub struct Editor {
|
|||
pub tree: Tree,
|
||||
pub next_document_id: DocumentId,
|
||||
pub documents: BTreeMap<DocumentId, Document>,
|
||||
pub document_history: Vec<PathBuf>,
|
||||
pub closed_document_paths: Vec<PathBuf>,
|
||||
|
||||
// We Flatten<> to resolve the inner DocumentSavedEventFuture. For that we need a stream of streams, hence the Once<>.
|
||||
// https://stackoverflow.com/a/66875668
|
||||
|
@ -1212,7 +1212,7 @@ impl Editor {
|
|||
tree: Tree::new(area),
|
||||
next_document_id: DocumentId::default(),
|
||||
documents: BTreeMap::new(),
|
||||
document_history: Vec::new(),
|
||||
closed_document_paths: Vec::new(),
|
||||
saves: HashMap::new(),
|
||||
save_queue: SelectAll::new(),
|
||||
write_count: 0,
|
||||
|
@ -1799,7 +1799,6 @@ impl Editor {
|
|||
|
||||
let id = self.new_document(doc);
|
||||
self.launch_language_servers(id);
|
||||
self.document_history.push(path);
|
||||
|
||||
helix_event::dispatch(DocumentDidOpen {
|
||||
editor: self,
|
||||
|
@ -1872,6 +1871,9 @@ impl Editor {
|
|||
}
|
||||
|
||||
let doc = self.documents.remove(&doc_id).unwrap();
|
||||
if let Some(path) = doc.path() {
|
||||
self.closed_document_paths.push(path.clone());
|
||||
}
|
||||
|
||||
// If the document we removed was visible in all views, we will have no more views. We don't
|
||||
// want to close the editor just for a simple buffer close, so we need to create a new view
|
||||
|
|
Loading…
Reference in New Issue