Skip to content

Commit e7e8a0c

Browse files
committed
[SDL] Fix the bug that prevents any text on the site from being deleted
1 parent 40144d3 commit e7e8a0c

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/library_glfw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ var LibraryGLFW = {
422422
// Prevent default backspace and tab behavior when the target
423423
// is not an input or textarea. Otherwise, no text in the site can be deleted.
424424
if (event.target.tagName !== "INPUT" && event.target.tagName !== "TEXTAREA" &&
425-
(event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */)) {
425+
(event.key == 'Backspace' || event.key == 'Tab')) {
426426
event.preventDefault();
427427
}
428428
},

src/library_sdl.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,13 @@ var LibrarySDL = {
689689
// won't fire. However, it's fine (and in some cases necessary) to
690690
// preventDefault for keys that don't generate a character. Otherwise,
691691
// preventDefault is the right thing to do in general.
692-
if (event.type !== 'keydown' || (!SDL.unicode && !SDL.textInput) || (event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */)) {
693-
event.preventDefault();
692+
// Prevent default backspace and tab behavior when the target
693+
// is not an input or textarea. Otherwise, no text in the site can be deleted.
694+
if (event.type !== 'keydown' ||
695+
(!SDL.unicode && !SDL.textInput) ||
696+
((event.key == 'Backspace' || event.key == 'Tab') &&
697+
event.target.tagName !== "INPUT" && event.target.tagName !== "TEXTAREA")) {
698+
event.preventDefault();
694699
}
695700

696701
if (event.type == 'mousedown') {

0 commit comments

Comments
 (0)