proper synchronization in write
(cherry picked from commit 396bb2b)
separate stacks for undo / redo for light virtual files (potentially they can have no document)
(cherry picked from commit 4277ef1)