Skip to content

Commit

Permalink
Programmatic content capability in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
zenoamaro committed Apr 11, 2020
1 parent d514017 commit 3fe92af
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions demo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,37 +34,32 @@ class Editor extends React.Component {
onEditorChange = (value, delta, source, editor) => {
this.setState({
value: editor.getContents(),
events: [
'text-change('+this.state.value+' -> '+value+')'
].concat(this.state.events)
events: [`[${source}] text-change`, ...this.state.events],
});
}

onEditorChangeSelection = (range, source) => {
this.setState({
selection: range,
events: [
'selection-change('+
this.formatRange(this.state.selection)
+' -> '+
this.formatRange(range)
+')'
].concat(this.state.events)
`[${source}] selection-change(${this.formatRange(this.state.selection)} -> ${this.formatRange(range)})`,
...this.state.events,
]
});
}

onEditorFocus = (range, source) => {
this.setState({
events: [
'focus('+this.formatRange(range)+')'
`[${source}] focus(${this.formatRange(range)})`
].concat(this.state.events)
});
}

onEditorBlur = (previousRange, source) => {
this.setState({
events: [
'blur('+this.formatRange(previousRange)+')'
`[${source}] blur(${this.formatRange(previousRange)})`
].concat(this.state.events)
});
}
Expand All @@ -77,6 +72,10 @@ class Editor extends React.Component {
this.setState({ readOnly: !this.state.readOnly });
}

onSetContents = () => {
this.setState({ value: 'This is some <b>fine</b> example content' });
}

render() {
return (
<div>
Expand Down Expand Up @@ -109,6 +108,9 @@ class Editor extends React.Component {
<button onClick={this.onToggleReadOnly}>
Set {readOnly? 'read/Write' : 'read-only'}
</button>
<button onClick={this.onSetContents}>
Fill contents programmatically
</button>
<button disabled={true}>
Selection: ({selection})
</button>
Expand Down

0 comments on commit 3fe92af

Please sign in to comment.