mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-15 21:28:40 -09:00
Fix horizontal split and term resize
This commit is contained in:
parent
b5eb437751
commit
c91c025edd
3 changed files with 36 additions and 29 deletions
|
|
@ -82,6 +82,7 @@ export default class SplitPane extends Component {
|
||||||
template(css) {
|
template(css) {
|
||||||
const children = this.props.children;
|
const children = this.props.children;
|
||||||
const {direction, borderColor} = this.props;
|
const {direction, borderColor} = this.props;
|
||||||
|
const sizeProperty = direction === 'horizontal' ? 'height' : 'flexBasis'
|
||||||
let {sizes} = this.props;
|
let {sizes} = this.props;
|
||||||
if (!sizes) {
|
if (!sizes) {
|
||||||
// workaround for the fact that if we don't specify
|
// workaround for the fact that if we don't specify
|
||||||
|
|
@ -93,6 +94,8 @@ export default class SplitPane extends Component {
|
||||||
{
|
{
|
||||||
React.Children.map(children, (child, i) => {
|
React.Children.map(children, (child, i) => {
|
||||||
const style = {
|
const style = {
|
||||||
|
// flexBasis doesn't work for the first horizontal pane, height need to be specified
|
||||||
|
[sizeProperty]: (sizes[i] * 100) + '%',
|
||||||
flexBasis: (sizes[i] * 100) + '%',
|
flexBasis: (sizes[i] * 100) + '%',
|
||||||
flexGrow: 0
|
flexGrow: 0
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,8 @@ class TermGroup_ extends Component {
|
||||||
super(props, context);
|
super(props, context);
|
||||||
this.bound = new WeakMap();
|
this.bound = new WeakMap();
|
||||||
this.termRefs = {}
|
this.termRefs = {}
|
||||||
|
this.sizeChanged = false;
|
||||||
|
this.onTermRef = this.onTermRef.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
bind(fn, thisObj, uid) {
|
bind(fn, thisObj, uid) {
|
||||||
|
|
@ -45,6 +47,11 @@ class TermGroup_ extends Component {
|
||||||
</SplitPane>);
|
</SplitPane>);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onTermRef(uid, term) {
|
||||||
|
this.term = term;
|
||||||
|
this.props.ref_(uid, term)
|
||||||
|
}
|
||||||
|
|
||||||
renderTerm(uid) {
|
renderTerm(uid) {
|
||||||
const session = this.props.sessions[uid];
|
const session = this.props.sessions[uid];
|
||||||
const termRef = this.props.terms[uid];
|
const termRef = this.props.terms[uid];
|
||||||
|
|
@ -79,32 +86,22 @@ class TermGroup_ extends Component {
|
||||||
// which is inefficient. Should maybe do something similar
|
// which is inefficient. Should maybe do something similar
|
||||||
// to this.bind.
|
// to this.bind.
|
||||||
return (<Term
|
return (<Term
|
||||||
ref_={term => {
|
ref_={this.onTermRef}
|
||||||
if (term) {
|
|
||||||
this.termRefs[uid] = term
|
|
||||||
} else {
|
|
||||||
delete this.termRefs[uid]
|
|
||||||
}
|
|
||||||
this.props.ref_(uid, term)
|
|
||||||
}}
|
|
||||||
key={uid}
|
key={uid}
|
||||||
{...props}
|
{...props}
|
||||||
/>);
|
/>);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps (nextProps) {
|
componentWillReceiveProps (nextProps) {
|
||||||
if (this.props.termGroup.sizes != nextProps.termGroup.sizes) {
|
|
||||||
// whenever we change the ratio, we want to force a resize
|
if (this.props.termGroup.sizes != nextProps.termGroup.sizes || nextProps.sizeChanged) {
|
||||||
// on all the splits. technically, we could have done this
|
this.term && this.term.measureResize();
|
||||||
// at the reducer level, which would be a better place for
|
// Indicate to children that their size has changed even if their ratio hasn't
|
||||||
// it, but this is not too inelegant considering that terms
|
this.sizeChanged = true;
|
||||||
// are already reporting their own size when, for example,
|
} else {
|
||||||
// the window gets resized
|
this.sizeChanged = false;
|
||||||
for (const uid in this.termRefs) {
|
|
||||||
const term = this.termRefs[uid]
|
|
||||||
term.measureResize();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template() {
|
template() {
|
||||||
|
|
@ -115,7 +112,8 @@ class TermGroup_ extends Component {
|
||||||
|
|
||||||
const groups = childGroups.map(child => {
|
const groups = childGroups.map(child => {
|
||||||
const props = getTermGroupProps(child.uid, this.props.parentProps, Object.assign({}, this.props, {
|
const props = getTermGroupProps(child.uid, this.props.parentProps, Object.assign({}, this.props, {
|
||||||
termGroup: child
|
termGroup: child,
|
||||||
|
sizeChanged: this.sizeChanged
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return (<DecoratedTermGroup
|
return (<DecoratedTermGroup
|
||||||
|
|
|
||||||
|
|
@ -17,12 +17,14 @@ export default class Term extends Component {
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
props.ref_(this);
|
props.ref_(props.uid, this);
|
||||||
this.termRef = null
|
this.termRef = null
|
||||||
this.termWrapperRef = null
|
this.termWrapperRef = null
|
||||||
this.termRect = null
|
this.termRect = null
|
||||||
this.onOpen = this.onOpen.bind(this)
|
this.onOpen = this.onOpen.bind(this)
|
||||||
this.onWindowResize = this.onWindowResize.bind(this)
|
this.onWindowResize = this.onWindowResize.bind(this)
|
||||||
|
this.onTermRef = this.onTermRef.bind(this)
|
||||||
|
this.onTermWrapperRef = this.onTermWrapperRef.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
|
@ -187,9 +189,17 @@ export default class Term extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onTermWrapperRef(component) {
|
||||||
|
this.termWrapperRef = component;
|
||||||
|
}
|
||||||
|
|
||||||
|
onTermRef(component) {
|
||||||
|
this.termRef = component;
|
||||||
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
terms[this.props.uid] = this;
|
terms[this.props.uid] = null;
|
||||||
this.props.ref_(null);
|
this.props.ref_(this.props.uid, null);
|
||||||
|
|
||||||
// to clean up the terminal, we remove the listeners
|
// to clean up the terminal, we remove the listeners
|
||||||
// instead of invoking `destroy`, since it will make the
|
// instead of invoking `destroy`, since it will make the
|
||||||
|
|
@ -209,15 +219,11 @@ export default class Term extends Component {
|
||||||
>
|
>
|
||||||
{ this.props.customChildrenBefore }
|
{ this.props.customChildrenBefore }
|
||||||
<div
|
<div
|
||||||
ref={component => {
|
ref={this.onTermWrapperRef}
|
||||||
this.termWrapperRef = component;
|
|
||||||
}}
|
|
||||||
className={css('fit', 'wrapper')}
|
className={css('fit', 'wrapper')}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
ref={component => {
|
ref={this.onTermRef}
|
||||||
this.termRef = component;
|
|
||||||
}}
|
|
||||||
className={css('term')}
|
className={css('term')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue