From 648fac7215e1841e3714d4c72c7aee75152da522 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Tue, 22 Oct 2024 23:09:27 +0200 Subject: [PATCH] LibWeb: Fix "input" events being dispatched twice when cancelled --- Tests/LibWeb/Text/expected/Editing/beforeinput-event.txt | 4 ++++ Tests/LibWeb/Text/input/Editing/beforeinput-event.html | 2 +- Userland/Libraries/LibWeb/Page/EventHandler.cpp | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Tests/LibWeb/Text/expected/Editing/beforeinput-event.txt b/Tests/LibWeb/Text/expected/Editing/beforeinput-event.txt index e8842c4f473..4faaeea258a 100644 --- a/Tests/LibWeb/Text/expected/Editing/beforeinput-event.txt +++ b/Tests/LibWeb/Text/expected/Editing/beforeinput-event.txt @@ -1,5 +1,9 @@ beforeinput data=(r) intputType=(insertText) +beforeinput data=(a) intputType=(insertText) beforeinput data=(e) intputType=(insertText) +beforeinput data=(b) intputType=(insertText) beforeinput data=(e) intputType=(insertText) +beforeinput data=(c) intputType=(insertText) beforeinput data=(e) intputType=(insertText) +beforeinput data=(null) intputType=(insertParagraph) Text in input: reee diff --git a/Tests/LibWeb/Text/input/Editing/beforeinput-event.html b/Tests/LibWeb/Text/input/Editing/beforeinput-event.html index 57a39b9f0de..56dfa6ac185 100644 --- a/Tests/LibWeb/Text/input/Editing/beforeinput-event.html +++ b/Tests/LibWeb/Text/input/Editing/beforeinput-event.html @@ -11,11 +11,11 @@ test(() => { const input = document.getElementById("input"); input.addEventListener("beforeinput", (e) => { + println(`beforeinput data=(${e.data}) intputType=(${e.inputType})`); if (e.data !== 'r' && e.data !== 'e') { e.preventDefault(); return; } - println(`beforeinput data=(${e.data}) intputType=(${e.inputType})`); }); internals.sendText(input, "raebece"); internals.commitText(); diff --git a/Userland/Libraries/LibWeb/Page/EventHandler.cpp b/Userland/Libraries/LibWeb/Page/EventHandler.cpp index 59bbfcadf3d..4583464d73c 100644 --- a/Userland/Libraries/LibWeb/Page/EventHandler.cpp +++ b/Userland/Libraries/LibWeb/Page/EventHandler.cpp @@ -38,8 +38,8 @@ namespace Web { -#define FIRE(event_result) \ - if (event_result == EventResult::Cancelled) \ +#define FIRE(expression) \ + if (auto event_result = (expression); event_result == EventResult::Cancelled) \ return event_result; static JS::GCPtr dom_node_for_event_dispatch(Painting::Paintable& paintable)