LibWeb: Invalidate paint cache for input/textarea on focus change

The invalidate_style() calls on text nodes in did_receive_focus() and
did_lose_focus() were no-ops since Node::invalidate_style() returns
early for character data nodes. Replace them with set_needs_repaint()
which properly invalidates the containing PaintableWithLines' paint
cache, ensuring selection highlights are cleared and the caret is
repainted when switching focus between text controls.

Fixes #8363
This commit is contained in:
Jelle Raaijmakers
2026-03-11 13:43:59 +01:00
committed by Tim Ledbetter
parent 76c65eca57
commit 2e42421553
Notes: github-actions[bot] 2026-03-11 16:45:30 +00:00
5 changed files with 46 additions and 12 deletions

View File

@@ -1472,10 +1472,10 @@ void HTMLInputElement::did_receive_focus()
{
if (!m_text_node)
return;
m_text_node->invalidate_style(DOM::StyleInvalidationReason::DidReceiveFocus);
m_text_node->set_needs_repaint();
if (m_placeholder_text_node)
m_placeholder_text_node->invalidate_style(DOM::StyleInvalidationReason::DidReceiveFocus);
m_placeholder_text_node->set_needs_repaint();
if (has_selectable_text()) {
if (document().last_focus_trigger() == FocusTrigger::Key)
@@ -1487,12 +1487,11 @@ void HTMLInputElement::did_receive_focus()
void HTMLInputElement::did_lose_focus()
{
if (m_text_node) {
m_text_node->invalidate_style(DOM::StyleInvalidationReason::DidLoseFocus);
}
if (m_text_node)
m_text_node->set_needs_repaint();
if (m_placeholder_text_node)
m_placeholder_text_node->invalidate_style(DOM::StyleInvalidationReason::DidLoseFocus);
m_placeholder_text_node->set_needs_repaint();
commit_pending_changes();
}