zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.62k stars 3.04k forks source link

Impossible to pass Alt key codes to terminal on macOS #17633

Open kivra-adalin opened 2 months ago

kivra-adalin commented 2 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

  1. Use a keyboard layout with dead keys (e.g. Alt+u creates a dead key ¨ that together with u creates ü).
  2. Open a terminal and run some program that accepts key binds with Alt (e.g. tmux)
  3. Try to input Alt+u when bound to a tmux command
  4. Notice ¨ getting sent as text to the terminal

The option terminal.option_as_meta makes no difference set to either true or false.

Environment

Zed: v0.151.2 (Zed) OS: macOS 14.6.1 Memory: 64 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

I think supporting diacritics is nice in the editor (because it is a "normal text input field" from a users perspective) but there should be a way to avoid them for the terminal. Otherwise it is impossible to send key commands involving Alt to terminal programs. I'm guessing terminal.option_as_meta does nothing because it is applied after the diacritics logic for Zed on macOS.

If applicable, attach your Zed.log file to this issue.

No response

Moshyfawn commented 1 month ago

You can try adding the terminal::SendKeystroke keymap as described here.

kivra-adalin commented 1 month ago

@Moshyfawn Unfortunately that doesn't seem to work. I tried that before and it seems that the umlaut / dead keys functionality happens before any key commands are parsed and handled according to the key map, because I still get ¨ umlauts (Optionu is set to produce that umlaut dead key in my layout) in the terminal with bindings like these:

  {
    "context": "Terminal",
    "bindings": {
      "alt-u": ["terminal::SendKeystroke", "alt-u"],
      "alt-shift-u": ["terminal::SendKeystroke", "alt-shift-u"]
    }
  }

Alternatively they are sent to the terminal pane, which then handles them as umlauts inside Zed before sending them to the actual terminal 🤷

schpet commented 1 month ago

i was trying to figure out why fish's alt-e wouldn't work but alt-v does (both open up the current command in $EDITOR) and this sounds like the same issue

gonzaloruizdevilla commented 1 month ago

I'm having a similar problem when using option-enter (alt-enter) in the terminal. "nter" is the text that appears in the terminal instead of sending alt-enter, as shown in the screenshot. I'm using some terminal tools that need to capture that combination of keys.

Screenshot 2024-10-02 at 23 24 16

schpet commented 1 month ago

@gonzaloruizdevilla i also hit that! it was recently fixed in #18363

i don't think it's in the stable release yet, but it's in preview as of... today https://zed.dev/releases/preview

there are instructions on how to run zed-preview here: https://zed.dev/docs/getting-started