How do I disable line selection on gutter click in ACE editor?

1k views Asked by At

I'm trying to disable all user interaction with the ace editor. I managed to stop most interactions with the following settings:

codeEditor.setReadOnly(true);
codeEditor.setHighlightActiveLine(false);
codeEditor.setHighlightGutterLine(false);
codeEditor.container.style.pointerEvents = "none";
codeEditor.renderer.$cursorLayer.element.style.opacity = 0;

However, while most of the interactivity is now disabled, mousedown events on the gutter still work. For example, when you click on a gutter line, it still selects the text on that line. Other events such as double click for select all or code folding also seem to work. You can check it here: http://jsfiddle.net/squarePenguin/zhpms1mm/

I tried to remove listeners on the gutter, but nothing seems to work. This is everything I tried:

codeEditor.getSession().removeAllListeners("guttermousedown");
codeEditor.getSession().removeAllListeners("gutterclick");
codeEditor.getSession().removeAllListeners("gutterdblclick");
codeEditor.getSession().removeAllListeners("guttermousemove");
codeEditor.getSession().removeAllListeners("click");
codeEditor.getSession().removeAllListeners("mousedown");

Do you have any idea? Thank you for your patience!

1

There are 1 answers

0
a user On BEST ANSWER

You can do it with

stop = function(e) {e.stop()}
editor.on("guttermousedown", stop, true);
editor.on("gutterclick", stop, true);
editor.on("gutterdblclick", stop, true);
editor.on("guttermousemove", stop, true);
editor.on("click", stop, true);
editor.on("mousedown", stop, true);

codeEditor.getSession().removeAllListeners doesn't work because mouse events are dispatched on editor not session, and removeAllListeners doesn't remove defaultHandlers

codeEditor.container.style.pointerEvents = "none"; doesn't work because some elements in ace have pointerEvents="auto" style.