Correctly handle target text selection in query (following https://github.com/wolfgangmm/ShakespeareDemo/commit/20042fe)