Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows] Add right click copy/paste #1247

Merged
merged 3 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion app/config-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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',
Expand Down
3 changes: 2 additions & 1 deletion lib/components/term-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions lib/components/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,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) {
Expand Down Expand Up @@ -253,6 +254,9 @@ export default class Term extends Component {
ev.target === this.termRef) {
ev.preventDefault();
}
if (this.props.quickEdit) {
this.term.onMouseDown_(ev);
}
}

componentWillReceiveProps(nextProps) {
Expand Down
3 changes: 2 additions & 1 deletion lib/components/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion lib/containers/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
14 changes: 14 additions & 0 deletions lib/hterm.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {clipboard} from 'electron';
import {hterm, lib} from 'hterm-umdjs';
import runes from 'runes';

Expand Down Expand Up @@ -286,11 +287,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';
Expand Down
8 changes: 7 additions & 1 deletion lib/reducers/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ const initial = Immutable({
cmdIsMeta: false
},
showHamburgerMenu: '',
showWindowControls: ''
showWindowControls: '',
quickEdit: false
});

const reducer = (state = initial, action) => {
Expand Down Expand Up @@ -183,6 +184,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;
Expand Down