ctrl + click to jump

I would like to implement a feature :when the mouse is hovered over a variable name and ctrl is pressed, then the mouse will become clickable and when clicked, it can jump to the appropriate line of code.

I’ve already implemented variable recognition, so here’s what I need now:

  1. when ctrl is pressed, how to make the mouse clickable
  2. jump (this could probably be done with gotoLine?)

is there an example of a similar feature?

thanks

CodeMirror doesn’t know enough about your code to tell you where a given identifier is defined. If you do have that information, for example by integrating a language server, cursor jumping shouldn’t be hard to implement.

view.dispatch({
  selection: {anchor: targetPosition},
  scrollIntoView: true
})

Thanks for the reply.
I know I can trigger a transaction by binding to a key-map (via view.dispatch as you said), but I don’t know how to make the mouse cursor clickable in a transaction, can you help me with this? Thank you very much!

Use EditorView.domEventHandlers to bind an event handler, then posAtCoords to find the position at those coordinates, and, probably, syntaxTree and resolveInner to figure out what the user clicked on.