Hi,
I've discovered some strange behavior in the following scenario. I have implemented an Action on XtextEditors by implementing the IEditorActionDelegate interface.
In the selectionChanged-method I try to find the current element ( in the the semantic model) to the selected text.
Here the method:
@Override
public void selectionChanged(IAction action, ISelection selection) {
// get the selected text
if (EditorUtils.getActiveXtextEditor() != null) {
project = EditorUtils.getActiveXtextEditor().getResource().getProject();
// get the selected text
ITextSelection textSelection = (ITextSelection) EditorUtils.getActiveXtextEditor().getSelectionProvider().getSelection();
foundElement = getSelectedElement(textSelection);
if (foundElement != null)
System.out.println("foundElement: " + foundElement.toString());
}
}
So far everything is working fine. The problem appears when I open my XtextEditor and add some concrete syntax. For example a new state like here:
After saving the editor I mark the the text and run my action, but the new element is not found in the semantic model.
Here the code for finding the marked element:
private EObject getSelectedElement(ITextSelection textSelection) {
if (EditorUtils.getActiveXtextEditor() != null) {
EObjectAtOffsetHelper atOffsetHelper = new EObjectAtOffsetHelper();
int offset = textSelection.getOffset();
String xtextFilePath = EditorUtils.getActiveXtextEditor().getResource().getFullPath().toString();
XtextResource xtextRes= (XtextResource) set.getResource(URI.createPlatformResourceURI(xtextFilePath, true), true);
EObject elem = atOffsetHelper.resolveElementAt(xtextRes, offset);
if (elem != null) {
return elem;
}
}
return null;
}
Is this a bug, or am I doing something wrong?
Thanks for any help!
~Alex