fix undo when invalid & selection #440