Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [platform-text-dev] Going from ITextEditor to ITextViewer andback

> It is not a good practice to access the text widget unless you do it for your own editor. Please see org.eclipse.jface.text.ITextViewer.getTextWidget() for details.

Let me give a concrete example.

In this StackOverflow question [1], a user is writing a plugin that provides a context menu action, and they want to write a filter for the action that enables the action based on what in the editor was right-clicked.

To do this, they need to map the coordinates of the right-click in the editor, to a character offset. StyledText provides a public API for doing this, getOffsetAtPoint(), so I suggested that they use getAdapter() to obtain the StyledText, and then getOffsetAtPoint() to obtain the character offset.

Is there something wrong with this? Is there a better way that I could have suggested?

Thanks,
Nate

[1] https://stackoverflow.com/questions/51710935/eclipse-cdt-plugin-get-ast-element-based-of-x-and-y-position-of-mouse-click-in/

Back to the top