From 995bfa0a093c31d01b0020ef0c5d306528a18d3c Mon Sep 17 00:00:00 2001 From: Vladimir Starkov Date: Sun, 23 Oct 2016 11:48:31 +0200 Subject: [PATCH 1/3] disable most binded hotkeys --- lib/containers/hyper.js | 42 ++++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/lib/containers/hyper.js b/lib/containers/hyper.js index f1e009c47237..c34c7dd901ee 100644 --- a/lib/containers/hyper.js +++ b/lib/containers/hyper.js @@ -16,6 +16,14 @@ const isMac = /Mac/.test(navigator.userAgent); class Hyper extends Component { constructor(props) { super(props); + /** + * attachKeyListeners and resetKeyListeners + * should be removed after being implemented in rpc + * see app/menu.js + */ + this.attachKeyListeners = this.attachKeyListeners.bind(this); + this.resetKeyListeners = this.resetKeyListeners.bind(this); + this.handleFocusActive = this.handleFocusActive.bind(this); this.onTermsRef = this.onTermsRef.bind(this); } @@ -36,7 +44,7 @@ class Hyper extends Component { } attachKeyListeners() { - const {moveTo, moveLeft, moveRight} = this.props; + const {moveTo} = this.props; const term = this.terms.getActiveTerm(); if (!term) { return; @@ -44,6 +52,7 @@ class Hyper extends Component { const lastIndex = this.terms.getLastTermIndex(); const document = term.getTermDocument(); const keys = new Mousetrap(document); + keys.bind('command+1', moveTo.bind(this, 0)); keys.bind('command+2', moveTo.bind(this, 1)); keys.bind('command+3', moveTo.bind(this, 2)); @@ -54,15 +63,6 @@ class Hyper extends Component { keys.bind('command+8', moveTo.bind(this, 7)); keys.bind('command+9', moveTo.bind(this, lastIndex)); - keys.bind('command+shift+left', moveLeft); - keys.bind('command+shift+right', moveRight); - keys.bind('command+shift+[', moveLeft); - keys.bind('command+shift+]', moveRight); - keys.bind('command+alt+left', moveLeft); - keys.bind('command+alt+right', moveRight); - keys.bind('ctrl+shift+tab', moveLeft); - keys.bind('ctrl+tab', moveRight); - const bound = method => term[method].bind(term); keys.bind('alt+left', bound('moveWordLeft')); keys.bind('alt+right', bound('moveWordRight')); @@ -75,24 +75,26 @@ class Hyper extends Component { this.keys = keys; } + resetKeyListeners() { + if (this.keys) { + this.keys.reset(); + } + } + onTermsRef(terms) { this.terms = terms; } componentDidUpdate(prev) { if (prev.activeSession !== this.props.activeSession) { - if (this.keys) { - this.keys.reset(); - } + this.resetKeyListeners(); this.handleFocusActive(); this.attachKeyListeners(); } } componentWillUnmount() { - if (this.keys) { - this.keys.reset(); - } + this.resetKeyListeners(); document.body.style.backgroundColor = 'inherit'; } @@ -146,14 +148,6 @@ const HyperContainer = connect( return { moveTo: i => { dispatch(uiActions.moveTo(i)); - }, - - moveLeft: () => { - dispatch(uiActions.moveLeft()); - }, - - moveRight: () => { - dispatch(uiActions.moveRight()); } }; }, From f629cc1af694aee338bab730f32e05b36edc41f5 Mon Sep 17 00:00:00 2001 From: Vladimir Starkov Date: Sun, 23 Oct 2016 11:52:01 +0200 Subject: [PATCH 2/3] swap hard-coded keybindings to "command" field in menu --- app/menu.js | 103 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 25 deletions(-) diff --git a/app/menu.js b/app/menu.js index 73bc00f25f9a..f3ff5a3251e8 100644 --- a/app/menu.js +++ b/app/menu.js @@ -22,7 +22,7 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Preferences...', - accelerator: 'Cmd+,', + command: 'show-settings', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('preferences'); @@ -64,14 +64,14 @@ module.exports = ({createWindow, updatePlugins}) => { submenu: [ { label: 'New Window', - accelerator: 'CmdOrCtrl+N', + command: 'new-window', click() { createWindow(); } }, { label: 'New Tab', - accelerator: 'CmdOrCtrl+T', + command: 'new-tab', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('termgroup add req'); @@ -85,7 +85,7 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Split Vertically', - accelerator: isMac ? 'Cmd+D' : 'Ctrl+Shift+E', + command: 'split-vertical', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('split request vertical'); @@ -94,7 +94,7 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Split Horizontally', - accelerator: isMac ? 'Cmd+Shift+D' : 'Ctrl+Shift+O', + command: 'split-horizontal', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('split request horizontal'); @@ -106,7 +106,7 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Close', - accelerator: 'CmdOrCtrl+W', + command: 'close', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('termgroup close req'); @@ -115,8 +115,8 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: isMac ? 'Close Terminal Window' : 'Quit', - role: 'close', - accelerator: 'CmdOrCtrl+Shift+W' + command: 'close-window', + role: 'close' } ] }; @@ -150,13 +150,51 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Clear', - accelerator: 'CmdOrCtrl+K', + command: 'clear', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('session clear req'); } } } + /** + ,{ + type: 'separator' + }, + * @TODO: implemented in rpc, ./lib/index.js + ...[{ + label: 'Move word Left', + command: 'move-word-left', + }, { + label: 'Move word Right', + command: 'move-word-right', + }, { + label: 'Delete word Left', + command: 'delete-word-left', + }, { + label: 'Delete word Right', + command: 'delete-word-right', + }, { + label: 'Delete line', + command: 'delete-line', + }, { + label: 'Move to line start', + command: 'move-to-line-start', + }, { + label: 'Move to line end', + command: 'move-to-line-end', + }, { + label: 'Select All', + command: 'select-all', + }].map(submenuItem => { + item.click = function click(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.rpc.emit(submenuItem.command); + } + }; + return item; + }), + */ ] }; @@ -165,7 +203,7 @@ module.exports = ({createWindow, updatePlugins}) => { {type: 'separator'}, { label: 'Preferences...', - accelerator: 'Cmd+,', + command: 'show-settings', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('preferences'); @@ -182,7 +220,7 @@ module.exports = ({createWindow, updatePlugins}) => { submenu: [ { label: 'Reload', - accelerator: 'CmdOrCtrl+R', + command: 'reload', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('reload'); @@ -191,7 +229,7 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Full Reload', - accelerator: 'CmdOrCtrl+Shift+R', + command: 'reload-full', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.reload(); @@ -200,7 +238,7 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Toggle Developer Tools', - accelerator: isMac ? 'Alt+Command+I' : 'Ctrl+Shift+I', + command: 'toggle-devtools', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.webContents.toggleDevTools(); @@ -212,7 +250,7 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Reset Zoom Level', - accelerator: 'CmdOrCtrl+0', + command: 'zoom-reset', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('reset fontSize req'); @@ -221,7 +259,7 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Zoom In', - accelerator: 'CmdOrCtrl+plus', + command: 'zoom-in', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('increase fontSize req'); @@ -230,13 +268,28 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Zoom Out', - accelerator: 'CmdOrCtrl+-', + command: 'zoom-out', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('decrease fontSize req'); } } } + /** + * @TODO: implemented in rpc, ./lib/index.js + ,{ + type: 'separator' + }, + ...[ 1, 2, 3, 4, 5, 6, 7, 8, 'last' ].map((value, index) => ({ + label: `Show ${value} Tab`, + command: `tab-show-${ value === 'last' ? value : index }`, + click(item, focusedWindow) { + if (focusedWindow) { + focusedWindow.rpc.emit(`move req ${ value === 'last' ? value : index }`); + } + } + })), + */ ] }; @@ -245,7 +298,7 @@ module.exports = ({createWindow, updatePlugins}) => { submenu: [ { label: 'Update All Now', - accelerator: 'CmdOrCtrl+Shift+U', + command: 'update-plugins', click() { updatePlugins(); } @@ -267,7 +320,7 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Show Previous Tab', - accelerator: 'CmdOrCtrl+Option+Left', + command: 'prev-tab', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('move left req'); @@ -276,7 +329,7 @@ module.exports = ({createWindow, updatePlugins}) => { }, { label: 'Show Next Tab', - accelerator: 'CmdOrCtrl+Option+Right', + command: 'next-tab', click(item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('move right req'); @@ -287,20 +340,20 @@ module.exports = ({createWindow, updatePlugins}) => { type: 'separator' }, { - label: 'Select Next Pane', - accelerator: 'Ctrl+Alt+Tab', + label: 'Select Previous Pane', + command: 'prev-pane', click(item, focusedWindow) { if (focusedWindow) { - focusedWindow.rpc.emit('next pane req'); + focusedWindow.rpc.emit('prev pane req'); } } }, { - label: 'Select Previous Pane', - accelerator: 'Ctrl+Shift+Alt+Tab', + label: 'Select Next Pane', + command: 'next-pane', click(item, focusedWindow) { if (focusedWindow) { - focusedWindow.rpc.emit('prev pane req'); + focusedWindow.rpc.emit('next pane req'); } } }, From 69e4fd8728dc461b4e05db365ead019bec9938d2 Mon Sep 17 00:00:00 2001 From: Vladimir Starkov Date: Sun, 23 Oct 2016 12:13:45 +0200 Subject: [PATCH 3/3] add hyper-keymap as a first built-in plugin. fix #872 --- app/config-default.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/config-default.js b/app/config-default.js index 66db6c4deee1..652e5a7c0653 100644 --- a/app/config-default.js +++ b/app/config-default.js @@ -81,7 +81,12 @@ module.exports = { // `hyperpower` // `@company/project` // `project#1.0.1` - plugins: [], + // + // Make sure, you dont remove 'hyper-keymap' plugin, + // unless you know what you are doing + plugins: [ + 'hyper-keymap' + ], // in development, you can create a directory under // `~/.hyper_plugins/local/` and include it here