Hi,marijn。
When registering the mousedown event, the obtained cursor position is incorrect
EditorView.domEventHandlers({
mousedown(evt, view) {
console.log('head', view.state.selection.main.head);
},
}),

Reproduce the demo:
Your code runs before codemirror parses the event.
You can confirm by putting evt.preventDefault()
in your handler, which will make codemirror not respond to the clicks at all.
If you want to do something when the selection changes, you can use
EditorView.updateListener.of((update) => {
if (update.state.selection.main.head !== update.startState.selection.main.head) {
console.log('Selection changed:', update.state.selection.main.head)
}
})
To make it more specific and check for the selection changing because of a mouse click, you can use Transaction.isUserEvent with "select.pointer"
.
Exactly what I was looking for, thank you , codemirror is a great project