Buffer: bump version on every content change

SetDirty(false) did not bump the version, so undo back to the saved
state (and reload, and replace_all_bytes) left the highlighter serving
spans for the old text. Reloading a file deleted on disk now also
clears undo history recorded against the old content.

Audit finding D9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015rcVQiiWyTzoNrsvLSaAfB
This commit is contained in:
Claude
2026-09-24 09:16:04 -07:00
committed by Kyle Isom
parent 52089d3564
commit f36aa9f456
2 changed files with 19 additions and 5 deletions
+13 -5
View File
@@ -391,11 +391,19 @@ public:
void SetDirty(bool d)
{
dirty_ = d;
if (d) {
++version_;
if (highlighter_) {
highlighter_->InvalidateFrom(0);
}
// Bump even when clearing: undo/redo back to the saved state changes the
// text and then calls SetDirty(false). Without a bump the highlighter
// keeps serving spans for the pre-undo text.
MarkContentChanged();
}
// Invalidate version-keyed caches (syntax highlighting) after a content change.
void MarkContentChanged()
{
++version_;
if (highlighter_) {
highlighter_->InvalidateFrom(0);
}
}