Ask Your Question

how can i know if the cursor is at the end of the line

asked 2020-01-18 00:44:34 +0200

juliosmax gravatar image

hi, i am using the java api to manipulate a document, i need to know if a XTextCursor object is at the end of the line, i saw the documentation in open office and i found this method: isAtEndOfLine(), but this is writen in C i guess, is there any equivalent in java api for this?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2020-01-18 16:40:41 +0200

Lupp gravatar image

I don't use Java. However ...
A TextCursor doesn't know about lines. The function isAtEndOfLine is supplied by the XLineCursor interface. The only object I know offering this interface is the ViewCursor.
The following Basic code using it for the purpose surely isn't exactly pretty, and will also not be very efficient but...

Function tryIsTextCursorAtEndOfLine(pDoc, pTextCursor, ByRef pErr) As Boolean
REM This is a construct I often use to get a similar functionality
REM as is provided by programming laguages as (e.g.) "Try ... Except ...End" 
tryIsTextCursorAtEndOfLine = False
pErr   = True
On Local Error Goto fail
cCtrl  = pDoc.CurrentController
lText  = pTextCursor.Text
vC     = cCtrl.ViewCursor
oldSel = pDoc.CurrentSelection
tryIsTextCursorAtEndOfLine = vC.isAtEndOfLine()
pErr  = False
End Function

Since your Java must have its way to access all the API elements used, the implementation of an equivalent function should be simple.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2020-01-18 00:44:34 +0200

Seen: 33 times

Last updated: Jan 18