From 82b88c6e16b00db1b31da00e29964b75c539bbf2 Mon Sep 17 00:00:00 2001 From: Lennon Donaghy Date: Tue, 3 Aug 2021 20:40:42 +0100 Subject: [PATCH] HackStudio: Fix editor not marking file with unsaved changes as dirty The editor's on_change callback was being overwritten in HackStudioWidget.cpp in order to call update_gml_preview on every change. This stopped the original callback from being called and marking files as dirty when changed. Now we call update_gml_preview in a new callback within the editor wrapper, which is then called within the original on_change callback in the editor. --- Userland/DevTools/HackStudio/EditorWrapper.cpp | 2 ++ Userland/DevTools/HackStudio/EditorWrapper.h | 2 ++ Userland/DevTools/HackStudio/HackStudioWidget.cpp | 4 ++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Userland/DevTools/HackStudio/EditorWrapper.cpp b/Userland/DevTools/HackStudio/EditorWrapper.cpp index 73f7588998..2fb43b84a3 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.cpp +++ b/Userland/DevTools/HackStudio/EditorWrapper.cpp @@ -43,6 +43,8 @@ EditorWrapper::EditorWrapper() }; m_editor->on_change = [this] { + if (this->on_change) + this->on_change(); bool was_dirty = m_document_dirty; m_document_dirty = true; if (!was_dirty) diff --git a/Userland/DevTools/HackStudio/EditorWrapper.h b/Userland/DevTools/HackStudio/EditorWrapper.h index 67ed2c62ae..d4c422ac51 100644 --- a/Userland/DevTools/HackStudio/EditorWrapper.h +++ b/Userland/DevTools/HackStudio/EditorWrapper.h @@ -52,6 +52,8 @@ public: void update_diff(); Vector const& hunks() const { return m_hunks; } + Function on_change; + private: EditorWrapper(); diff --git a/Userland/DevTools/HackStudio/HackStudioWidget.cpp b/Userland/DevTools/HackStudio/HackStudioWidget.cpp index 9ef2f5dc7a..f267dfc399 100644 --- a/Userland/DevTools/HackStudio/HackStudioWidget.cpp +++ b/Userland/DevTools/HackStudio/HackStudioWidget.cpp @@ -295,7 +295,7 @@ bool HackStudioWidget::open_file(const String& full_filename) current_editor().set_focus(true); current_editor().on_cursor_change = [this] { update_statusbar(); }; - current_editor().on_change = [this] { update_gml_preview(); }; + current_editor_wrapper().on_change = [this] { update_gml_preview(); }; update_gml_preview(); return true; @@ -541,7 +541,7 @@ void HackStudioWidget::add_new_editor(GUI::Widget& parent) wrapper->editor().set_focus(true); wrapper->set_project_root(LexicalPath(m_project->root_path())); wrapper->editor().on_cursor_change = [this] { update_statusbar(); }; - wrapper->editor().on_change = [this] { update_gml_preview(); }; + wrapper->on_change = [this] { update_gml_preview(); }; set_edit_mode(EditMode::Text); }