CodeMirror swallows onClick event #3145

Closed
opened 2015-03-21 00:25:37 +01:00 by marijnh · 3 comments
marijnh commented 2015-03-21 00:25:37 +01:00 (Migrated from gitlab.com)

CodeMirror's parenthesis match mechanism swallows the event on the first click when user clicks on a matching parenthesis.

For example, if I have a listener on the CodeMirror element:

    var editor = new CodeMirror(editorEl, config);
    goog.events.listen(editor.getElement(),
        goog.events.EventType.CLICK,
        function(e) { console.log('CLICKED'); });

Then if the editor displays code with parenthesis:

1 var xyz = function() {
2   // do something
3 };

If I click on line 1, codemirror will highlight the matched parenthesis on line 3, which is expected. However, it will also swallow the click event, and the listener wouldn't fire.

CodeMirror's parenthesis match mechanism swallows the event on the first click when user clicks on a matching parenthesis. For example, if I have a listener on the CodeMirror element: ``` javascript var editor = new CodeMirror(editorEl, config); goog.events.listen(editor.getElement(), goog.events.EventType.CLICK, function(e) { console.log('CLICKED'); }); ``` Then if the editor displays code with parenthesis: ``` 1 var xyz = function() { 2 // do something 3 }; ``` If I click on line 1, codemirror will highlight the matched parenthesis on line 3, which is expected. However, it will also swallow the click event, and the listener wouldn't fire.
marijnh commented 2015-03-23 12:07:21 +01:00 (Migrated from gitlab.com)

It has to. To prevent the default mouse behavior, CodeMirror must preventDefault mousedown events, which will prevent "click" from happening. Listen to mousedown or mouseup instead.

It has to. To prevent the default mouse behavior, CodeMirror must `preventDefault` `mousedown` events, which will prevent `"click"` from happening. Listen to `mousedown` or `mouseup` instead.
marijnh (Migrated from gitlab.com) closed this issue 2015-03-23 12:07:21 +01:00
marijnh commented 2015-03-23 19:02:35 +01:00 (Migrated from gitlab.com)

Thanks for the quick response! Can you provide a little more detail regarding why "it has to"? i.e. what behavior is it trying to prevent?

Thanks for the quick response! Can you provide a little more detail regarding why "it has to"? i.e. what behavior is it trying to prevent?
marijnh commented 2015-03-24 10:23:14 +01:00 (Migrated from gitlab.com)

We don't want clicking to steal focus from the hidden textarea, and we don't want dragging to create a DOM selection.

We don't want clicking to steal focus from the hidden textarea, and we don't want dragging to create a DOM selection.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/codemirror5#3145
No description provided.