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

Add backspace and shift-backspace for back/forward #424

Merged
merged 1 commit into from
Jan 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions app/content/webviewPreload.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,33 @@ document.addEventListener('contextmenu', (e) => {
e.preventDefault()
}, false)

var shiftDown = false
document.onkeydown = (e) => {
switch (e.keyCode) {
case KeyCodes.ESC:
e.preventDefault()
ipc.send(messages.STOP_LOAD)
break
case KeyCodes.BACKSPACE:
const msg = shiftDown ? messages.GO_FORWARD : messages.GO_BACK
const elem = document.activeElement
if (elem.contentEditable !== 'true' &&
elem.nodeName !== 'INPUT' &&
elem.nodeName !== 'TEXTAREA') {
// TODO: find other node types where this shortcut should be disabled
ipc.send(msg)
}
break
case KeyCodes.SHIFT:
shiftDown = true
break
}
}
document.onkeyup = (e) => {
switch (e.keyCode) {
case KeyCodes.SHIFT:
shiftDown = false
break
}
}

Expand Down
6 changes: 6 additions & 0 deletions app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ app.on('ready', function () {
ipcMain.on(messages.STOP_LOAD, () => {
BrowserWindow.getFocusedWindow().webContents.send(messages.STOP_LOAD)
})
ipcMain.on(messages.GO_BACK, () => {
BrowserWindow.getFocusedWindow().webContents.send(messages.GO_BACK)
})
ipcMain.on(messages.GO_FORWARD, () => {
BrowserWindow.getFocusedWindow().webContents.send(messages.GO_FORWARD)
})

// Load HTTPS Everywhere browser "extension"
HttpsEverywhere.init()
Expand Down
8 changes: 8 additions & 0 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class Main extends ImmutableComponent {
ipc.on(messages.STOP_LOAD, () => {
electron.remote.getCurrentWebContents().send(messages.SHORTCUT_ACTIVE_FRAME_STOP)
})
ipc.on(messages.GO_BACK, () => {
console.log('going back')
electron.remote.getCurrentWebContents().send(messages.SHORTCUT_ACTIVE_FRAME_BACK)
})
ipc.on(messages.GO_FORWARD, () => {
console.log('going forward')
electron.remote.getCurrentWebContents().send(messages.SHORTCUT_ACTIVE_FRAME_FORWARD)
})
ipc.on(messages.CONTEXT_MENU_OPENED, (e, nodeProps) => {
contextMenus.onMainContextMenu(nodeProps)
})
Expand Down
4 changes: 3 additions & 1 deletion js/constants/keyCodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const KeyCodes = {
ENTER: 13,
ESC: 27,
UP: 38,
DOWN: 40
DOWN: 40,
SHIFT: 16,
BACKSPACE: 8
}

module.exports = KeyCodes
2 changes: 2 additions & 0 deletions js/constants/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ const messages = {
APP_STATE_CHANGE: _,
APP_ACTION: _,
STOP_LOAD: _,
GO_FORWARD: _,
GO_BACK: _,
// Session restore
REQUEST_WINDOW_STATE: _,
RESPONSE_WINDOW_STATE: _,
Expand Down