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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user