Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GLFW] Fix the bug that prevents any text on the site from being deleted #22879

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/library_glfw.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ var LibraryGLFW = {
// This logic comes directly from the sdl implementation. We cannot
// call preventDefault on all keydown events otherwise onKeyPress will
// not get called
if (event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */) {
// Prevent default backspace and tab behavior when the target
// is not an input or textarea. Otherwise, no text in the site can be deleted.
if (event.target.tagName !== "INPUT" && event.target.tagName !== "TEXTAREA" &&
(event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */)) {
event.preventDefault();
}
},
Expand Down
9 changes: 7 additions & 2 deletions src/library_sdl.js
Original file line number Diff line number Diff line change
Expand Up @@ -696,8 +696,13 @@ var LibrarySDL = {
// 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' || (!SDL.unicode && !SDL.textInput) || (event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */)) {
event.preventDefault();
// Prevent default backspace and tab behavior when the target
// is not an input or textarea. Otherwise, no text in the site can be deleted.
if (event.type !== 'keydown' ||
(!SDL.unicode && !SDL.textInput) ||
((event.keyCode === 8 /* backspace */ || event.keyCode === 9 /* tab */ ) &&
event.target.tagName !== "INPUT" && event.target.tagName !== "TEXTAREA")) {
event.preventDefault();
}

if (event.type == 'mousedown') {
Expand Down