Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to get the current line from a text editor
How to get the current line from a text editor [message #550165] Thu, 29 July 2010 12:28
Alex is currently offline AlexFriend
Messages: 114
Registered: June 2010
Senior Member
Hi,

I registered an entry for the context menu of the text editor and in the handler for that menu entry I'd like to get the current line as a string.
So the procedure for the user should be: right click the line and select the menu entry.
For me the current line is the line in which the cursor is located at the moment. an example:
line1: abcdefg
line2: hijklmn
line3: opqrstuvw

if the cursor is currently located after the "k" I'd like to have "line2: hijklmn" be returned.

At the moment I do
ITextSelection selection= (ITextSelection)HandlerUtil.getCurrentSelectionChecked(event);

to get the current selection. The problem is, that the offset of the selection is kind of unpredictable. sometimes I get line1 or line3 instead of line2. Once I get the correct line I will always get the correct one when repeat the steps. So it seems to me that the selection is not "up to date".

Is there a better way to get the cursor position (current row and current column)?

And is there a handy way to get the full line of a text editor?

- Alex

[Updated on: Fri, 30 July 2010 04:21]

Report message to a moderator

Previous Topic:retrieve the name of a file selected with the right mouse button
Next Topic:Product's 'windowImages' property - transparency not working
Goto Forum:
  


Current Time: Tue Apr 23 14:39:21 GMT 2024

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

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

Back to the top