editor.setOption("configureMouse"...) before left mouse button is pressed


doc says that

" The function for setOption(“configureMouse”, …) is called when the left mouse button is pressed."

…but I have to set this option on the fly, before the left mouse button is pressed. Is there a way to do it?


Yes, that’s how it’s supposed to be used, you set the option to some function value implementing the behavior you want (at any time), and then when the mouse is pressed your function is called and can determine how the mouse action should be handled.

Thanks for your answer (and for your great editor).
There’s something which I don’t understand.

If for example I have this text:

%%%% START TABLE %%%
%%%% START TABLE %%%

And I want to switch to “block selection mode” as soon as I select something inside the table,
there is apparently no way to do it with setOption(“configureMouse”, …)

The only way I know to do this is to check if the cursor is inside the table before selecting, which adds an unwanted extra-operation (I must place the cursor before and only then I can select text).

Is there a way to avoid this and obtain the position (line, ch) or the selection start, so that I can use it inside the “configureMouse” function() soon after the mouse is pressed?

thanks again!

Do I understand correctly that you want to implement a new selection mode (similar to by-word, by-line, etc) but whether that takes effect depends on where the initial click happens? Or can it also change during a mouse selection?

The editor knows where in the document the click happens at the time where it calls configureMouse, but it’s not currently passing that to the the configuration function. If it’d help you, I guess we could change that.


I solved with:
editor.on(“mousedown”, … ) + editor.coordsChar(…)
They trigger the pressed line before the configureMouse function is called.


Note that lineAtHeight() doesn’t seem to work (issue/bug or do I miss something?) so I had to use
coordsChar() instead