Variables: Undo and Redo clear a highlight that names no variable

Undo, Redo and a canceled undo group put back an earlier document but
left the Variables panel highlight as it was. After renaming the
highlighted variable and undoing, the highlight still named the new
name: a variable defined later under that name showed highlighted
without a click, and Delete removed it.

Each of these paths now clears a highlight whose variable the restored
document does not define, as Delete Variables and Load Variable Library
already did.
This commit is contained in:
dotCooCoo
2026-11-02 12:03:36 +07:00
committed by bflatastic
parent 0ccc6d9df5
commit adb446049b
7 changed files with 58 additions and 6 deletions
+1 -3
View File
@@ -231,9 +231,7 @@ fn delete(s: &mut Session, p: &Value) -> Result<Value> {
let n = s.edit("Delete Variables", |d, _| Ok(d.variables.prune(&names)))?;
// A highlight of a variable that is gone highlights nothing.
let st = s.doc_mut()?;
if st.variables_highlight.as_ref().is_some_and(|h| st.doc.variables.variable(h).is_none()) {
st.variables_highlight = None;
}
st.drop_stale_variables_highlight();
st.revision += 1;
Ok(json!({"deleted": n}))
}