Issue #2019 - Do not dispatch keypress event for non-printable keys.

This will prevent the keypress DOM event from firing on keypresses
that do not produce printable keys (e.g. editing nav keys) in content.
This should not affect any chrome events that are in use.
Event dispatch can be re-enabled if necessary with the added pref.
This commit is contained in:
Moonchild 2022-10-17 12:07:37 +00:00 committed by roytam1
commit 1392f5f223
6 changed files with 48 additions and 15 deletions

View file

@ -397,20 +397,14 @@ TextEditor::HandleKeyPressEvent(nsIDOMKeyEvent* aKeyEvent)
return TypedText(NS_LITERAL_STRING("\t"), eTypedText);
}
case NS_VK_RETURN:
if (IsSingleLineEditor() || nativeKeyEvent->IsControl() ||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
nativeKeyEvent->IsOS()) {
if (IsSingleLineEditor() || !nativeKeyEvent->IsInputtingLineBreak()) {
return NS_OK;
}
aKeyEvent->AsEvent()->PreventDefault();
return TypedText(EmptyString(), eTypedBreak);
}
// NOTE: On some keyboard layout, some characters are inputted with Control
// key or Alt key, but at that time, widget sets FALSE to these keys.
if (!nativeKeyEvent->mCharCode || nativeKeyEvent->IsControl() ||
nativeKeyEvent->IsAlt() || nativeKeyEvent->IsMeta() ||
nativeKeyEvent->IsOS()) {
if (!nativeKeyEvent->IsInputtingText()) {
// we don't PreventDefault() here or keybindings like control-x won't work
return NS_OK;
}