Skip to content

Commit

Permalink
fix: Fix multi-line indentation (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Dec 4, 2018
1 parent 2bd2721 commit 766c15e
Showing 1 changed file with 34 additions and 52 deletions.
86 changes: 34 additions & 52 deletions src/Playroom/Playroom.js
Expand Up @@ -217,6 +217,38 @@ export default class Playroom extends Component {
})
);

const codeMirrorEl = (
<ReactCodeMirror
codeMirrorInstance={codeMirror}
ref={this.storeCodeMirrorRef}
value={code}
onChange={this.handleChange}
options={{
mode: 'jsx',
autoCloseTags: true,
autoCloseBrackets: true,
theme: 'neo',
gutters: [styles.gutter],
hintOptions: { schemaInfo: tags },
extraKeys: {
Tab: cm => {
if (cm.somethingSelected()) {
cm.indentSelection('add');
} else {
const indent = cm.getOption('indentUnit');
const spaces = Array(indent + 1).join(' ');
cm.replaceSelection(spaces);
}
},
"'<'": completeAfter,
"'/'": completeIfAfterLt,
"' '": completeIfInTag,
"'='": completeIfInTag
}
}}
/>
);

if (editorUndocked && codeReady) {
return (
<div>
Expand All @@ -234,33 +266,7 @@ export default class Playroom extends Component {
width={window.outerWidth}
onClose={this.handleRedockEditor}
>
<div className={styles.undockedEditorContainer}>
<ReactCodeMirror
codeMirrorInstance={codeMirror}
ref={this.storeCodeMirrorRef}
value={code}
onChange={this.handleChange}
options={{
mode: 'jsx',
autoCloseTags: true,
autoCloseBrackets: true,
theme: 'neo',
gutters: [styles.gutter],
hintOptions: { schemaInfo: tags },
extraKeys: {
Tab: cm => {
const indent = cm.getOption('indentUnit');
const spaces = Array(indent + 1).join(' ');
cm.replaceSelection(spaces);
},
"'<'": completeAfter,
"'/'": completeIfAfterLt,
"' '": completeIfInTag,
"'='": completeIfInTag
}
}}
/>
</div>
<div className={styles.undockedEditorContainer}>{codeMirrorEl}</div>
</WindowPortal>
</div>
);
Expand Down Expand Up @@ -299,31 +305,7 @@ export default class Playroom extends Component {
onClick={this.handleUndockEditor}
/>
</div>
<ReactCodeMirror
codeMirrorInstance={codeMirror}
ref={this.storeCodeMirrorRef}
value={code}
onChange={this.handleChange}
options={{
mode: 'jsx',
autoCloseTags: true,
autoCloseBrackets: true,
theme: 'neo',
gutters: [styles.gutter],
hintOptions: { schemaInfo: tags },
extraKeys: {
Tab: cm => {
const indent = cm.getOption('indentUnit');
const spaces = Array(indent + 1).join(' ');
cm.replaceSelection(spaces);
},
"'<'": completeAfter,
"'/'": completeIfAfterLt,
"' '": completeIfInTag,
"'='": completeIfInTag
}
}}
/>
{codeMirrorEl}
</Resizable>
</div>
);
Expand Down

0 comments on commit 766c15e

Please sign in to comment.