Line widgets disappear on `setValue` calls

Hi There,

I’m trying to understand line widget lifecycle to be able to manage them. In particular, I’d like to control when line widgets get created and removed.

Right now I’m using the controlled component from react-codemirror2 (effectively for the purposes of this question - when there is a value change, it calls editor.setValue). This, however, removes any line widgets that I’ve added. So I’d have the following questions about line widget lifecycle:

  • which events remove them? (listening to all update events feels wrong)
  • is there a way to prevent their removal through certain updates?
  • when they are removed by CodeMirror, is there a special event that is called? (I’m aware I can force removal through clear())

Line widgets are associated with the line object. When an update replaces/removes line breaks, the line objects after those breaks are also dropped.

is there a way to prevent their removal through certain updates?

For setValue, I’m not even sure how that would work. When you remove the current document and replace it with a new one, the lines that widgets are associated with are gone, so there’s no obvious place to ‘keep’ them.

1 Like

Thank you - got it, that makes sense! If they appear/disappear with line breaks then that actually works well with my use case (compiler errors/warnings) and agree that it won’t be needed to “keep it alive” if the line is gone.