2016-07-14 15:40:15 -08:00
|
|
|
/* global Blob,URL,requestAnimationFrame */
|
2016-07-13 12:44:24 -08:00
|
|
|
import React from 'react';
|
2016-07-21 11:07:19 -08:00
|
|
|
import Color from 'color';
|
2016-10-19 14:55:06 -08:00
|
|
|
import uuid from 'uuid';
|
2016-07-13 12:44:24 -08:00
|
|
|
import hterm from '../hterm';
|
|
|
|
|
import Component from '../component';
|
2016-10-25 04:53:15 -08:00
|
|
|
import getColorList from '../utils/colors';
|
2016-08-18 00:33:09 -08:00
|
|
|
import notify from '../utils/notify';
|
2016-06-30 22:01:04 -08:00
|
|
|
|
|
|
|
|
export default class Term extends Component {
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
constructor(props) {
|
2016-07-13 12:44:24 -08:00
|
|
|
super(props);
|
2016-10-03 18:00:50 -08:00
|
|
|
this.handleWheel = this.handleWheel.bind(this);
|
|
|
|
|
this.handleMouseDown = this.handleMouseDown.bind(this);
|
2016-11-16 09:44:04 -09:00
|
|
|
this.handleMouseUp = this.handleMouseUp.bind(this);
|
2016-09-21 06:27:11 -08:00
|
|
|
this.handleScrollEnter = this.handleScrollEnter.bind(this);
|
|
|
|
|
this.handleScrollLeave = this.handleScrollLeave.bind(this);
|
2016-11-16 09:44:04 -09:00
|
|
|
this.onHyperCaret = this.onHyperCaret.bind(this);
|
2016-12-21 06:19:41 -09:00
|
|
|
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
|
|
|
this.handleFocus = this.handleFocus.bind(this);
|
2016-07-13 12:44:24 -08:00
|
|
|
props.ref_(this);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
componentDidMount() {
|
|
|
|
|
const {props} = this;
|
2016-10-19 14:55:06 -08:00
|
|
|
this.term = props.term || new hterm.Terminal(uuid.v4());
|
2016-11-16 09:44:04 -09:00
|
|
|
this.term.onHyperCaret(this.hyperCaret);
|
2016-06-30 22:01:04 -08:00
|
|
|
|
2016-07-03 12:35:45 -08:00
|
|
|
// the first term that's created has unknown size
|
|
|
|
|
// subsequent new tabs have size
|
2016-07-13 12:44:24 -08:00
|
|
|
if (props.cols && props.rows) {
|
2016-07-07 07:53:23 -08:00
|
|
|
this.term.realizeSize_(props.cols, props.rows);
|
2016-06-30 22:01:04 -08:00
|
|
|
}
|
|
|
|
|
|
2016-10-19 14:55:06 -08:00
|
|
|
const prefs = this.term.getPrefs();
|
|
|
|
|
|
|
|
|
|
prefs.set('font-family', props.fontFamily);
|
|
|
|
|
prefs.set('font-size', props.fontSize);
|
|
|
|
|
prefs.set('font-smoothing', props.fontSmoothing);
|
|
|
|
|
prefs.set('cursor-color', this.validateColor(props.cursorColor, 'rgba(255,255,255,0.5)'));
|
|
|
|
|
prefs.set('enable-clipboard-notice', false);
|
|
|
|
|
prefs.set('foreground-color', props.foregroundColor);
|
2016-11-09 15:11:51 -09:00
|
|
|
|
|
|
|
|
// hterm.ScrollPort.prototype.setBackgroundColor is overriden
|
|
|
|
|
// to make hterm's background transparent. we still need to set
|
|
|
|
|
// background-color for proper text rendering
|
|
|
|
|
prefs.set('background-color', props.backgroundColor);
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('color-palette-overrides', getColorList(props.colors));
|
|
|
|
|
prefs.set('user-css', this.getStylesheet(props.customCSS));
|
|
|
|
|
prefs.set('scrollbar-visible', false);
|
|
|
|
|
prefs.set('receive-encoding', 'raw');
|
|
|
|
|
prefs.set('send-encoding', 'raw');
|
|
|
|
|
prefs.set('alt-sends-what', 'browser-key');
|
2016-07-03 12:35:45 -08:00
|
|
|
|
2016-08-05 14:30:40 -08:00
|
|
|
if (props.bell === 'SOUND') {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('audible-bell-sound', this.props.bellSoundURL);
|
2016-08-05 14:30:40 -08:00
|
|
|
} else {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('audible-bell-sound', '');
|
2016-08-05 14:30:40 -08:00
|
|
|
}
|
|
|
|
|
|
2016-08-13 13:03:44 -08:00
|
|
|
if (props.copyOnSelect) {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('copy-on-select', true);
|
2016-08-13 13:03:44 -08:00
|
|
|
} else {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('copy-on-select', false);
|
2016-08-13 13:03:44 -08:00
|
|
|
}
|
|
|
|
|
|
2016-07-03 12:35:45 -08:00
|
|
|
this.term.onTerminalReady = () => {
|
|
|
|
|
const io = this.term.io.push();
|
2016-07-13 12:44:24 -08:00
|
|
|
io.onVTKeystroke = io.sendString = props.onData;
|
2016-07-03 12:35:45 -08:00
|
|
|
io.onTerminalResize = (cols, rows) => {
|
2016-07-14 14:02:13 -08:00
|
|
|
if (cols !== this.props.cols || rows !== this.props.rows) {
|
2016-07-13 12:44:24 -08:00
|
|
|
props.onResize(cols, rows);
|
|
|
|
|
}
|
2016-07-03 12:35:45 -08:00
|
|
|
};
|
2016-07-21 15:15:23 -08:00
|
|
|
|
2016-09-30 04:30:11 -08:00
|
|
|
this.term.modifierKeys = props.modifierKeys;
|
2016-07-21 15:15:23 -08:00
|
|
|
// this.term.CursorNode_ is available at this point.
|
|
|
|
|
this.term.setCursorShape(props.cursorShape);
|
2016-10-22 12:05:32 -08:00
|
|
|
|
|
|
|
|
// emit onTitle event when hterm instance
|
|
|
|
|
// wants to set the title of its tab
|
|
|
|
|
this.term.setWindowTitle = props.onTitle;
|
2016-11-16 09:44:04 -09:00
|
|
|
this.term.focusHyperCaret();
|
2016-07-03 12:35:45 -08:00
|
|
|
};
|
2016-10-07 07:07:39 -08:00
|
|
|
this.term.decorate(this.termRef);
|
2016-07-03 12:35:45 -08:00
|
|
|
this.term.installKeyboard();
|
2016-09-21 06:27:11 -08:00
|
|
|
if (this.props.onTerminal) {
|
|
|
|
|
this.props.onTerminal(this.term);
|
|
|
|
|
}
|
2016-07-13 12:44:24 -08:00
|
|
|
|
|
|
|
|
const iframeWindow = this.getTermDocument().defaultView;
|
2016-10-03 18:00:50 -08:00
|
|
|
iframeWindow.addEventListener('wheel', this.handleWheel);
|
|
|
|
|
|
2016-11-16 09:44:04 -09:00
|
|
|
this.getScreenNode().addEventListener('mouseup', this.handleMouseUp);
|
2017-02-15 11:22:09 -09:00
|
|
|
this.getScreenNode().addEventListener('mousedown', this.handleMouseDown);
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
handleWheel(e) {
|
2016-08-06 01:17:09 -08:00
|
|
|
if (this.props.onWheel) {
|
|
|
|
|
this.props.onWheel(e);
|
|
|
|
|
}
|
2016-10-19 14:55:06 -08:00
|
|
|
const prefs = this.term.getPrefs();
|
|
|
|
|
prefs.set('scrollbar-visible', true);
|
2016-07-13 12:44:24 -08:00
|
|
|
clearTimeout(this.scrollbarsHideTimer);
|
|
|
|
|
if (!this.scrollMouseEnter) {
|
|
|
|
|
this.scrollbarsHideTimer = setTimeout(() => {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('scrollbar-visible', false);
|
2016-07-13 12:44:24 -08:00
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
handleScrollEnter() {
|
2016-07-13 12:44:24 -08:00
|
|
|
clearTimeout(this.scrollbarsHideTimer);
|
2016-10-19 14:55:06 -08:00
|
|
|
const prefs = this.term.getPrefs();
|
|
|
|
|
prefs.set('scrollbar-visible', true);
|
2016-07-13 12:44:24 -08:00
|
|
|
this.scrollMouseEnter = true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
handleScrollLeave() {
|
2016-10-19 14:55:06 -08:00
|
|
|
const prefs = this.term.getPrefs();
|
|
|
|
|
prefs.set('scrollbar-visible', false);
|
2016-07-13 12:44:24 -08:00
|
|
|
this.scrollMouseEnter = false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-16 09:44:04 -09:00
|
|
|
handleMouseUp() {
|
|
|
|
|
this.props.onActive();
|
|
|
|
|
// this makes sure that we focus the hyper caret only
|
|
|
|
|
// if a click on the term does not result in a selection
|
|
|
|
|
// otherwise, if we focus without such check, it'd be
|
|
|
|
|
// impossible to select a piece of text
|
|
|
|
|
if (this.term.document_.getSelection().type !== 'Range') {
|
|
|
|
|
this.term.focusHyperCaret();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-21 06:19:41 -09:00
|
|
|
handleFocus() {
|
|
|
|
|
// This will in turn result in `this.focus()` being
|
|
|
|
|
// called, which is unecessary.
|
|
|
|
|
// Should investigate if it matters.
|
|
|
|
|
this.props.onActive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleKeyDown(e) {
|
|
|
|
|
if (e.ctrlKey && e.key === 'c') {
|
|
|
|
|
this.props.onURLAbort();
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-16 09:44:04 -09:00
|
|
|
|
|
|
|
|
onHyperCaret(caret) {
|
|
|
|
|
this.hyperCaret = caret;
|
2016-10-03 18:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
write(data) {
|
2017-01-09 09:05:44 -09:00
|
|
|
// sometimes the preference set above for
|
|
|
|
|
// `receive-encoding` is not known by the vt
|
|
|
|
|
// before we type to write (since the preference
|
|
|
|
|
// manager is asynchronous), so we force it to
|
|
|
|
|
// avoid buffering
|
|
|
|
|
// this fixes a race condition where sometimes
|
|
|
|
|
// opening new sessions results in broken
|
|
|
|
|
// output due to the term attempting to decode
|
|
|
|
|
// as `utf-8` instead of `raw`
|
|
|
|
|
if (this.term.vt.characterEncoding !== 'raw') {
|
|
|
|
|
this.term.vt.characterEncoding = 'raw';
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 20:18:46 -08:00
|
|
|
this.term.io.writeUTF8(data);
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
focus() {
|
2016-11-16 09:44:04 -09:00
|
|
|
this.term.focusHyperCaret();
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
clear() {
|
2016-07-13 12:44:24 -08:00
|
|
|
this.term.clearPreserveCursorRow();
|
2016-07-17 18:52:29 -08:00
|
|
|
|
|
|
|
|
// If cursor is still not at the top, a command is probably
|
|
|
|
|
// running and we'd like to delete the whole screen.
|
|
|
|
|
// Move cursor to top
|
|
|
|
|
if (this.term.getCursorRow() !== 0) {
|
2016-12-15 16:48:47 -09:00
|
|
|
this.write('\x1B[0;0H\x1B[2J');
|
2016-07-17 18:52:29 -08:00
|
|
|
}
|
2016-07-03 12:35:45 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
moveWordLeft() {
|
2016-07-19 09:48:11 -08:00
|
|
|
this.term.onVTKeystroke('\x1bb');
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
moveWordRight() {
|
2016-07-19 09:48:11 -08:00
|
|
|
this.term.onVTKeystroke('\x1bf');
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
deleteWordLeft() {
|
2016-07-19 09:48:11 -08:00
|
|
|
this.term.onVTKeystroke('\x1b\x7f');
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
deleteWordRight() {
|
2016-07-19 09:48:11 -08:00
|
|
|
this.term.onVTKeystroke('\x1bd');
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
deleteLine() {
|
2016-07-19 09:48:11 -08:00
|
|
|
this.term.onVTKeystroke('\x1bw');
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
moveToStart() {
|
2016-07-19 09:48:11 -08:00
|
|
|
this.term.onVTKeystroke('\x01');
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
moveToEnd() {
|
2016-07-19 09:48:11 -08:00
|
|
|
this.term.onVTKeystroke('\x05');
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
selectAll() {
|
2016-08-18 19:09:40 -08:00
|
|
|
this.term.selectAll();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
getScreenNode() {
|
|
|
|
|
return this.term.scrollPort_.getScreenNode();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
getTermDocument() {
|
2016-07-03 12:35:45 -08:00
|
|
|
return this.term.document_;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
getStylesheet(css) {
|
2016-11-19 08:51:01 -09:00
|
|
|
const hyperCaret = `
|
2016-11-16 09:44:04 -09:00
|
|
|
.hyper-caret {
|
|
|
|
|
outline: none;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
color: transparent;
|
|
|
|
|
text-shadow: 0 0 0 black;
|
|
|
|
|
font-family: ${this.props.fontFamily};
|
|
|
|
|
font-size: ${this.props.fontSize}px;
|
|
|
|
|
}
|
2016-11-19 08:51:01 -09:00
|
|
|
`;
|
2017-01-27 16:16:41 -09:00
|
|
|
const scrollBarCss = `
|
|
|
|
|
::-webkit-scrollbar {
|
2017-01-07 16:50:00 -09:00
|
|
|
width: 5px;
|
|
|
|
|
}
|
|
|
|
|
::-webkit-scrollbar-thumb {
|
|
|
|
|
-webkit-border-radius: 10px;
|
|
|
|
|
border-radius: 10px;
|
|
|
|
|
background: ${this.props.borderColor};
|
|
|
|
|
}
|
|
|
|
|
::-webkit-scrollbar-thumb:window-inactive {
|
|
|
|
|
background: ${this.props.borderColor};
|
2017-01-27 16:16:41 -09:00
|
|
|
}
|
|
|
|
|
`;
|
2017-02-16 11:56:20 -09:00
|
|
|
const selectCss = `
|
|
|
|
|
::selection {
|
|
|
|
|
background: ${Color(this.props.cursorColor).alpha(0.4).rgbString()};
|
|
|
|
|
}
|
|
|
|
|
`;
|
2016-11-19 08:51:01 -09:00
|
|
|
return URL.createObjectURL(new Blob([`
|
2016-07-08 13:27:41 -08:00
|
|
|
.cursor-node[focus="false"] {
|
2016-11-19 08:51:01 -09:00
|
|
|
border-width: 1px !important;
|
2016-07-08 13:27:41 -08:00
|
|
|
}
|
2017-02-15 18:59:11 -09:00
|
|
|
x-row {
|
|
|
|
|
line-height: 1.2em;
|
|
|
|
|
}
|
2016-11-19 08:51:01 -09:00
|
|
|
${hyperCaret}
|
2017-01-27 16:16:41 -09:00
|
|
|
${scrollBarCss}
|
2017-02-16 11:56:20 -09:00
|
|
|
${selectCss}
|
2016-07-13 12:44:24 -08:00
|
|
|
${css}
|
2016-11-19 08:51:01 -09:00
|
|
|
`], {type: 'text/css'}));
|
2016-07-08 13:27:41 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
validateColor(color, alternative = 'rgb(255,255,255)') {
|
2016-08-18 00:33:09 -08:00
|
|
|
try {
|
|
|
|
|
return Color(color).rgbString();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
notify(`color "${color}" is invalid`);
|
|
|
|
|
}
|
|
|
|
|
return alternative;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
handleMouseDown(ev) {
|
|
|
|
|
// we prevent losing focus when clicking the boundary
|
|
|
|
|
// wrappers of the main terminal element
|
2016-10-07 07:07:39 -08:00
|
|
|
if (ev.target === this.termWrapperRef ||
|
|
|
|
|
ev.target === this.termRef) {
|
2016-10-03 18:00:50 -08:00
|
|
|
ev.preventDefault();
|
|
|
|
|
}
|
2017-02-15 11:22:09 -09:00
|
|
|
if (this.props.quickEdit) {
|
|
|
|
|
this.term.onMouseDown_(ev);
|
|
|
|
|
}
|
2016-10-03 18:00:50 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
componentWillReceiveProps(nextProps) {
|
2016-06-30 22:01:04 -08:00
|
|
|
if (this.props.url !== nextProps.url) {
|
|
|
|
|
// when the url prop changes, we make sure
|
|
|
|
|
// the terminal starts or stops ignoring
|
|
|
|
|
// key input so that it doesn't conflict
|
|
|
|
|
// with the <webview>
|
|
|
|
|
if (nextProps.url) {
|
2016-12-21 06:19:41 -09:00
|
|
|
this.term.io.push();
|
|
|
|
|
window.addEventListener('keydown', this.handleKeyDown);
|
2016-06-30 22:01:04 -08:00
|
|
|
} else {
|
2016-12-21 06:19:41 -09:00
|
|
|
window.removeEventListener('keydown', this.handleKeyDown);
|
2016-07-03 12:35:45 -08:00
|
|
|
this.term.io.pop();
|
2016-06-30 22:01:04 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
if (!this.props.cleared && nextProps.cleared) {
|
|
|
|
|
this.clear();
|
2016-07-05 12:14:30 -08:00
|
|
|
}
|
|
|
|
|
|
2016-10-19 14:55:06 -08:00
|
|
|
const prefs = this.term.getPrefs();
|
|
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
if (this.props.fontSize !== nextProps.fontSize) {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('font-size', nextProps.fontSize);
|
2016-11-16 09:44:04 -09:00
|
|
|
this.hyperCaret.style.fontSize = nextProps.fontSize + 'px';
|
2016-06-30 22:01:04 -08:00
|
|
|
}
|
2016-07-05 12:14:30 -08:00
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
if (this.props.foregroundColor !== nextProps.foregroundColor) {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('foreground-color', nextProps.foregroundColor);
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
2016-07-03 12:35:45 -08:00
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
if (this.props.fontFamily !== nextProps.fontFamily) {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('font-family', nextProps.fontFamily);
|
2016-11-16 09:44:04 -09:00
|
|
|
this.hyperCaret.style.fontFamily = nextProps.fontFamily;
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
2016-07-03 13:11:45 -08:00
|
|
|
|
2016-07-19 10:30:57 -08:00
|
|
|
if (this.props.fontSmoothing !== nextProps.fontSmoothing) {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('font-smoothing', nextProps.fontSmoothing);
|
2016-07-19 10:30:57 -08:00
|
|
|
}
|
|
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
if (this.props.cursorColor !== nextProps.cursorColor) {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('cursor-color', this.validateColor(nextProps.cursorColor, 'rgba(255,255,255,0.5)'));
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
2016-07-03 12:35:45 -08:00
|
|
|
|
2016-07-21 15:15:23 -08:00
|
|
|
if (this.props.cursorShape !== nextProps.cursorShape) {
|
|
|
|
|
this.term.setCursorShape(nextProps.cursorShape);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
if (this.props.colors !== nextProps.colors) {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('color-palette-overrides', getColorList(nextProps.colors));
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
2016-07-03 12:35:45 -08:00
|
|
|
|
2016-07-13 12:44:24 -08:00
|
|
|
if (this.props.customCSS !== nextProps.customCSS) {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('user-css', this.getStylesheet(nextProps.customCSS));
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
2016-08-05 14:30:40 -08:00
|
|
|
|
|
|
|
|
if (this.props.bell === 'SOUND') {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('audible-bell-sound', this.props.bellSoundURL);
|
2016-08-05 14:30:40 -08:00
|
|
|
} else {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('audible-bell-sound', '');
|
2016-08-05 14:30:40 -08:00
|
|
|
}
|
2016-08-13 13:03:44 -08:00
|
|
|
|
|
|
|
|
if (this.props.copyOnSelect) {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('copy-on-select', true);
|
2016-08-13 13:03:44 -08:00
|
|
|
} else {
|
2016-10-19 14:55:06 -08:00
|
|
|
prefs.set('copy-on-select', false);
|
2016-08-13 13:03:44 -08:00
|
|
|
}
|
2016-06-30 22:01:04 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
componentWillUnmount() {
|
2016-07-13 12:44:24 -08:00
|
|
|
clearTimeout(this.scrollbarsHideTimer);
|
|
|
|
|
this.props.ref_(null);
|
2016-06-30 22:01:04 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
template(css) {
|
2016-10-03 18:00:50 -08:00
|
|
|
return (<div
|
2016-10-07 07:07:39 -08:00
|
|
|
ref={component => {
|
|
|
|
|
this.termWrapperRef = component;
|
|
|
|
|
}}
|
2016-11-19 11:05:48 -09:00
|
|
|
className={css('fit', this.props.isTermActive && 'active')}
|
2016-10-03 18:00:50 -08:00
|
|
|
onMouseDown={this.handleMouseDown}
|
|
|
|
|
style={{padding: this.props.padding}}
|
|
|
|
|
>
|
2016-07-13 12:44:24 -08:00
|
|
|
{ this.props.customChildrenBefore }
|
2016-10-07 07:07:39 -08:00
|
|
|
<div
|
|
|
|
|
ref={component => {
|
|
|
|
|
this.termRef = component;
|
|
|
|
|
}}
|
|
|
|
|
className={css('fit', 'term')}
|
|
|
|
|
/>
|
2016-09-21 06:27:11 -08:00
|
|
|
{ this.props.url ?
|
|
|
|
|
<webview
|
2016-12-21 06:19:41 -09:00
|
|
|
key="hyper-webview"
|
2016-09-21 06:27:11 -08:00
|
|
|
src={this.props.url}
|
2016-10-03 18:00:50 -08:00
|
|
|
onFocus={this.handleFocus}
|
2016-09-21 06:27:11 -08:00
|
|
|
style={{
|
2016-10-11 09:27:00 -08:00
|
|
|
background: '#fff',
|
2016-09-21 06:27:11 -08:00
|
|
|
position: 'absolute',
|
|
|
|
|
top: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
display: 'inline-flex',
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%'
|
|
|
|
|
}}
|
|
|
|
|
/> :
|
2016-12-21 06:19:41 -09:00
|
|
|
<div // eslint-disable-line react/jsx-indent
|
|
|
|
|
key="scrollbar"
|
|
|
|
|
className={css('scrollbarShim')}
|
|
|
|
|
onMouseEnter={this.handleScrollEnter}
|
|
|
|
|
onMouseLeave={this.handleScrollLeave}
|
|
|
|
|
/>
|
2016-06-30 22:01:04 -08:00
|
|
|
}
|
2016-12-21 06:19:41 -09:00
|
|
|
<div key="hyper-caret" contentEditable className="hyper-caret" ref={this.onHyperCaret}/>
|
2016-07-13 12:44:24 -08:00
|
|
|
{ this.props.customChildren }
|
2016-09-21 06:27:11 -08:00
|
|
|
</div>);
|
2016-06-30 22:01:04 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
styles() {
|
2016-07-13 12:44:24 -08:00
|
|
|
return {
|
|
|
|
|
fit: {
|
2016-10-03 18:00:50 -08:00
|
|
|
display: 'block',
|
2016-07-13 12:44:24 -08:00
|
|
|
width: '100%',
|
|
|
|
|
height: '100%'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
term: {
|
|
|
|
|
position: 'relative'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
scrollbarShim: {
|
|
|
|
|
position: 'fixed',
|
|
|
|
|
right: 0,
|
|
|
|
|
width: '50px',
|
|
|
|
|
top: 0,
|
2016-07-22 10:49:25 -08:00
|
|
|
bottom: 0,
|
|
|
|
|
pointerEvents: 'none'
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
};
|
2016-06-30 22:01:04 -08:00
|
|
|
}
|
|
|
|
|
}
|