I would like to call “coordsAtPos” to get the screen coordinates of a position (eg. the cursor), then later call “posAtCoords” to get the nearest position to those coordinates again. (eg/ to swap a document but keep a similar cursor position.)
However, I find that even without changing the document at all, ‘posAtCoords’ often doesn’t return anything close to ‘coordsAtPos’.
Above is a gif showing the behaviour. Just for demonstration purposes, I’ve set an onClick callback to get the $cursor.pos, call posAtCoords on it, resolve that position, and then create a new selection (I tried both TextSelection and Selection.near). The cursor jumps around a lot, whereas I would expect that we could round-trip these functions to get back the same position. Maybe I am missing something with how these functions are supposed to work?