1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:37:44 +00:00

LibGUI: Don't fire on_change hook at start of TextEditor::paint_event()

If something happens in response to on_change that causes the widget
to get unparented, creating a GUI::Painter will fail since it can't
find the window to paint into.

Since painting only cares about the syntax highlighting spans, what we
really want is to ensure that spans are up-to-date before we start
painting.

The problem was that rehighlighting and the on_change hook were bundled
together in an awkward lazy update mechanism. This patch fixes that by
decoupling rehighlighting and on_change. Rehighlighting is now lazy
and only happens when we handle either paint or mouse events. :^)

Fixes #8302.
This commit is contained in:
Andreas Kling 2021-06-29 11:22:57 +02:00
parent 114e8fffcd
commit bec2b3086c
2 changed files with 12 additions and 18 deletions

View file

@ -283,7 +283,7 @@ private:
Gfx::IntRect visible_text_rect_in_inner_coordinates() const;
void recompute_all_visual_lines();
void ensure_cursor_is_valid();
void flush_pending_change_notification_if_needed();
void rehighlight_if_needed();
size_t visual_line_containing(size_t line_index, size_t column) const;
void recompute_visual_lines(size_t line_index);
@ -311,6 +311,7 @@ private:
bool m_in_drag_select { false };
bool m_ruler_visible { false };
bool m_gutter_visible { false };
bool m_needs_rehighlight { false };
bool m_has_pending_change_notification { false };
bool m_automatic_indentation_enabled { false };
WrappingMode m_wrapping_mode { WrappingMode::NoWrap };