Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: alt+i always inserts '^' character #41024

Open
AriaMinaei opened this issue Jan 2, 2018 · 23 comments
Open

macOS: alt+i always inserts '^' character #41024

AriaMinaei opened this issue Jan 2, 2018 · 23 comments
Assignees
Labels
chromium Issues and items related to Chromium keybindings VS Code keybinding issues macos Issues with VS Code on MAC/OS X upstream Issue identified as 'upstream' component related (exists outside of VS Code) upstream-issue-linked This is an upstream issue that has been reported upstream
Milestone

Comments

@AriaMinaei
Copy link

AriaMinaei commented Jan 2, 2018

  • VSCode Version: 1.19.1 & 1.20.0-insider (f911534)
  • OS Version: macOS Sierra 10.12.6

Steps to Reproduce:

  1. Assign keyboard shortcut "option+i" to a command such as 'Toggle Sidebar Visibility' or 'Go to Definition':
    image
  2. Try the shortcut in the editor. Sometimes the shortcut works (correct behavior), other times, the 'ˆ' character is put in the text without the command working (incorrect behavior), and sometimes the command works but the 'ˆ' character is also inserted (incorrect behavior).

Reproduces without extensions: Yes

#22664 & #22894 might be relevant.


2022.12: Edited to add the upstream link:

Upstream issue: https://bugs.chromium.org/p/chromium/issues/detail?id=887519

@Tyriar Tyriar added keybindings VS Code keybinding issues and removed editor labels Jan 2, 2018
@alexdima
Copy link
Member

alexdima commented Jan 8, 2018

The root cause is the when condition associated with the keybinding.

The default keybinding for go to definition is bound only when editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor. When you edit/associate option+i with it, it will create a new keybinding rule that follows the same condition.

editorHasDefinitionProvider is a dynamic context key which depends on the file you are currently editing and the set of extensions you have installed. For example, if you have an extension (built in or installed from the marketplace) that implements the goto definition functionality for the current programming language, the key editorHasDefinitionProvider will be set.

Out of the box:

  • TypeScript, JavaScript, CSS will have such a definition provider
  • a plain text file does not have a definition provider

In your case, I believe you would want the keybinding option+i to always be considered, so you can do the following in your keybindings.json:

BEFORE:

    {
        "key": "alt+i",
        "command": "editor.action.goToDeclaration",
        "when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
    },
    {
        "key": "f12",
        "command": "-editor.action.goToDeclaration",
        "when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
    }

AFTER:

    {
        "key": "alt+i",
        "command": "editor.action.goToDeclaration",
        "when": "editorTextFocus && !isInEmbeddedEditor"
    },
    {
        "key": "f12",
        "command": "-editor.action.goToDeclaration",
        "when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
    }

@alexdima alexdima added the *question Issue represents a question, should be posted to StackOverflow (VS Code) label Jan 8, 2018
@vscodebot vscodebot bot closed this as completed Jan 8, 2018
@alexdima alexdima closed this as completed Jan 8, 2018
@microsoft microsoft deleted a comment from vscodebot bot Jan 8, 2018
@AriaMinaei
Copy link
Author

Thanks for the explanation @alexandrudima, but the workaround doesn't work, and the bug happens regardless of any command/when combination, meaning if I bind any other action to alt+i, it'll insert the ˆ character.

@alexdima alexdima reopened this Jan 10, 2018
@alexdima alexdima removed *question Issue represents a question, should be posted to StackOverflow (VS Code) insiders labels Jan 10, 2018
@alexdima
Copy link
Member

alexdima commented Jan 10, 2018

Indeed, I can reproduce and get the circumflex character too when e.g. binding alt+i to toggle line comment:

{
	"key": "alt+i",
	"command": "editor.action.commentLine",
	"when": "editorTextFocus && !editorReadonly"
}

@alexdima alexdima added editor-input Editor text input macos Issues with VS Code on MAC/OS X bug Issue identified by VS Code Team member as probable bug labels Feb 5, 2018
@alexdima
Copy link
Member

alexdima commented Feb 5, 2018

This is also reproducible when in the Search Viewlet for example, and using the following binding:

{
        "key": "alt+i",
        "command": "toggleSearchWholeWord",
        "when": "searchInputBoxFocus && searchViewletVisible"
}

it is just weird that e.preventDefault() does not prevent the cirumflex character from appearing:
41024

@alexdima alexdima removed the editor-input Editor text input label Feb 5, 2018
@alexdima alexdima changed the title Bug: Some keyboard shortcuts work unreliably on macOS macOS: alt+i always inserts '^' character Feb 5, 2018
@alexdima
Copy link
Member

alexdima commented Feb 5, 2018

The same happens for alt+` (#41590)

@alexdima alexdima added this to the Backlog milestone Apr 18, 2018
@alexdima alexdima added the help wanted Issues identified as good community contribution opportunities label Apr 25, 2018
@alexdima
Copy link
Member

I can reproduce in Chrome and have filed https://bugs.chromium.org/p/chromium/issues/detail?id=887519

@alexdima alexdima added upstream Issue identified as 'upstream' component related (exists outside of VS Code) and removed bug Issue identified by VS Code Team member as probable bug help wanted Issues identified as good community contribution opportunities labels Sep 20, 2018
@kiranpoojary
Copy link

after using :
[
{doc1},
{doc2},
...
{docN}
]

Solved my problem

@alexdima
Copy link
Member

The same happens for alt + e (#108478)

@alexdima
Copy link
Member

alexdima commented Dec 9, 2020

Similar issue with shift+option+f on the ABC - India keyboard layout (#97166)

@chinaran
Copy link

chinaran commented Feb 6, 2022

https://stackoverflow.com/questions/11876485/how-to-disable-generating-special-characters-when-pressing-the-alta-optiona
It works for me to use another input sources(not default ABC) on macos.

@codebysandwich
Copy link

alt - n insert ˜ too alt - m can work as expected

@wrinkledeth
Copy link

@codebysandwich , did you ever find a solution? This is really bothering me as I would like to be able to use alt+n as well, but keep getting a ˜character

@codebysandwich
Copy link

@codebysandwich , did you ever find a solution? This is really bothering me as I would like to be able to use alt+n as well, but keep getting a ˜character

i'm sorry about that, i used + + n instead of + n
:(

@jrdodds
Copy link

jrdodds commented Jan 30, 2023

The macOS option key (⌥) is used for special characters, symbols, and accents. The macOS option key bindings and Windows alt key binding are not equivalent. Simply mapping Windows alt key bindings to macOS option key bindings will conflict with existing macOS option key bindings. Many of the issues tracked here are key binding conflicts.

The Keyboard Viewer with a US keyboard shows as follows without any modifier key pressed:

Screen Shot 2023-01-29 at 11 20 44 PM

and with the option key pressed:

Screen Shot 2023-01-29 at 11 21 30 PM

@greneholt
Copy link

This StackOverflow answer explains how to completely prevent Option+key from producing special characters, allowing you to use these combinations for shortcuts in VS Code and various other editors.

In short:

  1. Download this QWERTY keyboard layout file (or generate one yourself using the instructions in the linked answer).
  2. Move it to ~/Library/Keyboard Layouts/
  3. Go to System Settings > Keyboard > Text Input > Input Sources > Edit.
  4. Click + in the bottom left, scroll to the bottom of the list on the left and select Others then select QWERTY no option and click Add.
  5. Either delete your existing layout (probably called U.S.) or just switch to the QWERTY no option layout using the input-source select in the menu bar.

@jrdodds
Copy link

jrdodds commented Jul 1, 2023

The selected input source is global for the user. It's not limited to VSCode. I'd suggest keeping the existing keyboard so that it is possible to switch (in the input menu) to a keyboard that supports normal option functionality, if ever needed.

@jimeh
Copy link

jimeh commented Jul 1, 2023

So, yes, macOS does insert special characters on alt/option+, rather than trigger special keys. However, not in all apps. Emacs for example handles all those bindings correctly, and both Terminal and iTerm have settings that allow them to capture alt/option keybindings and pass them to whatever you have running in a terminal, instead of inserting the character macOS would normally insert.

So macOS definitely exposes some mechanism for apps to capture alt/option keybings. I don't know enough about macOS development myself to say what that mechanism is, but I know it's possible as other apps do it.

Hence it would be nice if we could see VSCode support it too.

@greneholt
Copy link

Agreed, but until Chromium deals with the upstream issue I don't think that will be possible. This workaround at least allows those who don't need extended character sets to use these shortcuts.

@forivall
Copy link
Contributor

I'm hitting this issue with dead keys overriding the keyboard shortcuts defined by the dance extension. I've had to resort to the same solution as @codebysandwich. Interestingly, the keyboard shortcuts "recording keys" mode is able to capture the key combination, so there could be a workaround by using the same key capture mechanism used there.

@diminutivesloop
Copy link
Contributor

Could there not be an option similar to terminal.integrated.macOptionIsMeta but that applies globally? When I enable that option I can type shortcuts like option+c in the terminal and it doesn't output 'ç' like it does elsewhere. I use the Codeium extension and a bunch of their default shortcuts conflict with the special character shortcuts, and it would be nice for those to just work without having to override them.

@diminutivesloop
Copy link
Contributor

Although to be fair terminal.integrated.macOptionIsMeta only works for some special character shortcuts and doesn't appear to address option+i.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chromium Issues and items related to Chromium keybindings VS Code keybinding issues macos Issues with VS Code on MAC/OS X upstream Issue identified as 'upstream' component related (exists outside of VS Code) upstream-issue-linked This is an upstream issue that has been reported upstream
Projects
None yet
Development

No branches or pull requests