Track last copied text, in order to find selection boundaries on paste

Issue #2697