How can I get cursor position (number, not an object)?


I try to get cursor position number, not an object but a from/to position (C#).

How can this be done ?

Thank you very much for any help

Hello @OfficeNet,

To get the current cursor position number in the current LibreOffice Writer document, you could use the following Function:

Function Writer_getCursorPosition() As Long
REM Returns the position of the Cursor inside the normal text flow within the current Writer document.
	If Not ThisComponent.supportsService( "" ) Then Stop
	Dim lCount  As Long
	Dim oText   As Object : oText   = ThisComponent.getText()
	Dim oCursor As Object : oCursor = oText.createTextCursorByRange( ThisComponent.CurrentSelection.getByIndex(0) )
	Do While oCursor.goLeft( 1, False )
		lCount = lCount + 1
	Writer_getCursorPosition = lCount
End Function