void () { String text = """ package org; public class TestClass { int field; public int getField() { return field; } }"""; init(text); int blockSelectionStartOffset = text.indexOf("public int"); Editor editor = myFixture.getEditor(); LogicalPosition blockSelectionStartPosition = editor.offsetToLogicalPosition(blockSelectionStartOffset); LogicalPosition blockSelectionEndPosition = new LogicalPosition( blockSelectionStartPosition.line + 2, editor.offsetToLogicalPosition(text.indexOf('{', blockSelectionStartOffset)).column + 1); editor.getSelectionModel().setBlockSelection(blockSelectionStartPosition, blockSelectionEndPosition); verifySyntaxInfo(""" foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=public int\s foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=getField() { text= text= \s foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=return\s foreground=java.awt.Color[r=102,g=14,b=122],text=field foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=; text= text=} """); } public void testColumnModeBlockSelection() { String text = """ package org; public class TestClass { int field; public int getField() { return field; } }"""; init(text); int blockSelectionStartOffset = text.indexOf("public int"); Editor editor = myFixture.getEditor(); ((EditorEx) editor).setColumnMode(true); LogicalPosition blockSelectionStartPosition = editor.offsetToLogicalPosition(blockSelectionStartOffset); LogicalPosition blockSelectionEndPosition = new LogicalPosition( blockSelectionStartPosition.line + 2, editor.offsetToLogicalPosition(text.indexOf('{', blockSelectionStartOffset)).column + 1); editor.getSelectionModel().setBlockSelection(blockSelectionStartPosition, blockSelectionEndPosition); verifySyntaxInfo(""" foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=public int\s foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=getField() { text= text= \s foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=return\s foreground=java.awt.Color[r=102,g=14,b=122],text=field foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=; text= text=} """); } public void testColumnModeBlockSelectionWithGaps() { String text = """ public class TestClass { int field; int otherField; }"""; init(text); int blockSelectionStartOffset = text.indexOf("int"); Editor editor = myFixture.getEditor(); ((EditorEx) editor).setColumnMode(true); LogicalPosition blockSelectionStartPosition = editor.offsetToLogicalPosition(blockSelectionStartOffset); LogicalPosition blockSelectionEndPosition = new LogicalPosition(blockSelectionStartPosition.line + 2, blockSelectionStartPosition.column + 16); editor.getSelectionModel().setBlockSelection(blockSelectionStartPosition, blockSelectionEndPosition); verifySyntaxInfo(""" foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=int\s foreground=java.awt.Color[r=102,g=14,b=122],text=field foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=; text= text= foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=int\s foreground=java.awt.Color[r=102,g=14,b=122],text=otherField foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=; """); } public void testRegularSelection() { // We want to exclude unnecessary indents from the pasted results. String text = """ package org; public class TestClass { int field; public int getField() { return field; } }"""; init(text); int selectionStart = text.indexOf("public int"); int selectionEnd = text.indexOf('}', selectionStart) + 1; SelectionModel selectionModel = myFixture.getEditor().getSelectionModel(); selectionModel.setSelection(selectionStart, selectionEnd); String expected = """ foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=public int\s foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=getField() { text= \s foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=return\s foreground=java.awt.Color[r=102,g=14,b=122],text=field foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=; text=} """; verifySyntaxInfo(expected); selectionModel.setSelection(selectionStart - 2, selectionEnd); verifySyntaxInfo(expected); selectionModel.setSelection(selectionStart - 4, selectionEnd); verifySyntaxInfo(expected); } public void testIncorrectFirstLineCalculationOffset() { init("\"tr\" #> <selection>template.statusList.sortBy</selection>(_.index).map(fromStatus =>"); verifySyntaxInfo("fontStyle=0,text=template.statusList.sortBy\n"); } public void testJavadoc() { init( """ package org; import java.io.Serializable; <selection>/** * Code in <code>here</code> * <strong>Hi</strong> man * @param <T> </selection>*/ public interface SampleTest<T> extends Serializable { boolean isNotNull(); T getValue(); }""" ); verifySyntaxInfo(""" foreground=java.awt.Color[r=128,g=128,b=128],fontStyle=2,text=/** text= * Code in\s background=java.awt.Color[r=226,g=255,b=226],text=<code> background=java.awt.Color[r=255,g=255,b=255],text=here background=java.awt.Color[r=226,g=255,b=226],text=</code> background=java.awt.Color[r=255,g=255,b=255],text= text= *\s background=java.awt.Color[r=226,g=255,b=226],text=<strong> background=java.awt.Color[r=255,g=255,b=255],text=Hi background=java.awt.Color[r=226,g=255,b=226],text=</strong> background=java.awt.Color[r=255,g=255,b=255],text= man text= *\s fontStyle=3,text=@param\s foreground=java.awt.Color[r=61,g=61,b=61],text=<T> text=\s """); } public void testIndentStrippingWhenFirstLineIsMostIndented() { init(""" public class Test { <selection> int field; }</selection>"""); verifySyntaxInfo(""" text= \s foreground=java.awt.Color[r=0,g=0,b=128],fontStyle=1,text=int\s foreground=java.awt.Color[r=102,g=14,b=122],text=field foreground=java.awt.Color[r=0,g=0,b=0],fontStyle=0,text=; text=} """); }