Revert "More keybindings in macOs modals with buttons"

Joseph Lyons created

This reverts commit 1398a1206299cbaf5e14b9de30d2fbfe83f04334.

Change summary

crates/gpui/src/platform/mac/window.rs | 39 +--------------------------
1 file changed, 2 insertions(+), 37 deletions(-)

Detailed changes

crates/gpui/src/platform/mac/window.rs đź”—

@@ -699,31 +699,6 @@ impl platform::Window for Window {
         msg: &str,
         answers: &[&str],
     ) -> oneshot::Receiver<usize> {
-        // macOs applies overrides to modal window buttons after they are added.
-        // Two most important for this logic are:
-        // * Buttons with "Cancel" title will be displayed as the last buttons in the modal
-        // * Last button added to the modal via `addButtonWithTitle` stays focused
-        // * Focused buttons react on "space"/" " keypresses
-        // * Usage of `keyEquivalent`, `makeFirstResponder` or `setInitialFirstResponder` does not change the focus
-        //
-        // See also https://developer.apple.com/documentation/appkit/nsalert/1524532-addbuttonwithtitle#discussion
-        // ```
-        // By default, the first button has a key equivalent of Return,
-        // any button with a title of “Cancel” has a key equivalent of Escape,
-        // and any button with the title “Don’t Save” has a key equivalent of Command-D (but only if it’s not the first button).
-        // ```
-        //
-        // To avoid situations when the last element added is "Cancel" and it gets the focus
-        // (hence stealing both ESC and Space shortcuts), we find and add one non-Cancel button
-        // last, so it gets focus and a Space shortcut.
-        // This way, "Save this file? Yes/No/Cancel"-ish modals will get all three buttons mapped with a key.
-        let latest_non_cancel_label = answers
-            .iter()
-            .enumerate()
-            .rev()
-            .find(|(_, &label)| label != "Cancel")
-            .filter(|&(label_index, _)| label_index > 0);
-
         unsafe {
             let alert: id = msg_send![class!(NSAlert), alloc];
             let alert: id = msg_send![alert, init];
@@ -734,20 +709,10 @@ impl platform::Window for Window {
             };
             let _: () = msg_send![alert, setAlertStyle: alert_style];
             let _: () = msg_send![alert, setMessageText: ns_string(msg)];
-
-            for (ix, answer) in answers
-                .iter()
-                .enumerate()
-                .filter(|&(ix, _)| Some(ix) != latest_non_cancel_label.map(|(ix, _)| ix))
-            {
-                let button: id = msg_send![alert, addButtonWithTitle: ns_string(answer)];
-                let _: () = msg_send![button, setTag: ix as NSInteger];
-            }
-            if let Some((ix, answer)) = latest_non_cancel_label {
+            for (ix, answer) in answers.iter().enumerate() {
                 let button: id = msg_send![alert, addButtonWithTitle: ns_string(answer)];
                 let _: () = msg_send![button, setTag: ix as NSInteger];
             }
-
             let (done_tx, done_rx) = oneshot::channel();
             let done_tx = Cell::new(Some(done_tx));
             let block = ConcreteBlock::new(move |answer: NSInteger| {
@@ -755,7 +720,7 @@ impl platform::Window for Window {
                     let _ = postage::sink::Sink::try_send(&mut done_tx, answer.try_into().unwrap());
                 }
             });
-
+            let block = block.copy();
             let native_window = self.0.borrow().native_window;
             self.0
                 .borrow()