Move selectionChanged code to its own class.

Work on #440.
Fix reverse selection if char at EOL got excluded.

When the last char of a reverse selection is at the end of the line, the
"empty-selection" code might kick in and move the cursor one to the
left. The user might still have his mouse button down and keep dragging
a selection, but now it will not include that last character.

If a new selection is made which should likely have included that last
character, simply include it.

Fixes #440.