Fix preview toggling issues with CodeMirror

This commit is contained in:
Jori Lallo
2016-06-03 00:28:36 -07:00
parent 3f993ac813
commit 6206acfad0
2 changed files with 9 additions and 3 deletions

View File

@@ -42,6 +42,12 @@ class DocumentEdit extends Component {
})
}
onPreviewToggle = () => {
// Force re-render to fix issues with
// Codemirror cursor (gets out of sync)
state.togglePreview(this.forceUpdate());
}
render() {
let title = (
<Title
@@ -60,7 +66,7 @@ class DocumentEdit extends Component {
/>
</HeaderAction>
<DropdownMenu label="More">
<MenuItem onClick={ state.togglePreview }>
<MenuItem onClick={ this.onPreviewToggle }>
Preview <Switch checked={ state.preview } />
</MenuItem>
</DropdownMenu>

View File

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