coordChar always returning end of line

Hi,

I have an editor with one line of text. I’m trying to get the token under the cursor so that I can check if it has an a specific css class applied and if so kick off another action. I’m monitoring mouse movements on the DIV that wraps the editor and am then passing the pageX and pageY values like so:

editor.coordsChar({left: e.pageX, top: e.pageY})

These left and top values are unchanged by the call to “fromCoordSystem” so that when we drop into the call to “lineAtHeight” the numbers are way too big as it seems this method assumes the coords are relative to the top of the editor.

However, even if I adjust the pageX and pageY values to account for the position of the editor on the page, the lineAtHeight method seems to be working on the basis that each line is only 5px high which is kinda low and means that most cursor positions over a given word come out with Y values greater than this. This results in the line number being calculated as 1 which is greater than the last line position of 0 so the editor simply returns a location of the last character of the line.

I then tried adjusting the X and Y values even further but even if I end up passing the values 3 and 2 for example as X and Y co-ordinates I get line number zero but it still gives me character 25 (the end of the line).

Have I configured something incorrectly or am I using the wrong method here ?

Thanks,

David

Could it be that the editor was initialized before some font or css file loaded and is using the wrong layout metrics? Does calling refresh() on it help with this? If not, can you try to reduce your situation to the minimum code required to trigger the problem?