diff --git a/src/input.rs b/src/input.rs
index af519006b5854b1ea2910a5e96b2ab5e6d934516..3e1b84ebf95d310d32fa158b3401d89edb4c6a8d 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -574,13 +574,16 @@ pub(crate) fn undo_redo(
     >,
     mut evw_changed: EventWriter<CosmicTextChanged>,
 ) {
-    if active_editor.0.is_none() {
-        return;
-    }
+    let entity = match active_editor.0 {
+        Some(entity) => entity,
+        None => return,
+    };
 
-    let entity = active_editor.0.unwrap();
+    let (mut editor, attrs, mut edit_history) = match editor_q.get_mut(entity) {
+        Ok(components) => components,
+        Err(_) => return,
+    };
 
-    let (mut editor, attrs, mut edit_history) = editor_q.get_mut(entity).unwrap();
     let command = keypress_command(&keys);
 
     let attrs = &attrs.0;