Intellij IDEA plugin development get selected text

To get selected text in a Intellij Platform Plugin project, we can use following code


The first line is used to get current editor object


Then call getSelectionModel and getSelectedText method to get selected text


The last two lines is to to some operation for selected text, it’s unrelated to our goal.