mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 20:38:41 -09:00
* npm: add .npmrc with save-exact=true * split panes: create initial implementation This allows users to split their Hyperterm terms into multiple nested splits, both vertical and horizontal. Fixes #56 * split panes: suport closing tabs and individual panes * split panes: ensure new splits are placed at the correct index New split panes should be placed after the currently active pane, not at the end like they were previously. * split panes: add explicit dependency to uuid * split panes: implement split pane cycling This adds menu buttons for moving back and forward between open split panes in the currect terminal tab. Doesn't add a hotkey yet, needs some bikeshedding. * split panes: move activeSessionUid to its own object It made little sense to have so many objects with `activeSessionUid` set to `null` when it only mattered on the top level. Now it's an object mapping term-group `uid` to `sessionUid` instead. * split panes: make sure closing the last split pane exits the app * split panes: fix a crash after closing specific panes Sometimes the terminal would crash when a specific split pane was closed, because the `activeSessions` mapping wasn't updated correctly. * split panes: fix a bug that caused initial session sizing to be wrong * fix all our focus / blur issues in one fell swoop :O (famous last words) * get rid of react warning * hterm: make sure not to lose focus when VT listens on clicks * term: restore onactive callback * add missing `return` to override (just in case) * split pane: new split pane implementation * goodbye react-split-pane * added term group resizing action and reducer * terms: supply border color so that we can use it for splits * term-group: add resizing hook * term-groups: add resizing constant * remove split pane css side-effect * split panes: pass existing hterm instances to Term * split panes: add keybindings for split pane cycling * split panes: remove unused action * split panes: remove unused styling * split-pane: remove `console.log` * split-pane: remove `console.log` * split panes: rebalance sizes on insert/removal * split panes: pass existing hterm instances to Term * split panes: add keybindings for split pane cycling * split panes: remove unused action * split panes: remove unused styling * split panes: rebalance sizes on insert/removal * split panes: set a minimum size for resizing * split-pane: fix vertical splits * css :| * package: bump electron * split panes: attach onFocus listener to webviews * 1.4.1 and 1.4.2 are broken. they have the following regression: - open google.com on the main window - open a new tab - come back to previous tab. webview is gone :| * split panes: handle PTY exits * split panes: add linux friendly keybindings
176 lines
4.7 KiB
JavaScript
176 lines
4.7 KiB
JavaScript
import Mousetrap from 'mousetrap';
|
|
import React from 'react';
|
|
|
|
import Component from '../component';
|
|
import {connect} from '../utils/plugins';
|
|
import * as uiActions from '../actions/ui';
|
|
import * as termGroupActions from '../actions/term-groups';
|
|
|
|
import HeaderContainer from './header';
|
|
import TermsContainer from './terms';
|
|
import NotificationsContainer from './notifications';
|
|
|
|
const isMac = /Mac/.test(navigator.userAgent);
|
|
|
|
class HyperTerm extends Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.handleFocusActive = this.handleFocusActive.bind(this);
|
|
this.onTermsRef = this.onTermsRef.bind(this);
|
|
}
|
|
|
|
componentWillReceiveProps(next) {
|
|
if (this.props.backgroundColor !== next.backgroundColor) {
|
|
// this can be removed when `setBackgroundColor` in electron
|
|
// starts working again
|
|
document.body.style.backgroundColor = next.backgroundColor;
|
|
}
|
|
}
|
|
|
|
handleFocusActive() {
|
|
const term = this.terms.getActiveTerm();
|
|
if (term) {
|
|
term.focus();
|
|
}
|
|
}
|
|
|
|
attachKeyListeners() {
|
|
const {moveTo, moveLeft, moveRight, splitHorizontal, splitVertical} = this.props;
|
|
const term = this.terms.getActiveTerm();
|
|
if (!term) {
|
|
return;
|
|
}
|
|
const lastIndex = this.terms.getLastTermIndex();
|
|
const document = term.getTermDocument();
|
|
const keys = new Mousetrap(document);
|
|
if (process.platform === 'darwin') {
|
|
keys.bind('command+d', splitVertical);
|
|
keys.bind('command+shift+d', splitHorizontal);
|
|
}
|
|
|
|
keys.bind('command+1', moveTo.bind(this, 0));
|
|
keys.bind('command+2', moveTo.bind(this, 1));
|
|
keys.bind('command+3', moveTo.bind(this, 2));
|
|
keys.bind('command+4', moveTo.bind(this, 3));
|
|
keys.bind('command+5', moveTo.bind(this, 4));
|
|
keys.bind('command+6', moveTo.bind(this, 5));
|
|
keys.bind('command+7', moveTo.bind(this, 6));
|
|
keys.bind('command+8', moveTo.bind(this, 7));
|
|
keys.bind('command+9', moveTo.bind(this, lastIndex));
|
|
|
|
keys.bind('command+shift+left', moveLeft);
|
|
keys.bind('command+shift+right', moveRight);
|
|
keys.bind('command+shift+[', moveLeft);
|
|
keys.bind('command+shift+]', moveRight);
|
|
keys.bind('command+alt+left', moveLeft);
|
|
keys.bind('command+alt+right', moveRight);
|
|
keys.bind('ctrl+shift+tab', moveLeft);
|
|
keys.bind('ctrl+tab', moveRight);
|
|
|
|
const bound = method => term[method].bind(term);
|
|
keys.bind('alt+left', bound('moveWordLeft'));
|
|
keys.bind('alt+right', bound('moveWordRight'));
|
|
keys.bind('alt+backspace', bound('deleteWordLeft'));
|
|
keys.bind('alt+del', bound('deleteWordRight'));
|
|
keys.bind('command+backspace', bound('deleteLine'));
|
|
keys.bind('command+left', bound('moveToStart'));
|
|
keys.bind('command+right', bound('moveToEnd'));
|
|
keys.bind('command+a', bound('selectAll'));
|
|
this.keys = keys;
|
|
}
|
|
|
|
onTermsRef(terms) {
|
|
this.terms = terms;
|
|
}
|
|
|
|
componentDidUpdate(prev) {
|
|
if (prev.activeSession !== this.props.activeSession) {
|
|
if (this.keys) {
|
|
this.keys.reset();
|
|
}
|
|
this.handleFocusActive();
|
|
this.attachKeyListeners();
|
|
}
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
if (this.keys) {
|
|
this.keys.reset();
|
|
}
|
|
document.body.style.backgroundColor = 'inherit';
|
|
}
|
|
|
|
template(css) {
|
|
const {isMac, customCSS, borderColor} = this.props;
|
|
return (<div>
|
|
<div
|
|
style={{borderColor}}
|
|
className={css('main', isMac && 'mainRounded')}
|
|
>
|
|
<HeaderContainer/>
|
|
<TermsContainer ref_={this.onTermsRef}/>
|
|
</div>
|
|
|
|
<NotificationsContainer/>
|
|
<style dangerouslySetInnerHTML={{__html: customCSS}}/>
|
|
{ this.props.customChildren }
|
|
</div>);
|
|
}
|
|
|
|
styles() {
|
|
return {
|
|
main: {
|
|
position: 'fixed',
|
|
top: 0,
|
|
left: 0,
|
|
right: 0,
|
|
bottom: 0,
|
|
// can be overridden by inline style above
|
|
border: '1px solid #333'
|
|
},
|
|
|
|
mainRounded: {
|
|
borderRadius: '5px'
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
const HyperTermContainer = connect(
|
|
state => {
|
|
return {
|
|
isMac,
|
|
customCSS: state.ui.css,
|
|
borderColor: state.ui.borderColor,
|
|
activeSession: state.sessions.activeUid,
|
|
backgroundColor: state.ui.backgroundColor
|
|
};
|
|
},
|
|
dispatch => {
|
|
return {
|
|
moveTo: i => {
|
|
dispatch(uiActions.moveTo(i));
|
|
},
|
|
|
|
moveLeft: () => {
|
|
dispatch(uiActions.moveLeft());
|
|
},
|
|
|
|
moveRight: () => {
|
|
dispatch(uiActions.moveRight());
|
|
},
|
|
|
|
splitHorizontal: () => {
|
|
dispatch(termGroupActions.requestHorizontalSplit());
|
|
},
|
|
|
|
splitVertical: () => {
|
|
dispatch(termGroupActions.requestVerticalSplit());
|
|
}
|
|
};
|
|
},
|
|
null,
|
|
{withRef: true}
|
|
)(HyperTerm, 'HyperTerm');
|
|
|
|
export default HyperTermContainer;
|