Cursor height and decorations

I am using mark decorations that set different font-size on the same line.

Now the way Codemirror renders the cursor is based on the direction of navigation.

To simplify it, let’s say I have only two ranges <range 1><range 2>.

If I navigate from left to right (or by default), the cursor between the ranges will have the height of range 1.

If I navigate from right to left, the cursor between the ranges will have the height of range 2.

That’s reasonable. But I would like the cursor to instead take into account the inclusiveness of the decorations.

So say range 2 has a inclusive: false mark Decoration. If I navigate from right to left, I want the cursor to have the height of range 1, not of range 2, when it’s between the ranges.

Now I am already using a custom implementation of cursors, so I could customize measureCursor function to take into account the decorations present at the pos - but I how do I get the decorations at given position?

I am looking for something like view.directlyProvidedDecorationsAtPos(pos: number). Does this exist somewhere that I’m missing it? Or how could I implement it? Or is there a simpler solution to my problem?

Thanks as always!

What you are seeing is the effect of the assoc field in cursors, which tracks whether the cursor is associated with the character before or after it. This is necessary for bidirectional code, where we’d otherwise draw the cursor in the wrong place when it is on a direction boundary (where the same numerical position corresponds to two different visual positions on the screen). The selection drawing logic takes both the position and the text size from the associated character.

To get the active decorations, you could access the EditorView.decorations facet from your code, but going from decoration objects to actual styling information might be non-trivial.

1 Like