Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Getting position (Point) of text cursor in editor
Getting position (Point) of text cursor in editor [message #493485] Mon, 26 October 2009 13:48 Go to next message
Andrey  is currently offline Andrey Friend
Messages: 4
Registered: October 2009
Junior Member
I'm trying to show custom popup menu at text cursor position in editor. So I create a command and key binding then add command handler where I creates popup menu and open it. But how can I get text cursor position to show my popup at cursor?
Re: Getting position (Point) of text cursor in editor [message #494754 is a reply to message #493485] Mon, 02 November 2009 14:15 Go to previous messageGo to next message
Matthias Kohles is currently offline Matthias KohlesFriend
Messages: 71
Registered: July 2009
Member
do you mean the line number in the opened document where the cursor is currently positioned?
Re: Getting position (Point) of text cursor in editor [message #494785 is a reply to message #494754] Mon, 02 November 2009 16:18 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur KronenbergFriend
Messages: 159
Registered: August 2009
Senior Member
The current position of your cursor is represented by the offset. When you are in an text editor you can get the ITextEditor like that:


public static ITextEditor getITextEditor(IEditorPart editor) {
		ITextEditor textEditor = null;
		if (editor instanceof ITextEditor) {
			textEditor = (ITextEditor) editor;
		} else {
			textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
		}
		return textEditor;
	}


When you have the text editor you can get the ITextSelection and in there the offset.

If you use a handler this might give you the neccessary selection where you find the offset:

HandlerUtil.getCurrentSelection(event)


Best,
Artur
Re: Getting position (Point) of text cursor in editor [message #494927 is a reply to message #494785] Tue, 03 November 2009 10:01 Go to previous messageGo to next message
Andrey  is currently offline Andrey Friend
Messages: 4
Registered: October 2009
Junior Member
Yep, I know how to get offset. But I don't know how to convert offset to exact position in pixels (x,y).
Re: Getting position (Point) of text cursor in editor [message #603076 is a reply to message #494754] Mon, 02 November 2009 16:18 Go to previous messageGo to next message
Artur Kronenberg is currently offline Artur KronenbergFriend
Messages: 159
Registered: August 2009
Senior Member
The current position of your cursor is represented by the offset. When you are in an text editor you can get the ITextEditor like that:


public static ITextEditor getITextEditor(IEditorPart editor) {
ITextEditor textEditor = null;
if (editor instanceof ITextEditor) {
textEditor = (ITextEditor) editor;
} else {
textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class);
}
return textEditor;
}

When you have the text editor you can get the ITextSelection and in there the offset.

If you use a handler this might give you the neccessary selection where you find the offset:

HandlerUtil.getCurrentSelection(event)

Best,
Artur
Re: Getting position (Point) of text cursor in editor [message #603094 is a reply to message #603076] Tue, 03 November 2009 10:02 Go to previous messageGo to next message
Andrey  is currently offline Andrey Friend
Messages: 4
Registered: October 2009
Junior Member
Yep, I know how to get offset. But I don't know how to convert offset to exact position in pixels (x,y).
Re: Getting position (Point) of text cursor in editor [message #849879 is a reply to message #603094] Thu, 19 April 2012 14:28 Go to previous messageGo to next message
Eclipse UserFriend
Hello NG,
I have the same problem. Is it possible anyhow to resolve the current x
and y coordinates in pixels for the current cursor position in a text
editor for displaying a tooltip at?

best regards,
Gilbert

Andrey wrote:
> Yep, I know how to get offset. But I don't know how to convert offset to
> exact position in pixels (x,y).
Re: Getting position (Point) of text cursor in editor [message #853622 is a reply to message #849879] Mon, 23 April 2012 07:16 Go to previous message
Eclipse UserFriend
no ideas?
Previous Topic:Editing Custom Library in Java Build Path
Next Topic:productBuild.xml and optional dependencies
Goto Forum:
  


Current Time: Thu Apr 25 05:54:58 GMT 2024

Powered by FUDForum. Page generated in 0.04192 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top