Edit: Tim Down is right, I seem to have overlooked the character code in light of the key code. The >
character has a charCode
of 62
, which is also what's sent in the jQuery event object's which
, keyCode
, and charCode
properties. I've made appropriate changes below:
Try the following HTML:
<a href='#' data-role='button' id='a1' class='html-inp' data-char='62'></a>
And the following jQuery:
$('.html-inp').click(function() {
var e = jQuery.Event('keypress'),
char = $(this).data('char');
e.shiftKey = true;
e.which = char;
e.charCode = char;
e.keyCode = char;
editor.replaceSelection(String.fromCharCode(char), focus);
editor.trigger(e);
});
This should have the effect of inserting the bracket into the editor, and also triggering the keypress
event on the editor so that the rest of your code can act accordingly.