Skip to content

Commit

Permalink
Hacking ACE Editor to hide cursor in read-only mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Krulis committed May 23, 2019
1 parent eac725d commit 0efbc9b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 25 deletions.
5 changes: 1 addition & 4 deletions src/components/forms/Fields/MarkdownTextAreaField.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ class MarkdownTextAreaField extends Component {
<SourceCodeField {...this.props} mode="markdown" readOnly={disabled} />
<Row>
<Col sm={4}>
<OnOffCheckbox
name={`${name}.togglePreview`}
checked={showPreview}
onChange={() => this.toggleShowPreview()}>
<OnOffCheckbox name={`${name}.togglePreview`} checked={showPreview} onChange={this.toggleShowPreview}>
<FormattedMessage id="app.markdownTextArea.showPreview" defaultMessage="Preview" />
</OnOffCheckbox>
</Col>
Expand Down
46 changes: 25 additions & 21 deletions src/components/forms/Fields/SourceCodeField.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,35 @@ import { loadAceEditor, getAceModeFromExtension } from '../../helpers/AceEditorL
let AceEditor = loadAceEditor();

const SourceCodeField = (
{ input, mode, meta: { error, warning }, label = null, children, tabIndex, onBlur, ...props },
{ input, mode, meta: { error, warning }, label = null, children, tabIndex, onBlur, readOnly = false, ...props },
{ userSettings: { vimMode = false, darkTheme = false } }
) => (
<FormGroup controlId={input.name} validationState={error ? 'error' : warning ? 'warning' : undefined}>
{Boolean(label) && <ControlLabel>{label}</ControlLabel>}
<ClientOnly>
<AceEditor
{...props}
{...input}
mode={getAceModeFromExtension(mode)}
theme={darkTheme ? 'monokai' : 'github'}
name={input.name}
tabIndex={tabIndex}
keyboardHandler={vimMode ? 'vim' : undefined}
width="100%"
height="100%"
minLines={5}
maxLines={20}
onBlur={
() => input.onBlur() // this is a hack that will ensure blur call witout distorting the contents
}
editorProps={{
$blockScrolling: Infinity,
$autoScrollEditorIntoView: true,
}}
/>
<div className={readOnly ? 'noselection' : ''}>
<AceEditor
{...props}
{...input}
mode={getAceModeFromExtension(mode)}
theme={darkTheme ? 'monokai' : 'github'}
name={input.name}
tabIndex={tabIndex}
keyboardHandler={vimMode ? 'vim' : undefined}
width="100%"
height="100%"
minLines={5}
maxLines={20}
readOnly={readOnly}
onBlur={
() => input.onBlur() // this is a hack that will ensure blur call witout distorting the contents
}
editorProps={{
$blockScrolling: Infinity,
$autoScrollEditorIntoView: true,
}}
/>
</div>
</ClientOnly>
{error && <HelpBlock> {error} </HelpBlock>}
{!error && warning && <HelpBlock> {warning} </HelpBlock>}
Expand All @@ -61,6 +64,7 @@ SourceCodeField.propTypes = {
PropTypes.element,
PropTypes.shape({ type: PropTypes.oneOf([FormattedMessage]) }),
]),
readOnly: PropTypes.bool,
onBlur: PropTypes.func,
};

Expand Down
12 changes: 12 additions & 0 deletions src/containers/App/recodex.css
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,15 @@ th.shrink-col {
.wider-tooltip>.tooltip-inner {
max-width: 300px;
}


/*
* ACE Editor Overrides
*/
.noselection .ace_marker-layer .ace_selection {
background: transparent !important;
}

.noselection .ace_cursor {
color: transparent !important;
}

0 comments on commit 0efbc9b

Please sign in to comment.