Always match active tab when switching to edit view

If the tab on the view section has been programatically set then there
isn't a location hash to the existing code doesn't work. This code
resolves this by working out which tab is selected via classes.

Fixes #522