LibGUI: Set TextEditor to unmodified after saving size=0 files

This fixes #7946

Previously, TextEditor::write_to_file() would not mark its document
as unmodified if the file size was 0. This caused a desync in the
Text Editor app between the window's is_modified state and the
TextEditor's. It's already noted in the comments of the app's
save action code that propagating the modified state automatically
would be good, and it would solve issues like this, but I'm not yet
familiar enough with the code to try a change like that.
This commit is contained in:
Sam Atkins 2021-06-09 17:07:55 +01:00 committed by Andreas Kling
commit 6f92d1e639
Notes: sideshowbarker 2024-07-18 12:33:21 +09:00

View file

@ -1170,9 +1170,9 @@ bool TextEditor::write_to_file(const String& path)
return false;
}
if (file_size == 0)
return true;
if (file_size == 0) {
// A size 0 file doesn't need a data copy.
} else {
for (size_t i = 0; i < line_count(); ++i) {
auto& line = this->line(i);
if (line.length()) {
@ -1190,6 +1190,7 @@ bool TextEditor::write_to_file(const String& path)
return false;
}
}
}
document().set_unmodified();
return true;
}