import React from 'react'; import {Component} from '../base-components'; import {decorate, getTermGroupProps} from '../utils/plugins'; import {registerCommandHandlers} from '../command-registry'; import TermGroup_ from './term-group'; import StyleSheet_ from './style-sheet'; const TermGroup = decorate(TermGroup_, 'TermGroup'); const StyleSheet = decorate(StyleSheet_, 'StyleSheet'); const isMac = /Mac/.test(navigator.userAgent); export default class Terms extends Component { constructor(props, context) { super(props, context); this.terms = {}; this.bound = new WeakMap(); this.onRef = this.onRef.bind(this); this.registerCommands = registerCommandHandlers; props.ref_(this); } shouldComponentUpdate(nextProps) { for (const i in nextProps) { if (i === 'write') { continue; } if (this.props[i] !== nextProps[i]) { return true; } } for (const i in this.props) { if (i === 'write') { continue; } if (this.props[i] !== nextProps[i]) { return true; } } return false; } onRef(uid, term) { if (term) { this.terms[uid] = term; } else if (!this.props.sessions[uid]) { delete this.terms[uid]; } } getTermByUid(uid) { return this.terms[uid]; } getActiveTerm() { return this.getTermByUid(this.props.activeSession); } getLastTermIndex() { return this.props.sessions.length - 1; } onTerminal(uid, term) { this.terms[uid] = term; } componentDidMount() { window.addEventListener('contextmenu', () => { const selection = window.getSelection().toString(); const {props: {uid}} = this.getActiveTerm(); this.props.onContextMenu(uid, selection); }); } componentWillUnmount() { this.props.ref_(null); } template(css) { const shift = !isMac && this.props.termGroups.length > 1; return (