Changed cmd+w with no open tabs to close window (#10740)

William Viktorsson created

Fixes https://github.com/zed-industries/zed/issues/5322


Release Notes:

- Changed cmd+w with no open tabs to close window
[#5322](https://github.com/zed-industries/zed/issues/5322)



https://github.com/zed-industries/zed/assets/22855292/113b1635-ae30-4718-a3d3-758a4bf53714

Change summary

crates/workspace/src/pane.rs | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

Detailed changes

crates/workspace/src/pane.rs 🔗

@@ -5,7 +5,7 @@ use crate::{
     },
     toolbar::Toolbar,
     workspace_settings::{AutosaveSetting, TabBarSettings, WorkspaceSettings},
-    NewCenterTerminal, NewFile, NewSearch, OpenInTerminal, OpenTerminal, OpenVisible,
+    CloseWindow, NewCenterTerminal, NewFile, NewSearch, OpenInTerminal, OpenTerminal, OpenVisible,
     SplitDirection, ToggleZoom, Workspace,
 };
 use anyhow::Result;
@@ -874,6 +874,8 @@ impl Pane {
         cx: &mut ViewContext<Self>,
     ) -> Option<Task<Result<()>>> {
         if self.items.is_empty() {
+            // Close the window when there's no active items to close.
+            cx.dispatch_action(Box::new(CloseWindow));
             return None;
         }
         let active_item_id = self.items[self.active_item_index].item_id();