Signal Keydown

Hello,

I’m using CodeMirror in an unusual environment (an Adobe After Effects HTML5 panel) and in the current version (CC2015) there is a bug where certain keys like Backspace and the arrows don’t fire keydown events, but do fire keyup events.

Due to this I can only delete the characters I just wrote, but not the just created new line. After blurring and focusing the editor I can’t delete anything unless I select it. In another version the editor works splendid and I can mimic the problem with “Backspace”: false in extraKeys. I can make the arrow keys work by defining their commands also in extraKeys, but this doesn’t work for Backspace.

How can I get CodeMirror to listen to the keyup instead of keydown for all the shortcuts?
Including emacs and Sublime.

I’ve tried signal() and read about trigger, but was uncertain on how to use it.

editor.on("keyup", function (cm, event) {
  var keycode = event.which;
  CodeMirror.signal(cm, "keydown", {which: keycode, keyCode: keycode});
  console.log("keyup");
});

The signal event doesn’t fire and if it did would this create an infinite loop?

Have you tried enabling inputStyle: "contenteditable"? That might work.

If all else failed, you could create a list of keycodes that have this problem, and when seeing them in a keyup event, call triggerOnKeyDown to simulate their effect. But that sounds dangerously fragile.

Thanks Marijn!

inputStyle: "contenteditable" didn’t seem to help, although it did signal() in that mode, but it came with more problems to solve.

triggerOnKeyDown() seems to do the job, although I only tested it with backspace for now. It’s currently no priority for me, so I will look deeper into it at a later time.

For the sake of reference, what I did:

editor.on("keyup", function (cm, event) {
  event = {
    type: "keydown",
    keyCode: event.keyCode,
    ctrlKey: event.ctrlKey,
    shiftKey: event.shiftKey,
    altKey: event.altKey,
    metaKey: event.metaKey
  };
			
  console.log(event);

  if (keycode == 8) {
    cm.triggerOnKeyDown(event);		
  }
});

A more elaborate approach that I came across: