Fix ctrl-w

This PR fixes issue #996 as well as a similar problem that occurs when the find panel has focus.

This works but I'm not 100% sure that this is the correct or best way. @jleben would be great if you could take a look. Thanks to Luca Danieli for contributing the main fix.