I am using:
offset = selection.getAbsoluteCursorOffset()
lineno = selection.getLineOfOffset(offset)
line = selection.getLine(lineno)
to get the line containing the current cursor position. I then march up
and down the text grabbing lines until I have acquired the 'paragraph'
of text that contains the cursor.
PySelection has a 'selectCompleteLine' method that may be what you want...
Eventually I replace this paragraph with a reformatted paragraph. In
order to do this I need to figure out the offsets to the first character
of the original paragraph and to the last character of the delimiter on
the last line of the paragraph. Right now I am assuming that I can do
the latter by adding len(selection.getDelimiter(document)) to the last
character offset but this assumes that the delimiter on the last line is
the same size as the document delimiter.
Actually, I think you could use the PySelection.deleteLine approach (it checks the offset of the next line to see what it should delete -- if there's a 'next' line).
It is possible that this is not true, for example by using a Windows
editor to change a document that originated on Linux. However, I believe
that CPython gets upset if mixed delimiters are used within the same
document so maybe this does not really matter.
Maybe, I'm not really sure about this one...
In any case, I can use the IDocument method getLineDelimiter() to get
the line delimiter for a specific line, but it looks like you intended
PySelection to be the main interface for Jython extension scripts so
maybe you want add something like this one day.
BTW. I noticed that PySelection does not have a method
getStartLineOffset(lineno) that would be a pair with
getEndLineOffset(lineno). Not a big deal as it is easy to calculate.
Yeah, probably could be done...
I actually meant the line number shown at the bottom of the screen in
Eclipse - this line number always starts at 1, which is apparantly
internally known as line 0. So it looks like Eclipse is inconsistent
about starting at 0 or 1. No matter.
Oops... Well, yes, Eclipse has one representation for the gui and one for the internal API.
-- Fabio
