copyOnSelect support in canary (#2390)

This commit is contained in:
Derrick Pelletier 2017-10-24 15:06:46 -07:00 committed by CHaBou
parent 280f14e239
commit 0b57dc4158

View file

@ -1,6 +1,7 @@
/* global Blob,URL,requestAnimationFrame */
import React from 'react';
import Terminal from 'xterm';
import {clipboard} from 'electron';
import {PureComponent} from '../base-components';
import terms from '../terms';
import returnKey from '../utils/keymaps';
@ -26,6 +27,7 @@ export default class Term extends PureComponent {
this.onWindowPaste = this.onWindowPaste.bind(this);
this.onTermRef = this.onTermRef.bind(this);
this.onTermWrapperRef = this.onTermWrapperRef.bind(this);
this.onMouseUp = this.onMouseUp.bind(this);
}
componentDidMount() {
@ -129,6 +131,13 @@ export default class Term extends PureComponent {
}
}
onMouseUp() {
// handle copying selected text
if (this.props.copyOnSelect && this.term.hasSelection()) {
clipboard.writeText(this.term.getSelection());
}
}
write(data) {
this.term.write(data);
}
@ -225,7 +234,11 @@ export default class Term extends PureComponent {
template(css) {
return (
<div className={css('fit', this.props.isTermActive && 'active')} style={{padding: this.props.padding}}>
<div
className={css('fit', this.props.isTermActive && 'active')}
style={{padding: this.props.padding}}
onMouseUp={this.onMouseUp}
>
{this.props.customChildrenBefore}
<div ref={this.onTermWrapperRef} className={css('fit', 'wrapper')}>
<div ref={this.onTermRef} className={css('term')} />