@@ -17,7 +17,7 @@ export default class CodeEditor extends React.Component {
1717 initSingleFileSnippetEditor ( ) {
1818 const { config, snippet } = this . props
1919 if ( snippet ) {
20- const { theme, showLineNumber } = config . editor
20+ const { theme, showLineNumber, highlightCurrentLine } = config . editor
2121 const snippetMode = CodeMirror . findModeByName ( snippet . lang ) . mode
2222 require ( `codemirror/mode/${ snippetMode } /${ snippetMode } ` )
2323 const gutters = showLineNumber
@@ -32,9 +32,13 @@ export default class CodeEditor extends React.Component {
3232 gutters : gutters ,
3333 readOnly : true ,
3434 autoCloseBrackets : true ,
35- autoRefresh : true ,
36- styleActiveLine : { nonEmpty : false }
35+ autoRefresh : true
3736 } )
37+ if ( highlightCurrentLine ) {
38+ this . editor . setOption ( 'styleActiveLine' , { nonEmpty : false } )
39+ } else {
40+ this . editor . setOption ( 'styleActiveLine' , null )
41+ }
3842 this . editor . setSize ( '100%' , 'auto' )
3943 this . applyEditorStyleSingleFile ( )
4044 }
@@ -47,7 +51,13 @@ export default class CodeEditor extends React.Component {
4751 handleEditingFileValueChange,
4852 selectedFile
4953 } = this . props
50- const { theme, showLineNumber, tabSize, indentUsingTab } = config . editor
54+ const {
55+ theme,
56+ showLineNumber,
57+ tabSize,
58+ indentUsingTab,
59+ highlightCurrentLine
60+ } = config . editor
5161 const file = snippet . files [ selectedFile ]
5262 const fileExtension = getExtension ( file . name )
5363 const resultMode = CodeMirror . findModeByExtension ( fileExtension )
@@ -70,10 +80,14 @@ export default class CodeEditor extends React.Component {
7080 gutters : gutters ,
7181 readOnly : true ,
7282 autoCloseBrackets : true ,
73- autoRefresh : true ,
74- styleActiveLine : { nonEmpty : false }
83+ autoRefresh : true
7584 } )
7685
86+ if ( highlightCurrentLine ) {
87+ this . editor . setOption ( 'styleActiveLine' , { nonEmpty : false } )
88+ } else {
89+ this . editor . setOption ( 'styleActiveLine' , null )
90+ }
7791 this . editor . setOption ( 'indentUnit' , tabSize )
7892 this . editor . setOption ( 'tabSize' , tabSize )
7993 this . editor . setOption ( 'indentWithTabs' , indentUsingTab )
@@ -132,7 +146,8 @@ export default class CodeEditor extends React.Component {
132146 fontFamily,
133147 fontSize,
134148 tabSize,
135- indentUsingTab
149+ indentUsingTab,
150+ highlightCurrentLine
136151 } = config . editor
137152 // only update codemirror mode if new props is passed
138153 if ( props ) {
@@ -152,6 +167,12 @@ export default class CodeEditor extends React.Component {
152167 this . editor . setOption ( 'tabSize' , tabSize )
153168 this . editor . setOption ( 'indentWithTabs' , indentUsingTab )
154169
170+ if ( highlightCurrentLine ) {
171+ this . editor . setOption ( 'styleActiveLine' , { nonEmpty : false } )
172+ } else {
173+ this . editor . setOption ( 'styleActiveLine' , null )
174+ }
175+
155176 const wrapperElement = this . editor . getWrapperElement ( )
156177 wrapperElement . style . fontFamily = fontFamily
157178 if ( this . props . maxHeight ) {
@@ -172,7 +193,8 @@ export default class CodeEditor extends React.Component {
172193 fontFamily,
173194 fontSize,
174195 tabSize,
175- indentUsingTab
196+ indentUsingTab,
197+ highlightCurrentLine
176198 } = config . editor
177199 const gutters = showLineNumber
178200 ? [ 'CodeMirror-linenumbers' , 'CodeMirror-foldgutter' ]
@@ -189,6 +211,12 @@ export default class CodeEditor extends React.Component {
189211 }
190212 }
191213
214+ if ( highlightCurrentLine ) {
215+ this . editor . setOption ( 'styleActiveLine' , { nonEmpty : false } )
216+ } else {
217+ this . editor . setOption ( 'styleActiveLine' , null )
218+ }
219+
192220 this . editor . getWrapperElement ( ) . style . fontSize = `${ fontSize } px`
193221 this . editor . setOption ( 'lineNumbers' , showLineNumber )
194222 this . editor . setOption ( 'foldGutter' , showLineNumber )
0 commit comments