Skip to main content



      Home
Home » Eclipse Projects » Eclipse Platform » Mouse event in text editor
Mouse event in text editor [message #283168] Mon, 28 March 2005 19:19 Go to next message
Eclipse UserFriend
Hi,

I want to be able to get the current text cursor position in my
TextEditor when the user clicks in the editor to move the cursor where
the click occurs.

Thanks
Re: Mouse event in text editor [message #283193 is a reply to message #283168] Tue, 29 March 2005 10:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: B.m.ie

Given your IEditorPart editor -
Control control = (Control)editor.getAdapter(Control.class);
if (control instanceof StyledText)
{
final StyledText text = (StyledText) control;
text.addPaintListener(APaintListener);
}

within APaintListener:

public void paintControl(PaintEvent e)
{

IEditorPart editor =
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActiveEditor();

TextSelection selectedText = (TextSelection)
editor.getEditorSite().getSelectionProvider().getSelection() ;

int offset = selectedText.getOffset();
IDocument doc = ((ITextEditor)
editor).getDocumentProvider().getDocument(editor.getEditorIn put());
int line = doc.getLineOfOffset(offset);

}


the int line will have the current line number
Re: Mouse event in text editor [message #283215 is a reply to message #283193] Tue, 29 March 2005 18:07 Go to previous message
Eclipse UserFriend
Thanks!

BM wrote:

> Given your IEditorPart editor -
> Control control = (Control)editor.getAdapter(Control.class);
> if (control instanceof StyledText) {
> final StyledText text = (StyledText) control;
> text.addPaintListener(APaintListener);
> }
>
> within APaintListener:
>
> public void paintControl(PaintEvent e)
> {
>
> IEditorPart editor =
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActi vePage().getActiveEditor();
>
>
> TextSelection selectedText = (TextSelection)
> editor.getEditorSite().getSelectionProvider().getSelection() ;
>
> int offset = selectedText.getOffset();
> IDocument doc = ((ITextEditor)
> editor).getDocumentProvider().getDocument(editor.getEditorIn put());
> int line = doc.getLineOfOffset(offset);
>
> }
>
>
> the int line will have the current line number
>
>
Previous Topic:Calling menu Actions
Next Topic:Generic Method override compatibility
Goto Forum:
  


Current Time: Tue Nov 04 01:30:10 EST 2025

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

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

Back to the top