After a ton of stepping through the SharePoint JS in a debugger, I've finally found a way to prevent this problem.
In SharePoint 2010:
//Set focus on our list web part
var webPart = document.getElementById('WebPartWPQ1');
WpClick({target: webPart});
//Prevent it from losing focus
SP.Ribbon.WebPartComponent.$3_1.deselectWebPartAndZone = function() { };
In SharePoint 2013 Beta:
//Set focus on our list web part
var webPart = document.getElementById('MSOZoneCell_WebPartWPQ2');
WpClick({target: webPart});
//Prevent it from losing focus
SP.Ribbon.WebPartComponent.$3.deselectWebPartAndZone = function() { };
Note: This is super-hacky, and is in no way supported by Microsoft (thus it's very likely to change in a future version or possibly even the RTM of SharePoint 2013).
Also, note that your web part ids are likely to be different, so you should double check you're giving focus to the correct web part.
Explanation: It basically overrides the instance of SP.Ribbon.WebPartComponent
's ability to deselect a web part. From what I can tell, the $3/$3_1 property stores a reference to the SP.Ribbon.WebPartComponent
instance.
If anyone knows of a better way to access the instance of SP.Ribbon.WebPartComponent
other than the $3/$3_1 property, please speak up, as that would be make this method much more robust.