Mark tabs as selected properly.

Fixes for issue #796.