mirror of https://github.com/helix-editor/helix
Merge 749c16b9e9
into 362e97e927
commit
5076126aa1
|
@ -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"],
|
||||
|
|
|
@ -1067,7 +1067,8 @@ 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
|
||||
pub saves: HashMap<DocumentId, UnboundedSender<Once<DocumentSavedEventFuture>>>,
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue