int (@NotNull Editor editor, @NotNull CaretStopPolicy caretStopPolicy, boolean isCamel, boolean handleQuoted) { int maxOffset = getNextLineStopOffset(editor, caretStopPolicy.getLineStop()); final CaretStop wordStop = caretStopPolicy.getWordStop(); if (wordStop.equals(CaretStop.NONE)) return maxOffset; final int offset = editor.getCaretModel().getOffset(); if (offset == maxOffset) return maxOffset; final CharSequence text = editor.getDocument().getCharsSequence(); final HighlighterIterator tokenIterator = createHighlighterIteratorAtOffset(editor, offset); final int newOffset = getNextWordStopOffset(text, wordStop, tokenIterator, offset, maxOffset, isCamel); if (newOffset < maxOffset && handleQuoted && !tokenIterator.atEnd() && isTokenStart(tokenIterator, newOffset - 1) && isQuotedToken(tokenIterator, text)) { // now at the end of an opening quote: | "word" -> "|word" // find the start of a closing quote: "|word" -> "word|" (must be only a single step away) final int newOffsetBeforeQuote = getNextWordStopOffset(text, CaretStop.BOTH, tokenIterator, newOffset, maxOffset, isCamel); if (isTokenEnd(tokenIterator, newOffsetBeforeQuote + 1)) { return getNextWordStopOffset(text, wordStop, tokenIterator, newOffsetBeforeQuote, maxOffset, isCamel); // "word"| } } return newOffset; }