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

@@ -72,10 +72,10 @@ void HTMLTextAreaElement::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();
document().get_selection()->remove_all_ranges();
}
@@ -83,10 +83,10 @@ void HTMLTextAreaElement::did_receive_focus()
void HTMLTextAreaElement::did_lose_focus()
{
if (m_text_node)
m_text_node->invalidate_style(DOM::StyleInvalidationReason::DidLoseFocus);
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();
// The change event fires when the value is committed, if that makes sense for the control,
// or else when the control loses focus