better code
use selected text to filter the document
restore selection if canceled