diff --git a/Userland/Libraries/LibGUI/TextDocument.cpp b/Userland/Libraries/LibGUI/TextDocument.cpp index 075265f2be..6e0d7728c4 100644 --- a/Userland/Libraries/LibGUI/TextDocument.cpp +++ b/Userland/Libraries/LibGUI/TextDocument.cpp @@ -26,6 +26,7 @@ TextDocument::TextDocument(Client* client) if (client) m_clients.set(client); append_line(make(*this)); + set_modified(false); // TODO: Instead of a repating timer, this we should call a delayed 2 sec timer when the user types. m_undo_timer = Core::Timer::construct( @@ -91,6 +92,9 @@ bool TextDocument::set_text(const StringView& text) client->document_did_set_text(); clear_text_guard.disarm(); + + // FIXME: Should the modified state be cleared on some of the earlier returns as well? + set_modified(false); return true; } @@ -305,6 +309,8 @@ void TextDocument::update_views(Badge) void TextDocument::notify_did_change() { + set_modified(true); + if (m_client_notifications_enabled) { for (auto* client : m_clients) client->document_did_change(); @@ -878,4 +884,9 @@ const TextDocumentSpan* TextDocument::span_at(const TextPosition& position) cons return nullptr; } +void TextDocument::set_modified(bool modified) +{ + m_modified = modified; +} + } diff --git a/Userland/Libraries/LibGUI/TextDocument.h b/Userland/Libraries/LibGUI/TextDocument.h index bd711685d7..d73f505799 100644 --- a/Userland/Libraries/LibGUI/TextDocument.h +++ b/Userland/Libraries/LibGUI/TextDocument.h @@ -122,6 +122,8 @@ public: virtual bool is_code_document() const { return false; } bool is_empty() const; + bool is_modified() const { return m_modified; } + void set_modified(bool); protected: explicit TextDocument(Client* client); @@ -134,6 +136,7 @@ private: HashTable m_clients; bool m_client_notifications_enabled { true }; + bool m_modified { false }; UndoStack m_undo_stack; RefPtr m_undo_timer;