Fix for history popup position. [1799]

This is a big improvement on the current (stupid) behavior, but I feel
like this needs a little more work.

Also implemented a proof of concept for dynamically modifying how many
menu items are visible (depending on menu position).