Skip to content

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

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

Closed
wants to merge 8 commits into from
7 changes: 6 additions & 1 deletion lib/keyboard_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ const KeyboardUtils = {
}
},

// Adds support for Mac Option + Keypress. See #3197.
// (Vimium will ignore the symbols and treat them like letters, at least on a US Laptop keyboard).
getKeyChar(event) {
let key;
if (!Settings.get("ignoreKeyboardLayout")) {
if (
!Settings.get("ignoreKeyboardLayout") &&
!(this.platform === "Mac" && Settings.get("macOptionKeyFix") && event.altKey)
) {
key = event.key;
} else if (!event.code) {
key = event.key != null ? event.key : ""; // Fall back to event.key (see #3099).
Expand Down
1 change: 1 addition & 0 deletions lib/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ w: https://www.wikipedia.org/w/index.php?title=Special:Search&search=%s Wikipedi
regexFindMode: false,
waitForEnterForFilteredHints: true,
helpDialog_showAdvancedCommands: false,
macOptionKeyFix: true,
ignoreKeyboardLayout: false,
};

Expand Down
4 changes: 4 additions & 0 deletions pages/options.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ div#exampleKeyMapping {
margin-top: 5px;
}

div#macos {
display: none;
}

#linkHintCharactersContainer,
#linkHintNumbersContainer,
#waitForEnterForFilteredHintsContainer {
Expand Down
14 changes: 14 additions & 0 deletions pages/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,20 @@ <h2></h2>
Switch back to plain find mode by using the <code>\R</code> escape sequence.
</div>

<h2></h2>
<div id="macos">
<label>
<input id="macOptionKeyFix" type="checkbox" />
macOS: Treat Option as Alt/Meta
</label>
<div class="example">
This forces Vimium to treat an <code>Option + Key</code> keypress that would produce a
symbol on macOS as the equivalent <code>Alt + Letter</code> keypress. (With this
enabled, you can create maps such as <code>&lt;a-j&gt;</code> rather than
<code>&lt;a-&Delta;&gt;</code>.)
</div>
</div>

<h2></h2>
<label>
<input id="ignoreKeyboardLayout" type="checkbox" />
Expand Down
4 changes: 4 additions & 0 deletions pages/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const options = {
nextPatterns: "string",
previousPatterns: "string",
regexFindMode: "boolean",
macOptionKeyFix: "boolean",
ignoreKeyboardLayout: "boolean",
scrollStepSize: "number",
smoothScroll: "boolean",
Expand All @@ -24,6 +25,9 @@ const OptionsPage = {

const saveOptionsEl = document.querySelector("#saveOptions");

const isMacOS = KeyboardUtils.platform === "Mac";
if (isMacOS) document.getElementById("macos").style.display = "contents";

const onUpdated = () => {
saveOptionsEl.disabled = false;
saveOptionsEl.textContent = "Save changes";
Expand Down