Hacky runtime error highlight working

This commit is contained in:
Zach Rispoli 2017-07-17 17:27:21 -04:00 committed by Cassie Tarakajian
parent 1bb0efdac8
commit b5f9879c44
2 changed files with 21 additions and 3 deletions

View file

@ -118,8 +118,6 @@ class Editor extends React.Component {
this._cm.getWrapperElement().style['font-size'] = `${this.props.fontSize}px`;
this._cm.setOption('indentWithTabs', this.props.isTabIndent);
this._cm.setOption('tabSize', this.props.indentationAmount);
this._cm.addLineClass(1, null, 'line-runtime-error');
}
componentWillUpdate(nextProps) {
@ -155,6 +153,20 @@ class Editor extends React.Component {
if (this.props.theme !== prevProps.theme) {
this._cm.setOption('theme', `p5-${this.props.theme}`);
}
for (let i = 0; i < 1000; i += 1) {
this._cm.removeLineClass(i, 'background', 'line-runtime-error');
}
this.props.consoleEvents.forEach((consoleEvent) => {
if (consoleEvent.method === 'error') {
console.log(consoleEvent.arguments);
console.log(consoleEvent.source);
const n = consoleEvent.arguments.replace(')', '').split(' ');
const lineNumber = parseInt(n[n.length - 1], 10) - 1;
console.log(lineNumber);
this._cm.addLineClass(lineNumber, 'background', 'line-runtime-error');
}
});
}
componentWillUnmount() {
@ -290,6 +302,10 @@ Editor.propTypes = {
message: PropTypes.string.isRequired,
id: PropTypes.number.isRequired
})).isRequired,
consoleEvents: PropTypes.arrayOf(PropTypes.shape({
method: PropTypes.string.isRequired,
args: PropTypes.arrayOf(PropTypes.string)
})),
updateLintMessage: PropTypes.func.isRequired,
clearLintMessage: PropTypes.func.isRequired,
indentationAmount: PropTypes.number.isRequired,
@ -325,7 +341,8 @@ Editor.propTypes = {
};
Editor.defaultProps = {
isUserOwner: false
isUserOwner: false,
consoleEvents: []
};
export default Editor;

View file

@ -341,6 +341,7 @@ class IDEView extends React.Component {
collapseSidebar={this.props.collapseSidebar}
isUserOwner={this.isUserOwner()}
clearConsole={this.props.clearConsole}
consoleEvents={this.props.console}
/>
<Console
consoleEvents={this.props.console}