Find pos {line, ch} from overlayMode token method & add widget/btn/node at same pos

What’s the best way to ascertain which line of the document is being processed by the token method for an overlayMode?

The best I’ve achieved so far has been to use startState to create an object with a lines prop to track the line count. Then, using the token method in-conjunction with a blankLines method I increment the line count each time I hit the end of the line in the stream.

Additionally, I want to add / remove widgets once the whole doc/stream has finished being parsed or during the parse. These widgets are buttons which open a popup - much like you’d have when spell checking in a word processor for example, or refactoring in an IDE.

I’m finding that my widgets added via cm.addWidget(pos, node, false); are being positioned at left:0px even if is say 20. The vertical / top position is correct. I tested the pos value using cm.doc.setCursor(pos) and the cursor is positioned correctly.

Should the widget be positioned at the char rather the start of the line? Is there another mechanism for hanging nodes at a given position?

Modes can not and should not concern themselves with line numbers. They are intentionally defined to act on a stream, so that their output can be shifted down or up when content is added/deleted above a given piece of highlighted text.

I can’t reproduce your issue with addWidget. Please provide a demo on or so.