diff --git a/src/render/idyll-display/components/component-editor/code-cell.js b/src/render/idyll-display/components/component-editor/code-cell.js index d43da12..fea84ae 100644 --- a/src/render/idyll-display/components/component-editor/code-cell.js +++ b/src/render/idyll-display/components/component-editor/code-cell.js @@ -9,45 +9,38 @@ export default class EditableCodeCell extends React.Component { constructor(props) { super(props); this.state = { - editing: false + editing: true, + referenceMarkup: props.markup, + currentMarkup: props.markup + }; this._cellCodeRef = React.createRef(); } - toggleEdit = e => { - e.stopPropagation(); - if (this.state.editing) { - this.setState({ - editing: false - }); - } else { - this.edit(); - } - }; - - edit = () => { - this.setState( - { - editing: true - }, - () => { - this._cellCodeRef.current.focus(); - } - ); - }; - // Executes code change execute = () => { - this.props.onExecute(this._cellCodeRef.current.innerText); + this.setState({ + referenceMarkup: this._cellCodeRef.current.innerText, + currentMarkup: this._cellCodeRef.current.innerText + }, () => { + this.props.onExecute(this._cellCodeRef.current.innerText); + }) + }; // Updates markup on blur onBlur = e => { - this.toggleEdit(e); this.props.onBlur && this.props.onBlur(this._cellCodeRef.current.innerText); }; + handleKeyUp = e => { + e.stopPropagation(); + this.setState({ + currentMarkup: this._cellCodeRef.current.innerText.trim() + }) + } + handleKeyDown = e => { e.stopPropagation(); if (e.shiftKey && e.key === EXECUTE_KEY) { @@ -57,10 +50,10 @@ export default class EditableCodeCell extends React.Component { }; render() { - const { editing } = this.state; + const { editing, referenceMarkup, currentMarkup } = this.state; return ( -
+
{this.props.markup}diff --git a/src/render/idyll-display/components/component-editor/properties.js b/src/render/idyll-display/components/component-editor/properties.js index 1024dee..9749240 100644 --- a/src/render/idyll-display/components/component-editor/properties.js +++ b/src/render/idyll-display/components/component-editor/properties.js @@ -49,7 +49,6 @@ export default withContext( this.props.context.ast, this.props.context.activeComponent.id ); - console.log('updating node with properties', node, this.props.context.ast, this.props.context.activeComponent.id); this.debouncedSetAst(node, propertyName, propertyValue); } diff --git a/test/components.test.js b/test/components.test.js index 970da89..d00cb29 100644 --- a/test/components.test.js +++ b/test/components.test.js @@ -193,7 +193,7 @@ describe('', () => { let div = component.find('div'); - expect(div.props().contentEditable).toBeFalsy(); + expect(div.props().contentEditable).toBeTruthy(); const pre = component.find('pre'); pre.simulate('click');