Add to undo stack when replacing after folder search

Fixes #536.