fix when the selected text contains parentheses; add related test