Skip to content

Commit 0efbc9b

Browse files
author
Martin Krulis
committed
Hacking ACE Editor to hide cursor in read-only mode.
1 parent eac725d commit 0efbc9b

File tree

3 files changed

+38
-25
lines changed

3 files changed

+38
-25
lines changed

src/components/forms/Fields/MarkdownTextAreaField.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ class MarkdownTextAreaField extends Component {
4040
<SourceCodeField {...this.props} mode="markdown" readOnly={disabled} />
4141
<Row>
4242
<Col sm={4}>
43-
<OnOffCheckbox
44-
name={`${name}.togglePreview`}
45-
checked={showPreview}
46-
onChange={() => this.toggleShowPreview()}>
43+
<OnOffCheckbox name={`${name}.togglePreview`} checked={showPreview} onChange={this.toggleShowPreview}>
4744
<FormattedMessage id="app.markdownTextArea.showPreview" defaultMessage="Preview" />
4845
</OnOffCheckbox>
4946
</Col>

src/components/forms/Fields/SourceCodeField.js

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,35 @@ import { loadAceEditor, getAceModeFromExtension } from '../../helpers/AceEditorL
1111
let AceEditor = loadAceEditor();
1212

1313
const SourceCodeField = (
14-
{ input, mode, meta: { error, warning }, label = null, children, tabIndex, onBlur, ...props },
14+
{ input, mode, meta: { error, warning }, label = null, children, tabIndex, onBlur, readOnly = false, ...props },
1515
{ userSettings: { vimMode = false, darkTheme = false } }
1616
) => (
1717
<FormGroup controlId={input.name} validationState={error ? 'error' : warning ? 'warning' : undefined}>
1818
{Boolean(label) && <ControlLabel>{label}</ControlLabel>}
1919
<ClientOnly>
20-
<AceEditor
21-
{...props}
22-
{...input}
23-
mode={getAceModeFromExtension(mode)}
24-
theme={darkTheme ? 'monokai' : 'github'}
25-
name={input.name}
26-
tabIndex={tabIndex}
27-
keyboardHandler={vimMode ? 'vim' : undefined}
28-
width="100%"
29-
height="100%"
30-
minLines={5}
31-
maxLines={20}
32-
onBlur={
33-
() => input.onBlur() // this is a hack that will ensure blur call witout distorting the contents
34-
}
35-
editorProps={{
36-
$blockScrolling: Infinity,
37-
$autoScrollEditorIntoView: true,
38-
}}
39-
/>
20+
<div className={readOnly ? 'noselection' : ''}>
21+
<AceEditor
22+
{...props}
23+
{...input}
24+
mode={getAceModeFromExtension(mode)}
25+
theme={darkTheme ? 'monokai' : 'github'}
26+
name={input.name}
27+
tabIndex={tabIndex}
28+
keyboardHandler={vimMode ? 'vim' : undefined}
29+
width="100%"
30+
height="100%"
31+
minLines={5}
32+
maxLines={20}
33+
readOnly={readOnly}
34+
onBlur={
35+
() => input.onBlur() // this is a hack that will ensure blur call witout distorting the contents
36+
}
37+
editorProps={{
38+
$blockScrolling: Infinity,
39+
$autoScrollEditorIntoView: true,
40+
}}
41+
/>
42+
</div>
4043
</ClientOnly>
4144
{error && <HelpBlock> {error} </HelpBlock>}
4245
{!error && warning && <HelpBlock> {warning} </HelpBlock>}
@@ -61,6 +64,7 @@ SourceCodeField.propTypes = {
6164
PropTypes.element,
6265
PropTypes.shape({ type: PropTypes.oneOf([FormattedMessage]) }),
6366
]),
67+
readOnly: PropTypes.bool,
6468
onBlur: PropTypes.func,
6569
};
6670

src/containers/App/recodex.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,15 @@ th.shrink-col {
184184
.wider-tooltip>.tooltip-inner {
185185
max-width: 300px;
186186
}
187+
188+
189+
/*
190+
* ACE Editor Overrides
191+
*/
192+
.noselection .ace_marker-layer .ace_selection {
193+
background: transparent !important;
194+
}
195+
196+
.noselection .ace_cursor {
197+
color: transparent !important;
198+
}

0 commit comments

Comments
 (0)