From 270fe5bef97b2abb5599f61073a6e28c34c408c4 Mon Sep 17 00:00:00 2001 From: Liudas Dzisevicius Date: Wed, 15 Feb 2017 22:22:09 +0200 Subject: [PATCH] [Windows] Add right click copy/paste (#1247) * Add right click copy/paste * Add quick edit config option --- app/config-default.js | 6 +++++- lib/components/term-group.js | 3 ++- lib/components/term.js | 4 ++++ lib/components/terms.js | 3 ++- lib/containers/terms.js | 3 ++- lib/hterm.js | 14 ++++++++++++++ lib/reducers/ui.js | 8 +++++++- 7 files changed, 36 insertions(+), 5 deletions(-) diff --git a/app/config-default.js b/app/config-default.js index bda83745..2b2be53c 100644 --- a/app/config-default.js +++ b/app/config-default.js @@ -79,7 +79,11 @@ module.exports = { bell: 'SOUND', // if true, selected text will automatically be copied to the clipboard - copyOnSelect: false + copyOnSelect: false, + + // if true, on right click selected text will be copied or pasted if no + // selection is present + quickEdit: false // URL to custom bell // bellSoundURL: 'http://example.com/bell.mp3', diff --git a/lib/components/term-group.js b/lib/components/term-group.js index 8bba81a4..04973689 100644 --- a/lib/components/term-group.js +++ b/lib/components/term-group.js @@ -73,7 +73,8 @@ class TermGroup_ extends Component { onTitle: this.bind(this.props.onTitle, null, uid), onData: this.bind(this.props.onData, null, uid), onURLAbort: this.bind(this.props.onURLAbort, null, uid), - borderColor: this.props.borderColor + borderColor: this.props.borderColor, + quickEdit: this.props.quickEdit }); // This will create a new ref_ function for every render, diff --git a/lib/components/term.js b/lib/components/term.js index e4add848..dd206da9 100644 --- a/lib/components/term.js +++ b/lib/components/term.js @@ -93,6 +93,7 @@ export default class Term extends Component { iframeWindow.addEventListener('wheel', this.handleWheel); this.getScreenNode().addEventListener('mouseup', this.handleMouseUp); + this.getScreenNode().addEventListener('mousedown', this.handleMouseDown); } handleWheel(e) { @@ -275,6 +276,9 @@ export default class Term extends Component { ev.target === this.termRef) { ev.preventDefault(); } + if (this.props.quickEdit) { + this.term.onMouseDown_(ev); + } } componentWillReceiveProps(nextProps) { diff --git a/lib/components/terms.js b/lib/components/terms.js index 76259d62..4f5074b3 100644 --- a/lib/components/terms.js +++ b/lib/components/terms.js @@ -105,7 +105,8 @@ export default class Terms extends Component { onResize: this.props.onResize, onTitle: this.props.onTitle, onData: this.props.onData, - onURLAbort: this.props.onURLAbort + onURLAbort: this.props.onURLAbort, + quickEdit: this.props.quickEdit }); return ( diff --git a/lib/containers/terms.js b/lib/containers/terms.js index 6e40cf5a..a74e9c55 100644 --- a/lib/containers/terms.js +++ b/lib/containers/terms.js @@ -36,7 +36,8 @@ const TermsContainer = connect( bell: state.ui.bell, bellSoundURL: state.ui.bellSoundURL, copyOnSelect: state.ui.copyOnSelect, - modifierKeys: state.ui.modifierKeys + modifierKeys: state.ui.modifierKeys, + quickEdit: state.ui.quickEdit }; }, dispatch => { diff --git a/lib/hterm.js b/lib/hterm.js index cce4b46b..66480135 100644 --- a/lib/hterm.js +++ b/lib/hterm.js @@ -1,3 +1,4 @@ +import {clipboard} from 'electron'; import {hterm, lib} from 'hterm-umdjs'; import runes from 'runes'; @@ -305,11 +306,24 @@ hterm.Terminal.prototype.onMouse_ = function (e) { // the user to click on rows if (e.type === 'mousedown') { e.preventDefault = function () { }; + return; } return oldOnMouse.call(this, e); }; +hterm.Terminal.prototype.onMouseDown_ = function (e) { + // copy/paste on right click + if (e.button === 2) { + const text = this.getSelectionText(); + if (text) { + this.copyStringToClipboard(text); + } else { + this.onVTKeystroke(clipboard.readText()); + } + } +}; + // make background transparent to avoid transparency issues hterm.ScrollPort.prototype.setBackgroundColor = function () { this.screen_.style.backgroundColor = 'transparent'; diff --git a/lib/reducers/ui.js b/lib/reducers/ui.js index cfe5daee..49089743 100644 --- a/lib/reducers/ui.js +++ b/lib/reducers/ui.js @@ -85,7 +85,8 @@ const initial = Immutable({ cmdIsMeta: false }, showHamburgerMenu: '', - showWindowControls: '' + showWindowControls: '', + quickEdit: false }); const currentWindow = remote.getCurrentWindow(); @@ -188,6 +189,11 @@ const reducer = (state = initial, action) => { ret.showWindowControls = config.showWindowControls; } + if (typeof (config.quickEdit) !== 'undefined' && + config.quickEdit !== null) { + ret.quickEdit = config.quickEdit; + } + return ret; })()); break;