cursorCoords with variable font sizes and line heights


#1

I’ve got a CodeMirror instance displaying Markdown, and the following CSS to modify the display of header lines, similar to SimpleMDE:

    .cm-header {
      line-height: 120%;
    }

    .cm-header-1 {
      font-size: 225%;
    }
   /* etc. */

Where the problems come in is with cursorCoords, which I’m using at various points to draw lines to sections of the text that have been marked with markText. Basically, if I add a # character to the beginning of a line (making it into a header), the CSS gets applied, but the cursorCoords for the rest of the document still report marker positions from their old locations, even though they’ve been moved down by the line above them increasing in size.

They get set appropriately once a linebreak has been introduced after the header line. (If I add a linebreak from the end of the header, the problem persists, but anywhere else and it works.)

Am I correct in thinking that the line dimensions are getting cached somewhere and not getting updated until the clean newline? Is there a way to force the measurement to happen?

(My first thought was that I was calling cursorCoords before the CSS had a chance to get applied, but putting it on a timeout had no effect. :confused:)


#2

Intra-line coordinates are cached, but cursorCoords always goes through the line height data in the document tree to get the line’s base height, which should be updated as soon as a line is redrawn. If I try to reproduce this in http://codemirror.net/demo/variableheight.html, I can’t—the coordinates at the start of the 3rd line change immediately when I remove the # on the first line.

Are you sure you’re testing this right? Can you set up a small demo that shows the issue?


#3

Thanks for investigating @marijn, and for the insight into how the internal caching is working. Good to know that’s not the problem, so it’s likely something in my code. I’ll see if I can set up an isolated demo that reproduces, but in the process of separating it from the rest of my code I’m guessing I’ll also find the problem spot. :smile: