pull/13568/merge
Taylor Plewe 2025-06-16 09:06:33 -06:00 committed by GitHub
commit 5076126aa1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 1 deletions

View File

@ -321,6 +321,21 @@ fn buffer_previous(
Ok(())
}
fn buffer_reopen(
cx: &mut compositor::Context,
_args: Args,
event: PromptEvent,
) -> anyhow::Result<()> {
if event != PromptEvent::Validate {
return Ok(());
}
if let Some(last_closed_doc_path) = cx.editor.closed_document_paths.pop() {
cx.editor.open(&last_closed_doc_path, Action::Replace)?;
}
Ok(())
}
fn write_impl(cx: &mut compositor::Context, path: Option<&str>, force: bool) -> anyhow::Result<()> {
let config = cx.editor.config();
let jobs = &mut cx.jobs;
@ -2703,6 +2718,17 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
..Signature::DEFAULT
},
},
TypableCommand {
name: "buffer-reopen",
aliases: &["br", "breopen"],
doc: "Re-open the most previously closed buffer.",
fun: buffer_reopen,
completer: CommandCompleter::none(),
signature: Signature {
positionals: (0, Some(0)),
..Signature::DEFAULT
},
},
TypableCommand {
name: "write",
aliases: &["w"],

View File

@ -1067,6 +1067,7 @@ pub struct Editor {
pub tree: Tree,
pub next_document_id: DocumentId,
pub documents: BTreeMap<DocumentId, Document>,
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
@ -1218,6 +1219,7 @@ impl Editor {
tree: Tree::new(area),
next_document_id: DocumentId::default(),
documents: BTreeMap::new(),
closed_document_paths: Vec::new(),
saves: HashMap::new(),
save_queue: SelectAll::new(),
write_count: 0,
@ -1880,6 +1882,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