Skip to content

Commit

Permalink
Add shortcuts inside webview to move back/forward (#533)
Browse files Browse the repository at this point in the history
* first attempt

* Adds mousetrap as a dependency

it should get ctrl or cmd keys to go back and forward on history
inside the channels

* Fix multiple spaceslint error

* Removes mousetrap dependency

we are now using menu items and accelerators for binding shortcuts

the shortcuts on windows and linux should be "alt+left/right" and
on mac "cmd+left/right", like on chrome for instance
  • Loading branch information
vcapretz authored and gdelavald committed Oct 27, 2017
1 parent 23f034a commit bf38fa9
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const appIsReady = new Promise(resolve => {
}
});
if (process.platform === 'darwin') {
// Open protocol urls on mac as open-url is not yet implemented on other OS's
// Open protocol urls on mac as open-url is not yet implemented on other OS's
app.on('open-url', function (e, url) {
e.preventDefault();
const site = processProtocolArgv([url]);
Expand Down
5 changes: 5 additions & 0 deletions src/scripts/menus.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import servers from './servers';
import appMenu from './menus/app';
import editMenu from './menus/edit';
import viewMenu from './menus/view';
import historyMenu from './menus/history';
import windowMenu from './menus/window';
import helpMenu from './menus/help';

Expand All @@ -31,6 +32,10 @@ const menuTemplate = [
label: getLabel('View'),
submenu: viewMenu
},
{
label: getLabel('History'),
submenu: historyMenu
},
{
label: getLabel('Window'),
id: 'window',
Expand Down
30 changes: 30 additions & 0 deletions src/scripts/menus/history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import webview from '../webview';
const isMac = process.platform === 'darwin';

const macWindowTemplate = [
{
label: 'Back',
accelerator: 'Command+left',
click: () => { webview.goBack(); }
},
{
label: 'Forward',
accelerator: 'Command+right',
click: () => { webview.goForward(); }
}
];

const windowTemplate = [
{
label: 'Back',
accelerator: 'Alt+Left',
click: () => { webview.goBack(); }
},
{
label: 'Forward',
accelerator: 'Alt+Right',
click: () => { webview.goForward(); }
},
];

export default isMac ? macWindowTemplate : windowTemplate;
10 changes: 9 additions & 1 deletion src/scripts/webview.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class WebView extends EventEmitter {
}
});

webviewObj.addEventListener('console-message', function (e) {
webviewObj.addEventListener('console-message', (e) => {
console.log('webview:', e.message);
});

Expand Down Expand Up @@ -193,6 +193,14 @@ class WebView extends EventEmitter {
}
return false;
}

goBack () {
this.getActive().goBack();
}

goForward () {
this.getActive().goForward();
}
}

export default new WebView();

0 comments on commit bf38fa9

Please sign in to comment.