Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Don't toggle menu unless ALT was the last key pressed
Browse files Browse the repository at this point in the history
This prevents ALT codes from toggling menu

Fixes #4295

Auditors: @jonathansampson, @BrendanEich

Test Plan:
1. Launch Brave on Windows and go to http://jsbin.com
2. Click inside a text area and type a few letters
3. Push ALT (left) and release to confirm menu shows and do same to hide it
4. Push and hold ALT (left), key in 0133, then let go of ALT
5. The ellipsis should be typed out and the menu should NOT have been toggled
  • Loading branch information
bsclifton committed Nov 7, 2016
1 parent 55be56e commit 75bcc2b
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class Main extends ImmutableComponent {
this.onFind = this.onFind.bind(this)
this.onFindHide = this.onFindHide.bind(this)
this.checkForTitleMode = debounce(this.checkForTitleMode.bind(this), 20)
this.lastKeyPressed = undefined
}
registerWindowLevelShortcuts () {
// For window level shortcuts that don't work as local shortcuts
Expand All @@ -129,6 +130,8 @@ class Main extends ImmutableComponent {
}
break
}

this.lastKeyPressed = e.which
})
}

Expand All @@ -143,16 +146,20 @@ class Main extends ImmutableComponent {
break
}

e.preventDefault()
// Only show/hide the menu if last key pressed was ALT
// (typing ALT codes should not toggle menu)
if (this.lastKeyPressed === keyCodes.ALT) {
e.preventDefault()

if (getSetting(settings.AUTO_HIDE_MENU)) {
windowActions.toggleMenubarVisible(null)
} else {
if (customTitlebar.menubarSelectedIndex) {
windowActions.setSubmenuSelectedIndex()
windowActions.setContextMenuDetail()
if (getSetting(settings.AUTO_HIDE_MENU)) {
windowActions.toggleMenubarVisible(null)
} else {
windowActions.setSubmenuSelectedIndex([0])
if (customTitlebar.menubarSelectedIndex) {
windowActions.setSubmenuSelectedIndex()
windowActions.setContextMenuDetail()
} else {
windowActions.setSubmenuSelectedIndex([0])
}
}
}
break
Expand Down

0 comments on commit 75bcc2b

Please sign in to comment.