Преглед изворни кода

fix(themes): implement renderer cache invalidation on theme change

Introduced EditorEvent::ThemeChanged to notify UI of theme updates. Added invalidate_cache() to GtkRenderer to clear stale surface caches. Updated EditorCore to emit the event when setting a theme. Updated Lua bindings to use the new event-emitting setter.
Bernardo Magri пре 1 месец
родитељ
комит
1a27977493

+ 1 - 0
include/lumacs/editor_core.hpp

@@ -101,6 +101,7 @@ public:
     // Theme Management
     ThemeManager& theme_manager() override { return theme_manager_; }
     const ThemeManager& theme_manager() const override { return theme_manager_; }
+    void set_theme(const std::string& theme_name); // Sets theme and emits event
 
     // Registers (Delegated to RegisterManager)
     void copy_to_register(char register_name, const std::string& text) override;

+ 5 - 1
include/lumacs/gtk_renderer.hpp

@@ -48,7 +48,11 @@ public:
     /// @param width Output parameter for the width.
     /// @param height Output parameter for the height.
     /// @return True if the coordinates could be determined, false otherwise.
-            bool get_minibuffer_coords(int& x, int& y, int& width, int& height) const;
+    bool get_minibuffer_coords(int& x, int& y, int& width, int& height) const;
+
+    /// @brief Clears the internal render cache, forcing a full redraw.
+    /// Useful when the theme changes.
+    void invalidate_cache();
         
         private:
             struct LineCacheEntry {

+ 2 - 1
include/lumacs/ui_interface.hpp

@@ -27,7 +27,8 @@ enum class EditorEvent {
     ISearchBackwardMode,  ///< Enter backward incremental search mode (C-r).
     
     TransientMessageCleared, ///< A transient message has been cleared.
-    Quit                  ///< The application should exit.
+    Quit,                 ///< The application should exit.
+    ThemeChanged          ///< The active theme has changed.
 };
 
 /// @brief Abstract interface for a Lumacs editor UI frontend.

+ 5 - 0
src/editor_core.cpp

@@ -730,6 +730,11 @@ void EditorCore::enter_theme_selection_mode() { emit_event(EditorEvent::ThemeSel
 void EditorCore::enter_isearch_mode() { emit_event(EditorEvent::ISearchMode); }
 void EditorCore::enter_isearch_backward_mode() { emit_event(EditorEvent::ISearchBackwardMode); }
 
+void EditorCore::set_theme(const std::string& theme_name) {
+    theme_manager_.set_active_theme(theme_name);
+    emit_event(EditorEvent::ThemeChanged);
+}
+
 // === Private ===
 
 void EditorCore::emit_event(EditorEvent event) {

+ 8 - 0
src/gtk_editor.cpp

@@ -146,6 +146,14 @@ void GtkEditor::handle_editor_event(EditorEvent event) {
                 }
             }, nullptr
         );
+    } else if (event == EditorEvent::ThemeChanged) {
+        if (gtk_renderer_) {
+            gtk_renderer_->invalidate_cache();
+        }
+        // Redraw everything with new theme
+        if (content_widget_) {
+            queue_redraw_all_windows(content_widget_);
+        }
     } else if (event == EditorEvent::ISearchMode) {
         core_->minibuffer_manager().activate_minibuffer(
             MinibufferMode::ISearch, "I-search: ",

+ 5 - 0
src/gtk_renderer.cpp

@@ -562,4 +562,9 @@ bool GtkRenderer::get_minibuffer_coords(int& x, int& y, int& width, int& height)
     return true;
 }
 
+void GtkRenderer::invalidate_cache() {
+    render_cache_.clear();
+    spdlog::debug("GtkRenderer: Cache invalidated due to theme change.");
+}
+
 } // namespace lumacs

+ 1 - 1
src/lua_api.cpp

@@ -755,7 +755,7 @@ void LuaApi::register_types() {
         // Theme management
         "theme_manager", sol::property([](EditorCore& e) -> ThemeManager& { return e.theme_manager(); }),
         "config", sol::property([](EditorCore& e) -> Config& { return e.config(); }), // Added config property
-        "set_theme", [](EditorCore& e, const std::string& theme_name) { e.theme_manager().set_active_theme(theme_name); }, // Corrected
+        "set_theme", [](EditorCore& e, const std::string& theme_name) { e.set_theme(theme_name); }, // Corrected
         "active_theme", sol::property([](EditorCore& e) -> const Theme& { return *e.theme_manager().active_theme(); }), // Corrected
         "message", &EditorCore::set_message, // Added message alias for set_message