summaryrefslogtreecommitdiff
path: root/Applications/TextEditor/TextEditorWidget.cpp
diff options
context:
space:
mode:
authorSasan Hezarkhani <gootik_2003@hotmail.com>2019-12-04 22:57:54 -0800
committerAndreas Kling <awesomekling@gmail.com>2019-12-06 19:45:13 +0100
commit8cea5c053d6faa6f0a219246d2428b40be5488d9 (patch)
tree08714c29fb8ca0fae693aa063913d750c6c834f0 /Applications/TextEditor/TextEditorWidget.cpp
parentf93c0dc4894546ec71fe9677f7eaab153708ba0c (diff)
downloadserenity-8cea5c053d6faa6f0a219246d2428b40be5488d9.zip
TextEditor: `Fix bug when document is marked dirty on open.
Currently, when `set_text()` is called on GTextDocument a change is triggered and all clients registered get a document_did_set_text call. This in turn causes the TextEditorWidget to mark the document as dirty even on the first open, which makes for a weird experience.
Diffstat (limited to 'Applications/TextEditor/TextEditorWidget.cpp')
-rw-r--r--Applications/TextEditor/TextEditorWidget.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp
index 27f1fc6595..cc12a350f6 100644
--- a/Applications/TextEditor/TextEditorWidget.cpp
+++ b/Applications/TextEditor/TextEditorWidget.cpp
@@ -28,6 +28,12 @@ TextEditorWidget::TextEditorWidget()
m_editor->set_line_wrapping_enabled(true);
m_editor->on_change = [this] {
+ // Do not mark as diry on the first change (When document is first opened.)
+ if (m_document_opening) {
+ m_document_opening = false;
+ return;
+ }
+
bool was_dirty = m_document_dirty;
m_document_dirty = true;
if (!was_dirty)
@@ -282,8 +288,10 @@ void TextEditorWidget::open_sesame(const String& path)
return;
}
- m_document_dirty = false;
m_editor->set_text(file->read_all());
+ m_document_dirty = false;
+ m_document_opening = true;
+
set_path(FileSystemPath(path));
}