Skip to content

Commit bf38fa9

Browse files
vcapretzgdelavald
authored andcommitted
Add shortcuts inside webview to move back/forward (#533)
* 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
1 parent 23f034a commit bf38fa9

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

src/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const appIsReady = new Promise(resolve => {
5858
}
5959
});
6060
if (process.platform === 'darwin') {
61-
// Open protocol urls on mac as open-url is not yet implemented on other OS's
61+
// Open protocol urls on mac as open-url is not yet implemented on other OS's
6262
app.on('open-url', function (e, url) {
6363
e.preventDefault();
6464
const site = processProtocolArgv([url]);

src/scripts/menus.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import servers from './servers';
55
import appMenu from './menus/app';
66
import editMenu from './menus/edit';
77
import viewMenu from './menus/view';
8+
import historyMenu from './menus/history';
89
import windowMenu from './menus/window';
910
import helpMenu from './menus/help';
1011

@@ -31,6 +32,10 @@ const menuTemplate = [
3132
label: getLabel('View'),
3233
submenu: viewMenu
3334
},
35+
{
36+
label: getLabel('History'),
37+
submenu: historyMenu
38+
},
3439
{
3540
label: getLabel('Window'),
3641
id: 'window',

src/scripts/menus/history.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import webview from '../webview';
2+
const isMac = process.platform === 'darwin';
3+
4+
const macWindowTemplate = [
5+
{
6+
label: 'Back',
7+
accelerator: 'Command+left',
8+
click: () => { webview.goBack(); }
9+
},
10+
{
11+
label: 'Forward',
12+
accelerator: 'Command+right',
13+
click: () => { webview.goForward(); }
14+
}
15+
];
16+
17+
const windowTemplate = [
18+
{
19+
label: 'Back',
20+
accelerator: 'Alt+Left',
21+
click: () => { webview.goBack(); }
22+
},
23+
{
24+
label: 'Forward',
25+
accelerator: 'Alt+Right',
26+
click: () => { webview.goForward(); }
27+
},
28+
];
29+
30+
export default isMac ? macWindowTemplate : windowTemplate;

src/scripts/webview.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class WebView extends EventEmitter {
7373
}
7474
});
7575

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

@@ -193,6 +193,14 @@ class WebView extends EventEmitter {
193193
}
194194
return false;
195195
}
196+
197+
goBack () {
198+
this.getActive().goBack();
199+
}
200+
201+
goForward () {
202+
this.getActive().goForward();
203+
}
196204
}
197205

198206
export default new WebView();

0 commit comments

Comments
 (0)