Fix scrolling + codemirror render

This commit is contained in:
Jori Lallo
2016-06-03 01:01:01 -07:00
parent 6206acfad0
commit 1345f9629d
4 changed files with 11 additions and 8 deletions

View File

@@ -17,9 +17,13 @@ import { client } from '../../utils/ApiClient';
@observer @observer
class MarkdownAtlas extends React.Component { class MarkdownAtlas extends React.Component {
static propTypes = { static propTypes = {
text: React.PropTypes.string, text: React.PropTypes.string.isRequired,
onChange: React.PropTypes.func, onChange: React.PropTypes.func.isRequired,
replaceText: React.PropTypes.func, replaceText: React.PropTypes.func.isRequired,
// This is actually not used but it triggers
// re-render to help with CodeMirror focus issues
preview: React.PropTypes.bool.isRequired,
} }
getEditorInstance = () => { getEditorInstance = () => {

View File

@@ -43,9 +43,7 @@ class DocumentEdit extends Component {
} }
onPreviewToggle = () => { onPreviewToggle = () => {
// Force re-render to fix issues with state.togglePreview();
// Codemirror cursor (gets out of sync)
state.togglePreview(this.forceUpdate());
} }
render() { render() {
@@ -94,6 +92,7 @@ class DocumentEdit extends Component {
onChange={ state.updateText } onChange={ state.updateText }
text={ state.text } text={ state.text }
replaceText={ state.replaceText } replaceText={ state.replaceText }
preview={ state.preview }
/> />
</EditorPane> </EditorPane>
{ state.preview ? ( { state.preview ? (

View File

@@ -27,6 +27,7 @@
.paneContent { .paneContent {
flex: 1; flex: 1;
justify-content: center; justify-content: center;
height: 100%;
} }
.fullWidth { .fullWidth {

View File

@@ -83,9 +83,8 @@ const documentEditState = new class DocumentEditState {
this.text = this.text.replace(args.original, args.new); this.text = this.text.replace(args.original, args.new);
} }
@action togglePreview = (callback) => { @action togglePreview = () => {
this.preview = !this.preview; this.preview = !this.preview;
callback();
} }
constructor() { constructor() {