Error when adding line widget on renderLine event

Hello,

I am trying to insert line widget on renderLine event. If line meets a certain criteria, the line widget is inserted. Like:

cm.on("renderLine", function(cm, line, el) {

  // check line 
  // ...

  var el = document.createElement("div");
  el.innerHTML = "test";
  	if (!cm.lineInfo(line).widgets) { // check that no widget is already there to prevent loop
  	cm.addLineWidget(line, el);
  }	
});

It actually works as intended and it seems the most elegant solution for my needs, but there is an error notice thrown every time:

Uncaught NotFoundError: Failed to execute ‘insertBefore’ on ‘Node’: The node before which the new node is to be inserted is not a child of this node. (codemirror.js:873)

or/and

Uncaught TypeError: Cannot set property ‘forceUpdate’ of null (codemirror.js:2617)

Is it connected to:

“renderLine” (instance: CodeMirror, line: LineHandle, element: Element) Fired whenever a line is (re-)rendered to the DOM. Fired right after the DOM element is built, before it is added to the document. The handler may mess with the style of the resulting element, or add event handlers, but should not try to change the state of the editor.

Thanks!

iztok

The docs explicitly forbid messing with editor style from this handler.

I know and I just hoped adding widgets is allowed. I’ll go with some other approach. Thanks,
iztok