macvim-dev / macvim

Vim - the text editor - for macOS
https://macvim.org
Vim License
7.51k stars 683 forks source link

Feature request: keyboard navigation for the "VIM - ATTENTION" dialog #1403

Closed jbyler closed 1 year ago

jbyler commented 1 year ago

Summary

I mostly love how MacVim integrates vim into the macOS environment, but one rough edge is how I can't interact with the "VIM - ATTENTION // Swap file "ABC.swp" already exists!" dialog using the keyboard. The request is pretty general: I just want some way to make a choice in the dialog without using the mouse.

Options I can think of:

  1. Make it a native macOS dialog so that I can use to highlight one of the buttons, then press to press it.
  2. Provide custom shortcuts similar to the ones vim uses ("[O]pen Read-Only, (E)dit anyway, (R)ecover, (Q)uit, (A)bort")
  3. Don't use a macOS dialog at all; just make it work like Vim does, with the focus staying inside the main window, waiting for a key press.

I personally have a slight preference for #3 (it's vim, after all) but any way to make a choice without using the mouse with make me happy.

How to reproduce:

  1. Open any file in MacVim
  2. Open the same file again, using MacVim.app/Contents/bin/mvim

Alternate reproduction steps:

  1. Open any file in MacVim
  2. Open a new window in MacVim with ⌘N
  3. Edit the same file from step 1 in this new window, e.g. by using the :e ex command.

Expected:

  1. MacVim.app opens a new window with "E235: ATTENTION // Found a sway file by the name ..." warning, and a set of choices "Open Read-Only", "Edit anyway", "Recover", "Quit", "Abort"
  2. MacVim.app allows the user to choose one of these options with the keyboard.

Actual:

  1. Happens as expected
  2. There is no way to choose an option with the keyboard; the mouse must be used.

Workaround

Don't use the MacVim.app/Contents/bin/mvim script. Instead, open files in MacVim by using open -a MacVim.

ychin commented 1 year ago

You mean this dialog box right?

image

The dialog box is technically navigable using the keyboard:

  1. Because it's a macOS dialog box, it follows standard macOS conventions. The big blue button (in this case "Open Read-Only") is used when you hit Return. You can also use Tab to toggle which button you want and then use Space to select it (you see a blue outline), but you need to have enabled "Keyboard → Keyboard navigation" in System Settings. (See :h macvim-dialogs, but the docs is slightly outdated by suggesting you toggle "Full keyboard access" instead) a. Also, the "Don't Save" button in other dialog boxes can be accessed by doing Cmd-Delete or Cmd-D (this is common in macOS apps).
  2. Each key is bound to a shortcut key. E.g. "Edit anyway" can be accessed via "E" key. On Windows, there would be an underline on the "E" but macOS makes it kind of difficult to show the shortcut key associated with a button, annoyingly, so you just have to know which key is associated with a button which is not ideal.

For (2) I have been experimenting with different options to show the key associated with a button, either by manually displaying it as "(E)dit anyway", or find some other ways to show it. I'm still debating different options (since they also need to work with localized texts).

ychin commented 1 year ago

Don't use a macOS dialog at all; just make it work like Vim does, with the focus staying inside the main window, waiting for a key press.

There is already an option to do that: set guioption+=c.

jbyler commented 1 year ago

Hah, thanks so much @ychin, apologies for wasting your time!

  1. System Settings full keyboard access: yes, this worked. (I had this on previously, but somehow it got switched off. Should have confirmed before filing a feature request. Oops!)

  2. Each key is bound to a shortcut key: yes, this worked also. I really thought I had tried doing exactly this right before I filed the feature request, but I must have tried with the ⌘ key or something. I do think there's a discoverability problem with this feature, but it sounds like you're aware of and working on that. I think the difficulty comes from the fact that it's a native macOS dialog, but it's behaving in a vim-like but un-Mac-like way. You could make it look more like a menu: left-justified names, with right-justified keyboard shortcuts?

    Open Read-Only            ⏎
    Edit anyway              ⌘E
    Recover                  ⌘R
    Quit                     ⌘Q
    Abort                    ⌘A
  3. This one is my preferred option, and I'm going to use this going forward. I like how it doesn't mix Vim and macOS metaphors, so it feels natural and easy to understand. One correction: there's a typo in your message (guioptions not guioption). Here's what I'm putting in my ~/.vimrc in case others find this issue and want to use it:

    if has('gui_running')
        set guioptions+=c
    else

Thanks so much for your response, and again my apologies, since this is all there and documented!

ychin commented 1 year ago

You could make it look more like a menu: left-justified names, with right-justified keyboard shortcuts?

It's not that easy to do because it would look quite weird on a button. macOS just doesn't give you a good spot to show the "key equivalent" (which is their technical term for the shortcut key) on a button. On the menu it just shows it on the right like you suggested though (e.g. Edit->Copy menu shows "⌘C" on the right). But I'll think about how to surface it more.

ychin commented 1 year ago
     if has('gui_running')
         set guioptions+=c
     else

I think it's better to do has('gui') if you want this applied for all GUIs (e.g. GVim on Windows) or has('gui_macvim') if only for MacVim.

Reason this is better than has('gui_running') is that sometimes you could launch MacVim GUI from terminal by running the :gui command. If you do this, your guioptions wouldn't be set correctly because "gui_running" will be 0 when Vim first parsed the config files.