int (int offset) { Document document = myEditor.getDocument(); CharSequence text = document.getCharsSequence(); if (offset >= document.getTextLength() - 1 || document.getLineCount() == 0) { return offset; } int newOffset = offset + 1; int lineNumber = myEditor.offsetToLogicalPosition(offset).line; int maxOffset = document.getLineEndOffset(lineNumber); if (newOffset > maxOffset) { if (lineNumber + 1 >= document.getLineCount()) { return offset; } maxOffset = document.getLineEndOffset(lineNumber + 1); } boolean camel = myEditor.getSettings().isCamelWords(); for (; newOffset < maxOffset; newOffset++) { if (EditorActionUtil.isWordEnd(text, newOffset, camel)) { break; } } return newOffset; }