TextRange (final XmlText xmlText) { final String value = xmlText.getValue(); final int i = value.indexOf(value); final int start = xmlText.displayToPhysical(i); return value.isEmpty() ? new TextRange(start, start) : new TextRange(start, xmlText.displayToPhysical(i + value.length() - 1) + 1); }