Hello all, I am working on a package that will use the CodeMirror file editor in my package. For part of the package it will highlight errors in the file, by marking the lines in red.
The JS Api for CodeMirror allows this to be done, I am just having a problem getting the existing code editor as a Javascript Object, allowing me to run the functions & methods available on the CodeMirror object.
Here is my attempt, but without luck:
<scripttype="text/javascript">function highlightLine(lineNumber) {
//This seems to re-inititalizevar editor = CodeMirror.fromTextArea(document.getElementById("body_CodeTextBox"),{
lineNumbers: true,
matchBrackets: true
});
//Log the editor object
console.log(editor);
//Then highlight the linevar line = editor.getLineHandle(lineNumber);
console.log(line);
//Set line css class
editor.addLineClass(line, 'background', 'line-error');
}
</script>
Sorted the problem myself, For anyone else interested here is the solution:
<scripttype="text/javascript">function highlightLine(lineNumber) {
//Line number is zero based indexvar actualLineNumber = lineNumber - 1;
//Select editor loaded in the DOMvar myEditor = $("#body_EditorSource .CodeMirror");
console.log(myEditor);
console.log(myEditor[0].CodeMirror);
var codeMirrorEditor = myEditor[0].CodeMirror;
//Set line css class
codeMirrorEditor.setLineClass(actualLineNumber, 'background', 'line-error');
}
</script>
CodeMirror - Trying to highlight a line
Hello all,
I am working on a package that will use the CodeMirror file editor in my package.
For part of the package it will highlight errors in the file, by marking the lines in red.
The JS Api for CodeMirror allows this to be done, I am just having a problem getting the existing code editor as a Javascript Object, allowing me to run the functions & methods available on the CodeMirror object.
Here is my attempt, but without luck:
Any ideas please?
Thanks,
Warren
Sorted the problem myself,
For anyone else interested here is the solution:
This doesn't work in in new version of codemirror
is working on a reply...