mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 03:58:12 +00:00
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.
This commit is contained in:
parent
f93c0dc489
commit
8cea5c053d
2 changed files with 10 additions and 1 deletions
|
@ -28,6 +28,12 @@ TextEditorWidget::TextEditorWidget()
|
||||||
m_editor->set_line_wrapping_enabled(true);
|
m_editor->set_line_wrapping_enabled(true);
|
||||||
|
|
||||||
m_editor->on_change = [this] {
|
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;
|
bool was_dirty = m_document_dirty;
|
||||||
m_document_dirty = true;
|
m_document_dirty = true;
|
||||||
if (!was_dirty)
|
if (!was_dirty)
|
||||||
|
@ -282,8 +288,10 @@ void TextEditorWidget::open_sesame(const String& path)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_document_dirty = false;
|
|
||||||
m_editor->set_text(file->read_all());
|
m_editor->set_text(file->read_all());
|
||||||
|
m_document_dirty = false;
|
||||||
|
m_document_opening = true;
|
||||||
|
|
||||||
set_path(FileSystemPath(path));
|
set_path(FileSystemPath(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,4 +47,5 @@ private:
|
||||||
RefPtr<GWidget> m_find_widget;
|
RefPtr<GWidget> m_find_widget;
|
||||||
|
|
||||||
bool m_document_dirty { false };
|
bool m_document_dirty { false };
|
||||||
|
bool m_document_opening { false };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue