diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index 7bdc66e..acc9729 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -26,6 +26,10 @@ pub(crate) fn always(_: &Session) -> std::result::Result<(), String> {
Ok(())
}
+pub(crate) fn has_package(s: &Session) -> std::result::Result<(), String> {
+ if s.has_package() { Ok(()) } else { Err("no package is open".into()) }
+}
+
pub(crate) fn has_graph(s: &Session) -> std::result::Result<(), String> {
s.graph().map(|_| ()).map_err(|_| "no graph is open".into())
}
diff --git a/crates/engine/src/document_history_commands.rs b/crates/engine/src/document_history_commands.rs
index 1b065d0..a25ed73 100644
--- a/crates/engine/src/document_history_commands.rs
+++ b/crates/engine/src/document_history_commands.rs
@@ -68,7 +68,7 @@ impl Session {
}
fn document_history(&self, document: u64) -> Option<&DocumentHistory> {
- if document == self.document_id { Some(&self.history) } else { self.documents.get(&document).map(|document| &document.history) }
+ if self.has_package() && document == self.document_id { Some(&self.history) } else { self.documents.get(&document).map(|document| &document.history) }
}
pub fn can_undo_document(&self, document: u64) -> bool {
@@ -86,6 +86,7 @@ impl Session {
/// Undo in an open package without changing the active canvas
pub fn undo_document(&mut self, document: u64) -> Result