There is a feature "a global undo capability without opening a files".
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.textmanager.interop.ivslinkedundotransactionmanager?view=visualstudiosdk-2022
This is an useful and more performant option instead of opening files to enable undo.