开发者

read text at cursor position in JFace TextViewer

开发者 https://www.devze.com 2023-03-30 04:07 出处:网络
I have an editor that extends a TextEditor class. I would like to know if it is possible to read the text at the cursor position within the editor.

I have an editor that extends a TextEditor class. I would like to know if it is possible to read the text at the cursor position within the editor. Using ITextSelection is not useful since it expects that some text string is selected. I require to read text when the cursor is at some point and no text 开发者_如何学Pythonis selected.

Thanks.


ITextViewer.getSelectedRange(). It will return the offset and the size of the selection. Offset is the caret position and size may be 0. To read the text, use ITextViewer.getDocument().get() and analyze the contents at the respective offset.

0

精彩评论

暂无评论...
验证码 换一张
取 消