[Core] Select next tab on tab remove before the tab is removed.

Otherwise the next tab is first shown without toolbars and then resized,
leading to bugs like #1366.

Fixes #1366.