TextRange (String editorText, int start, int end) { int sentenceStart = start; while (sentenceStart > 0) { if (start - sentenceStart > 1000) return null; if (isSentenceEnd(editorText, sentenceStart - 1) || !isNatural(editorText.charAt(sentenceStart - 1))) { break; } sentenceStart--; } int sentenceEnd = Math.max(0, end - 1); while (sentenceEnd < editorText.length()) { sentenceEnd++; if (sentenceEnd - end > 1000) return null; if (isSentenceEnd(editorText, sentenceEnd - 1)) { break; } } while (sentenceStart < sentenceEnd && Character.isWhitespace(editorText.charAt(sentenceStart))) { sentenceStart++; } return new TextRange(sentenceStart, sentenceEnd); }