Merge pull request #694 from ollanta/handle-missing-keypress
Handle missing keypress event
diff --git a/src/services/saneKeyboardEvents.util.js b/src/services/saneKeyboardEvents.util.js
index e6bfb4f..f2b0b9c 100644
--- a/src/services/saneKeyboardEvents.util.js
+++ b/src/services/saneKeyboardEvents.util.js
@@ -177,6 +177,10 @@
checkTextareaFor(typedText);
}
+ function onKeyup(e) {
+ // Handle case of no keypress event being sent
+ if (!!keydown && !keypress) checkTextareaFor(typedText);
+ }
function typedText() {
// If there is a selection, the contents of the textarea couldn't
// possibly have just been typed in.
@@ -235,6 +239,7 @@
target.bind({
keydown: onKeydown,
keypress: onKeypress,
+ keyup: onKeyup,
focusout: onBlur,
cut: function() { checkTextareaOnce(function() { handlers.cut(); }); },
copy: function() { checkTextareaOnce(function() { handlers.copy(); }); },
diff --git a/test/unit/saneKeyboardEvents.test.js b/test/unit/saneKeyboardEvents.test.js
index 8f0acf1..467084a 100644
--- a/test/unit/saneKeyboardEvents.test.js
+++ b/test/unit/saneKeyboardEvents.test.js
@@ -31,6 +31,25 @@
el.val('a');
});
+ test('normal keys without keypress', function(done) {
+ var counter = 0;
+ saneKeyboardEvents(el, {
+ keystroke: noop,
+ typedText: function(text) {
+ counter += 1;
+ assert.ok(counter <= 1, 'callback is only called once');
+ assert.equal(text, 'a', 'text comes back as a');
+ assert.equal(el.val(), '', 'the textarea remains empty');
+
+ done();
+ }
+ });
+
+ el.trigger(Event('keydown', { which: 97 }));
+ el.trigger(Event('keyup', { which: 97 }));
+ el.val('a');
+ });
+
test('one keydown only', function(done) {
var counter = 0;