TextRange (String editorText, int start, int end) { while (start > 0) { if (!isNatural(editorText.charAt(start - 1))) { break; } start--; } while (end < editorText.length()) { final char c = editorText.charAt(end); if (!isNatural(c)) { break; } end++; } return new TextRange(start, end); }