diff --git a/website/playground/Playground.js b/website/playground/Playground.js index c7fa74552..a24e04e81 100644 --- a/website/playground/Playground.js +++ b/website/playground/Playground.js @@ -104,7 +104,15 @@ class Playground extends React.Component { this.setContent = (content) => this.setState({ content }); this.clearContent = this.setContent.bind(this, ""); this.resetOptions = () => this.setState({ options: defaultOptions }); - this.setSelection = (selection) => this.setState({ selection }); + this.setSelection = (selection) => { + this.setState({ selection }); + if (this.state.trackCursorOffset) { + this.handleOptionValueChange( + this.cursorOffsetOption, + util.convertSelectionToRange(selection, this.state.content)[0], + ); + } + }; this.setSelectionAsRange = () => { const { selection, content, options } = this.state; const [rangeStart, rangeEnd] = util.convertSelectionToRange( @@ -126,6 +134,9 @@ class Playground extends React.Component { this.rangeEndOption = props.availableOptions.find( (opt) => opt.name === "rangeEnd", ); + this.cursorOffsetOption = props.availableOptions.find( + (opt) => opt.name === "cursorOffset", + ); this.formatInput = this.formatInput.bind(this); this.insertDummyId = this.insertDummyId.bind(this); @@ -172,6 +183,7 @@ class Playground extends React.Component { ...ENABLED_OPTIONS, "rangeStart", "rangeEnd", + "cursorOffset", ]); const cliOptions = util.buildCliArgs(orderedOptions, options); @@ -247,7 +259,7 @@ class Playground extends React.Component { reformat={editorState.showSecondFormat} rethrowEmbedErrors={editorState.rethrowEmbedErrors} > - {({ formatted, debug }) => { + {({ formatted, debug, cursorOffset }) => { const fullReport = this.getMarkdown({ formatted, reformatted: debug.reformatted, @@ -294,6 +306,49 @@ class Playground extends React.Component { Set selected text as range + + ) ) : null} diff --git a/website/playground/panels.js b/website/playground/panels.js index 02117e843..7b39e6b75 100644 --- a/website/playground/panels.js +++ b/website/playground/panels.js @@ -97,10 +97,10 @@ class CodeMirrorPanel extends React.Component { } updateOverlay() { - if (!this.props.readOnly) { - if (this._overlay) { - this._codeMirror.removeOverlay(this._overlay); - } + if (this._overlay) { + this._codeMirror.removeOverlay(this._overlay); + } + if (this.props.overlayStart !== undefined) { const [start, end] = getIndexPosition(this.props.value, [ this.props.overlayStart, this.props.overlayEnd,