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

Commit

Permalink
Merge pull request #112 from brave/fix/escape-handling
Browse files Browse the repository at this point in the history
Handle ESC via element event handlers
  • Loading branch information
diracdeltas committed Dec 30, 2015
2 parents dfe2497 + 3885586 commit 4beeffb
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 9 deletions.
10 changes: 10 additions & 0 deletions app/content/webviewPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
var webFrame = require('electron').webFrame
var ipc = require('electron').ipcRenderer
var messages = require('../../js/constants/messages')
var KeyCodes = require('../../js/constants/keyCodes')

var browserZoomLevel = 0
var browserMaxZoom = 9
Expand Down Expand Up @@ -179,3 +180,12 @@ document.addEventListener('contextmenu', (e) => {
ipc.send(messages.CONTEXT_MENU_OPENED, e.target.nodeName)
e.preventDefault()
}, false)

document.onkeydown = (e) => {
switch (e.keyCode) {
case KeyCodes.ESC:
e.preventDefault()
ipc.send(messages.STOP_LOAD)
break
}
}
3 changes: 3 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ app.on('ready', function () {
ipcMain.on(messages.CONTEXT_MENU_OPENED, (e, nodeName) => {
BrowserWindow.getFocusedWindow().webContents.send(messages.CONTEXT_MENU_OPENED, nodeName)
})
ipcMain.on(messages.STOP_LOAD, () => {
BrowserWindow.getFocusedWindow().webContents.send(messages.STOP_LOAD)
})

Menu.init()

Expand Down
3 changes: 1 addition & 2 deletions app/localShortcuts.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ module.exports.register = (win) => {
['CmdOrCtrl+Shift+]', messages.SHORTCUT_NEXT_TAB],
['CmdOrCtrl+Shift+[', messages.SHORTCUT_PREV_TAB],
['CmdOrCtrl+9', messages.SHORTCUT_SET_ACTIVE_FRAME_TO_LAST],
['CmdOrCtrl+Shift+T', messages.SHORTCUT_UNDO_CLOSED_FRAME],
['Escape', messages.SHORTCUT_ACTIVE_FRAME_STOP]
['CmdOrCtrl+Shift+T', messages.SHORTCUT_UNDO_CLOSED_FRAME]
]

// Tab ordering shortcuts
Expand Down
9 changes: 4 additions & 5 deletions js/components/findbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,15 @@ export default class FindBar extends ImmutableComponent {
onKeyDown (e) {
switch (e.keyCode) {
case keyCodes.ESC:
// ESC is handled by a local shortcut, so use shift+ESC
if (e.shiftKey) {
this.props.onHide()
}
e.preventDefault()
this.props.onHide()
break
case keyCodes.ENTER:
e.preventDefault()
if (e.shiftKey) {
this.onFindPrev()
} else {
this.onFind()
this.onFindNext()
}
break
}
Expand Down
3 changes: 3 additions & 0 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Main extends ImmutableComponent {
})
}

ipc.on(messages.STOP_LOAD, () => {
electron.remote.getCurrentWebContents().send(messages.SHORTCUT_ACTIVE_FRAME_STOP)
})
ipc.on(messages.CONTEXT_MENU_OPENED, (e, nodeName) => {
console.log('got context menu open', nodeName)
contextMenus.onMainContextMenu(nodeName)
Expand Down
6 changes: 5 additions & 1 deletion js/components/urlBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const WindowActions = require('../actions/windowActions')
const KeyCodes = require('../constants/keyCodes')
const cx = require('../lib/classSet.js')
const ipc = global.require('electron').ipcRenderer
const remote = global.require('electron').remote

const UrlBarSuggestions = require('./urlBarSuggestions.js')
const messages = require('../constants/messages')
Expand Down Expand Up @@ -103,7 +104,10 @@ class UrlBar extends ImmutableComponent {
e.preventDefault()
}
break
// escape is handled by ipc shortcut-active-frame-stop event
case KeyCodes.ESC:
e.preventDefault()
remote.getCurrentWebContents().send(messages.SHORTCUT_ACTIVE_FRAME_STOP)
break
default:
}
}
Expand Down
3 changes: 2 additions & 1 deletion js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const messages = {
SET_AD_DIV_CANDIDATES: _, /** @arg {Array} adDivCandidates, @arg {string} placeholderUrl */
CONTEXT_MENU_OPENED: _, /** @arg {string} nodeName of node being clicked */
APP_STATE_CHANGE: _,
APP_ACTION: _
APP_ACTION: _,
STOP_LOAD: _
}

module.exports = mapValuesByKeys(messages)

0 comments on commit 4beeffb

Please sign in to comment.