Automatically detect the currently active view before closing tabs

This ensures that when a new tab is opened it retains the focus,
rather than the previous tab.

Fixes #14.