Skip to content

Commit 84f5f4a

Browse files
committed
Extract source editor to separate component.
This prepares it for integration with CodeMirror.
1 parent 691a683 commit 84f5f4a

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

js/editor.js

+14-4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,17 @@ class LoadSketch {
164164
}
165165
}
166166

167+
class Source extends Component {
168+
onInput(e) {
169+
const source = e.target.value;
170+
this.props.onSourceChanged(source);
171+
}
172+
173+
render(props) {
174+
return h('textarea', { className: 'editor__area', value: this.props.source, onInput: this.onInput.bind(this), readonly: this.props.loading });
175+
}
176+
}
177+
167178
class Editor extends Component {
168179
constructor(props) {
169180
super(props);
@@ -244,8 +255,7 @@ class Editor extends Component {
244255
document.querySelector('html').classList.remove('fullscreen');
245256
}
246257

247-
onInput(e) {
248-
const source = e.target.value;
258+
onSourceChanged(source) {
249259
this.setState({ source });
250260
if (this.props.onSourceChanged) {
251261
this.props.onSourceChanged(source);
@@ -345,8 +355,8 @@ class Editor extends Component {
345355
h(SeedPicker, { seed: this.state.seed, onSetSeed: this.onSetSeed.bind(this), onPrevSeed: this.onPrevSeed.bind(this), onNextSeed: this.onNextSeed.bind(this) })
346356
),
347357
h('div', { className: 'editor__source' },
348-
h('textarea', { className: 'editor__area', value: source, onInput: this.onInput.bind(this), readonly: state.loading }),
349-
debugView
358+
h(Source, { source, loading: this.state.loading, onSourceChanged: this.onSourceChanged.bind(this) }),
359+
debugView
350360
),
351361
),
352362
h('div', { className: 'editor__viewer-wrap'},

0 commit comments

Comments
 (0)