Fix shift+click selection extension for reverse selections (FF and older Chrome)

The selection direction was being lost when the window's current selection
was resynchronised to the cursor selection. For firefox and some versions
of Chrome, this would cause selection extension behaviours (shift+click)
to work incorrectly when attempting to extend the selection to the left
of the caret.

Note, this patch is largely a subset of some changes made in #112 in order to try and keep conflicts as few as possible.