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

macOptionFix: Added support for Mac OS Option + Key presses (Fixes #3197, #3666, #3662, #3284) #4643

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

alextorma
Copy link

@alextorma alextorma commented Mar 7, 2025

Description

This PR adds in support for <a-{key}> shortcuts in Vimium on MacOS. On MacOS, when the setting is enabled, Vimium will treat any <a> and <a-{key}> presses as if keyboard layout is ignored, thereby avoiding Mac's øπ†îøñ ߥµ∫ø¬ß (aka option symbols).

My apologies if the style isn't up to snuff - I'm somewhat scrappy and not exactly the most familiar with AirBnB style, but I'm happy to make revisions if you let me know what needs to be addressed!

Should fix #3197
Should fix #3666
Should fix #3662
Should fix #3284

@alextorma alextorma changed the title macOptionFix: Added support for Mac OS Option + Key presses (#3197) macOptionFix: Added support for Mac OS Option + Key presses (Fixes #3197) Mar 7, 2025
@philc
Copy link
Owner

philc commented Mar 10, 2025

Nicely done. I'd love to get this fixed.

I haven't tested this on alternate keyboard layouts, but I think it's safe to say that the approach in this PR only work for English keyboard layouts.

I don't think it's scalable to expand the support for this by hard coding the expected key for every available keyboard layout.

I'm leaning towards the approach of always ignoring keyboard layout on Mac when the alt key is pressed. Ignoring the keyboard layout for alt key presses on all platforms would probably break some existing configurations, but it shouldn't break existing configurations, because presumably they're already broken given that Alt keybindings currently don't work.

Let's leave this open for a bit to see if anyone else wants to chime in.

@alextorma
Copy link
Author

@philc, I hear you loud and clear. Try this one on for size! It's confirmed to work on both Mac and Linux (and by "work on Linux" I mean there is no behavior change on that platform as far as I can tell).

I've also been considering the potential for breaking existing configurations too - seeing as it was impossible to have both <a-{letter}> and <a-{symbol}> maps in a configuration in the past (at least, not with both working) I think we might be in the clear. There's probably a more in-depth way to handle translating the user maps on the fly rather than which character was read, but any solution that involves the option symbols will need to be locaized.

What I've done here is to simply treat any Alt and Alt + <key> press on macOS as keyboard-layout independent. I've also included a toggle on the options page (that only displays on macOS) to enable/disable this behaviour. It is enabled by default for the sake of new users, and the language it uses "Treat Option as Alt/Meta" should be familiar to Vimium's userbase (who I'm assuming are at least familiar with the very similarly named settings toggle in most terminal applications). Still, the new behavior can be disabled if someone so chooses.

With regards to setting a new (sane) default, my $0.02:

these issues have been reported going back years, and on all the threads I read, I never saw anybody mentioning <a-{option + key}> as being a solution/workaround until I mentioned it last week so how many configurations (of people who don't share information back to the community) are we worried about breaking here?

@alextorma
Copy link
Author

alextorma commented Mar 11, 2025

Sorry about that double commit just then... stupid vscode.

Edit: I realized just a bit too late that I was showing the wrong Option + Key -> Symbol pair example on the Options page. Last commit of the night, I swear.

@alextorma alextorma changed the title macOptionFix: Added support for Mac OS Option + Key presses (Fixes #3197) macOptionFix: Added support for Mac OS Option + Key presses (Fixes #3197, #3666, #3662, #3284) Mar 12, 2025
Copy link
Contributor

@UncleSnail UncleSnail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This generally looks like a good fix, although the condition can be simplified. Good job.

@alextorma alextorma requested a review from UncleSnail March 19, 2025 22:34
Copy link
Contributor

@UncleSnail UncleSnail left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trigger <a-f> on Mac? Alt keys don't work on mac Vimium Mac Alt-based hotkeys don't work
3 participants