fixed IDEA-132100 and IDEA-132017 - incorrect mode after restore from history
(cherry picked from commit 1d3e17d)