aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-09-10 13:57:45 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-09-10 13:57:45 -0700
commit574045bde8eeaa5068cb6476c4e18483af71390f (patch)
treeba0b75bfb93f89024c02d10ac70849cc787da085 /src
parent7715b4172944e360a3c1fa785cd9721463b1ce33 (diff)
fix preventDefault being called after event has been replaced
Diffstat (limited to 'src')
-rw-r--r--src/library_sdl.js15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/library_sdl.js b/src/library_sdl.js
index 7c0593b2..528560c3 100644
--- a/src/library_sdl.js
+++ b/src/library_sdl.js
@@ -442,6 +442,14 @@ var LibrarySDL = {
}
// fall through
case 'keydown': case 'keyup': case 'keypress': case 'mousedown': case 'mouseup': case 'DOMMouseScroll': case 'mousewheel':
+ // If we preventDefault on keydown events, the subsequent keypress events
+ // won't fire. However, it's fine (and in some cases necessary) to
+ // preventDefault for keys that don't generate a character. Otherwise,
+ // preventDefault is the right thing to do in general.
+ if (event.type !== 'keydown' || (event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */)) {
+ event.preventDefault();
+ }
+
if (event.type == 'DOMMouseScroll' || event.type == 'mousewheel') {
var button = (event.type == 'DOMMouseScroll' ? event.detail : -event.wheelDelta) > 0 ? 4 : 3;
var event2 = {
@@ -499,13 +507,6 @@ var LibrarySDL = {
SDL.savedKeydown = event;
}
- // If we preventDefault on keydown events, the subsequent keypress events
- // won't fire. However, it's fine (and in some cases necessary) to
- // preventDefault for keys that don't generate a character.
- if (event.type !== 'keydown' || (event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */)) {
- event.preventDefault();
- }
-
// Don't push keypress events unless SDL_StartTextInput has been called.
if (event.type !== 'keypress' || SDL.textInput) {
SDL.events.push(event);