From 961a39e8f38cead77459b9df487cd73224f91e70 Mon Sep 17 00:00:00 2001 From: Marc Bachmann Date: Tue, 19 Jul 2016 19:48:11 +0200 Subject: [PATCH] Add cursor actions (#217) * Add cursor actions * Use Command+Option+Left shortcuts to change tabs This changes the behavior the ones of sublime & chrome --- app/lib/components/term.js | 28 ++++++++++++++++++++++++++++ app/lib/containers/hyperterm.js | 11 +++++++++++ app/lib/hterm.js | 2 +- menu.js | 4 ++-- 4 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/lib/components/term.js b/app/lib/components/term.js index 34e144de..4cd0c2d5 100644 --- a/app/lib/components/term.js +++ b/app/lib/components/term.js @@ -95,6 +95,34 @@ export default class Term extends Component { } } + moveWordLeft () { + this.term.onVTKeystroke('\x1bb'); + } + + moveWordRight () { + this.term.onVTKeystroke('\x1bf'); + } + + deleteWordLeft () { + this.term.onVTKeystroke('\x1b\x7f'); + } + + deleteWordRight () { + this.term.onVTKeystroke('\x1bd'); + } + + deleteLine () { + this.term.onVTKeystroke('\x1bw'); + } + + moveToStart () { + this.term.onVTKeystroke('\x01'); + } + + moveToEnd () { + this.term.onVTKeystroke('\x05'); + } + getTermDocument () { return this.term.document_; } diff --git a/app/lib/containers/hyperterm.js b/app/lib/containers/hyperterm.js index b0b9d64d..e3d4c9a9 100644 --- a/app/lib/containers/hyperterm.js +++ b/app/lib/containers/hyperterm.js @@ -49,6 +49,17 @@ class HyperTerm extends Component { keys.bind('command+shift+]', moveRight); keys.bind('command+alt+left', moveLeft); keys.bind('command+alt+right', moveRight); + + const bound = method => { return term[method].bind(term) } + keys.bind('alt+left', bound('moveWordLeft')); + keys.bind('alt+right', bound('moveWordRight')); + keys.bind('alt+backspace', bound('deleteWordLeft')); + keys.bind('alt+del', bound('deleteWordRight')); + keys.bind('command+left', bound('deleteWordLeft')); + keys.bind('command+right', bound('deleteWordRight')); + keys.bind('command+backspace', bound('deleteLine')); + keys.bind('command+left', bound('moveToStart')); + keys.bind('command+right', bound('moveToEnd')); this.keys = keys; } diff --git a/app/lib/hterm.js b/app/lib/hterm.js index 848299b4..f5475e26 100644 --- a/app/lib/hterm.js +++ b/app/lib/hterm.js @@ -29,7 +29,7 @@ hterm.Terminal.prototype.copySelectionToClipboard = function () { // hyperterm and not the terminal itself const oldKeyDown = hterm.Keyboard.prototype.onKeyDown_; hterm.Keyboard.prototype.onKeyDown_ = function (e) { - if (e.metaKey) { + if (e.metaKey || e.altKey) { return; } return oldKeyDown.call(this, e); diff --git a/menu.js b/menu.js index f07e3a00..4ac05e28 100644 --- a/menu.js +++ b/menu.js @@ -216,7 +216,7 @@ module.exports = function createMenu ({ createWindow, updatePlugins }) { }, { label: 'Show Previous Tab', - accelerator: 'CmdOrCtrl+Left', + accelerator: 'CmdOrCtrl+Option+Left', click (item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('move left req'); @@ -225,7 +225,7 @@ module.exports = function createMenu ({ createWindow, updatePlugins }) { }, { label: 'Show Next Tab', - accelerator: 'CmdOrCtrl+Right', + accelerator: 'CmdOrCtrl+Option+Right', click (item, focusedWindow) { if (focusedWindow) { focusedWindow.rpc.emit('move right req');