I am using CodeMirror for YAML.
I am making my editor readOnly using ‘readOnly: true ’ option.
But visually, the editor does not look to be readOnly.
Is there also a way to blur the editor while in readOnly mode so that it appears to be readOnly and user need not click inside the editor to understand that it is not editable?
marijn
December 7, 2018, 10:24am
2
You’ll have to do that with your own styling.
I have something like that already:
1 Like
This did not work for me.
Ah, it’s probably because I forgot to give you the other half of the code I wrote:
/**
* Mark CodeMirror lines "read-only", and get a function that can alter them.
*
* @param editor {CodeMirror} The editor.
* @param startLine {Integer} The line index to start at.
* @param endLine {Integer} The line index to end at.
*
* @returns {Function(String)} A callback for replacing read-only content.
*
* @note CodeMirror uses zero-based indexes for the API, and one-based indexes
* for the rendering: the first line appears in gutters as line 1, but in the
* API, it is line 0.
*/
getTextLock: function(editor, startLine, endLine)
{
const doc = editor.getDoc();
const options = { readOnly: true, className: "readOnly" };
if (startLine === 0)
options.inclusiveLeft = true;
if (endLine === Infinity)
This file has been truncated. show original
In particular, I set a readOnly class in the options.
1 Like