import React from 'react'; 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 React.Component { constructor(props, context) { super(props, context); this.terms = {}; this.bound = new WeakMap(); 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; } }; getTermByUid(uid) { return this.terms[uid]; } getActiveTerm() { return this.getTermByUid(this.props.activeSession); } 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); }); } componentDidUpdate(prevProps) { for (let uid in prevProps.sessions) { if (!this.props.sessions[uid]) { this.terms[uid].term.dispose(); delete this.terms[uid]; } } } componentWillUnmount() { this.props.ref_(null); } render() { const shift = !isMac && this.props.termGroups.length > 1; return (