KZcoding
KZcoding

Reputation: 1517

Ace editor: Why is the keyboard event handler being called twice?

Currently, I am capturing keyboard events whenever any key is pressed in my ace editor, via this javascript code:

editor.keyBinding.addKeyboardHandler({
    handleKeyboard: function(data, hash, keyString, keyCode, event) {
        console.log(ketString)
        ...
    }

The problem is that the handler function is being called twice every time a key is pressed in the ace editor, but I want it to be called once. Any ideas?

EDIT

Based on feedback from @Michael Geary, I added a console.trace() every time the keyboard handler is called, and I have traced the calls from two locations in the ace.js code:

this.onCommandKey = function(e, t, n) {
    var i = r.keyCodeToString(n);
    this.$callKeyboardHandlers(t, i, n, e)      <-----------
}
,
this.onTextInput = function(e) {
    this.$callKeyboardHandlers(-1, e)           <-----------
}

The question, why are onCommandKey and onTextInput both being triggered?

Upvotes: 0

Views: 1304

Answers (1)

a user
a user

Reputation: 24149

they are calling it with different hashid and often with different keystring. The first call is for the keypress event where hashid is the combination of modifier keys as seen in https://github.com/ajaxorg/ace/blob/55f206452dd2ebd4094edbae7a145bfb09da87bb/lib/ace/keyboard/hash_handler.js#L225. And the second is for textinput event with hashid=-1

Upvotes: 1

Related Questions