diff --git a/crates/outline/src/outline.rs b/crates/outline/src/outline.rs index dbcfbef973..c4285a4552 100644 --- a/crates/outline/src/outline.rs +++ b/crates/outline/src/outline.rs @@ -162,25 +162,24 @@ impl OutlineView { } fn toggle(workspace: &mut Workspace, _: &Toggle, cx: &mut ViewContext) { - let editor = workspace + if let Some(editor) = workspace .active_item(cx) - .unwrap() - .to_any() - .downcast::() - .unwrap(); - let settings = workspace.settings(); - let buffer = editor - .read(cx) - .buffer() - .read(cx) - .read(cx) - .outline(Some(settings.borrow().theme.editor.syntax.as_ref())); - if let Some(outline) = buffer { - workspace.toggle_modal(cx, |cx, _| { - let view = cx.add_view(|cx| OutlineView::new(outline, editor, settings, cx)); - cx.subscribe(&view, Self::on_event).detach(); - view - }) + .and_then(|item| item.to_any().downcast::()) + { + let settings = workspace.settings(); + let buffer = editor + .read(cx) + .buffer() + .read(cx) + .read(cx) + .outline(Some(settings.borrow().theme.editor.syntax.as_ref())); + if let Some(outline) = buffer { + workspace.toggle_modal(cx, |cx, _| { + let view = cx.add_view(|cx| OutlineView::new(outline, editor, settings, cx)); + cx.subscribe(&view, Self::on_event).detach(); + view + }) + } } }