|
1 | 1 | import React from 'react';
|
2 | 2 | import { connect } from 'react-redux';
|
3 | 3 |
|
| 4 | +import { Focus } from './reducers/output/meta'; |
4 | 5 | import State from './state';
|
5 | 6 | import { CommonEditorProps } from './types';
|
6 | 7 |
|
@@ -116,6 +117,19 @@ class AdvancedEditor extends React.PureComponent<AdvancedEditorProps> {
|
116 | 117 | }
|
117 | 118 |
|
118 | 119 | public componentDidUpdate(prevProps, _prevState) {
|
| 120 | + // There's a tricky bug with Ace: |
| 121 | + // |
| 122 | + // 1. Open the page |
| 123 | + // 2. Fill up the page with text but do not cause scrolling |
| 124 | + // 3. Run the code (causing the pane to cover some of the text |
| 125 | + // 4. Try to scroll |
| 126 | + // |
| 127 | + // Ace doesn't know that we changed the visible area and so |
| 128 | + // doesn't recalculate. Knowing if the focus changed is enough |
| 129 | + // to force such a recalculation. |
| 130 | + if (this.props.focus !== prevProps.focus) { |
| 131 | + this._editor.editor.resize(); |
| 132 | + } |
119 | 133 | this.gotoPosition(prevProps.position, this.props.position);
|
120 | 134 | }
|
121 | 135 |
|
@@ -150,6 +164,7 @@ interface AdvancedEditorProps {
|
150 | 164 | name: string,
|
151 | 165 | version: string,
|
152 | 166 | }>;
|
| 167 | + focus?: Focus; |
153 | 168 | }
|
154 | 169 |
|
155 | 170 | // The ACE editor weighs in at ~250K. Adding all of the themes and the
|
@@ -245,11 +260,17 @@ interface AdvancedEditorAsyncState {
|
245 | 260 | interface PropsFromState {
|
246 | 261 | theme: string;
|
247 | 262 | keybinding?: string;
|
| 263 | + focus?: Focus; |
248 | 264 | }
|
249 | 265 |
|
250 |
| -const mapStateToProps = ({ configuration: { theme, keybinding } }: State) => ({ |
251 |
| - theme, |
252 |
| - keybinding: keybinding === 'ace' ? null : keybinding, |
253 |
| -}); |
| 266 | +const mapStateToProps = (state: State) => { |
| 267 | + const { configuration: { theme, keybinding } } = state; |
| 268 | + |
| 269 | + return { |
| 270 | + theme, |
| 271 | + keybinding: keybinding === 'ace' ? null : keybinding, |
| 272 | + focus: state.output.meta.focus, |
| 273 | + }; |
| 274 | +}; |
254 | 275 |
|
255 | 276 | export default connect<PropsFromState, undefined, CommonEditorProps>(mapStateToProps)(AdvancedEditorAsync);
|
0 commit comments