The editor is a Java JComponent, which we are able to access in a user-code method as a JavaElement. I tried invoking a method on the component, but I always get "Specified method is not supported". Here is my example code:
public static void FindLine(RepoItemInfo editor, String snippet, int selectStart, int selectEnd) { String editorText = editor.FindAdapter<JavaElement>().Element.GetAttributeValueText("Text"); String[] lines = editorText.Split(new char[] {'\n'}); int lineStart = 0; for (int i = 0; i < lines.Length; i++) { if (lines.Contains(snippet)) { int begin = lineStart + selectStart; int end = begin + selectEnd; Report.Log(ReportLevel.Info, "User", "Found snippet '" + snippet + "' on line " + (i+1) + ". Selecting " + begin + ":" + end); int current = (int)element.InvokeMethod("getCaretPosition", new Object[0]); Report.Log(ReportLevel.Info, "User", "Current caret position: " + current); JavaObjectWrapper javaEditor = (JavaObjectWrapper)editor.FindAdapter<JavaElement>().InvokeMethod("getEditor", new Object[0]); JavaObjectWrapper selectionModel = (JavaObjectWrapper)javaEditor.GetProperty("mySelectionModel"); selectionModel.Invoke("setSelection", new Object[] {begin, end}); return; } lineStart += lines.Length + 1; } Validate.Fail("The snippet '" + snippet + "' was not found in the editor"); }
You can see that I have tried several things - getCaretPosition() is a method on the EditorComponentImpl (the IntelliJ editor class which extends JTextComponent), as is getEditor(). I don't actually care about getCaretPosition(), but I tried it since it returns an int and should be working.
What am I missing?
Windows 7, Ranorex 8.1.1, C#