[Windows] Add right click copy/paste (#1247)

* Add right click copy/paste

* Add quick edit config option
This commit is contained in:
Liudas Dzisevicius 2017-02-15 22:22:09 +02:00 committed by Matheus Fernandes
parent 6f758654d2
commit 270fe5bef9
7 changed files with 36 additions and 5 deletions

View file

@ -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',

View file

@ -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,

View file

@ -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) {

View file

@ -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 (

View file

@ -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 => {

View file

@ -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';

View file

@ -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;