void () { // Inspired by IDEA-63313 String text = """ class Test { String my1FieldWithLongName; }"""; init(text, PlainTextFileType.INSTANCE); CaretModel caretModel = getEditor().getCaretModel(); SelectionModel selectionModel = getEditor().getSelectionModel(); IntList expectedBoundaries = new IntArrayList(); expectedBoundaries.add(text.indexOf("my")); expectedBoundaries.add(text.indexOf("Field")); expectedBoundaries.add(text.indexOf("With")); expectedBoundaries.add(text.indexOf("Long")); expectedBoundaries.add(text.indexOf("Name")); boolean camelWords = getEditor().getSettings().isCamelWords(); getEditor().getSettings().setCamelWords(true); try { int selectionStart; int selectionEnd = text.indexOf("Name") + 1; caretModel.moveToOffset(selectionEnd); // Check backward selection. for (int i = expectedBoundaries.size() - 1; i >= 0; i--) { selectionStart = expectedBoundaries.getInt(i); moveCaretToPreviousWordWithSelection(); assertEquals(selectionStart, caretModel.getOffset()); assertEquals(selectionStart, selectionModel.getSelectionStart()); assertEquals(selectionEnd, selectionModel.getSelectionEnd()); } // Check forward selection. selectionStart = text.indexOf("my") - 1; selectionModel.removeSelection(); caretModel.moveToOffset(selectionStart); for (int i = 1; i < expectedBoundaries.size(); i++) { selectionEnd = expectedBoundaries.getInt(i); moveCaretToNextWordWithSelection(); assertEquals(selectionEnd, caretModel.getOffset()); assertEquals(selectionStart, selectionModel.getSelectionStart()); assertEquals(selectionEnd, selectionModel.getSelectionEnd()); } } finally { getEditor().getSettings().setCamelWords(camelWords); } }