Correctly handle target text selection in query.