The following gives the same result regardless of which direction the selection is made and therefore which end the viewcursor is.
So the question is - how to find out where the viewcursor is when there is a selection?
Looking at MRI for clues... it looks that it can only be done easily if the selection ends or starts on a line using
it can be done by getting the position of the viewcursor, collapsing it, getting the position again, comparing the two and restoring the selection
It can be found in a complicated fashion using the accessiblecontext.
The following uses constants which work for me to get the "Document view" (the text window), which may differ for you
and assumes you have the view cursor in the first line of the document
.getCaretPosition will get the view cursor's character position
To turn this method into a generic sub without making these assumptions will be some work and may be very innefficient and/or prone to crashes.
Code:
vc = ThisComponent.getCurrentController().getViewCursor()oText =vc.getText()tc = otext.createtextcursorbyrange(vc.start)tc.goright(1,true)msgbox tc.string
Looking at MRI for clues... it looks that it can only be done easily if the selection ends or starts on a line using
Code:
vc.isAtEndOfLinevc.isAtStartOfLine
Code:
vc = ThisComponent.getCurrentController().getViewCursor()tc = vc.text.createtextcursorbyrange(vc)pos1 = vc.getpositionvc.collapsetoendpos2 = vc.getpositionvc.gotorange(Tc,false)if pos1.x - pos2.x =0 and pos1.y - pos2.y = 0 then msgbox "at end" else msgbox "at start"end if
The following uses constants which work for me to get the "Document view" (the text window), which may differ for you
and assumes you have the view cursor in the first line of the document
.getCaretPosition will get the view cursor's character position
To turn this method into a generic sub without making these assumptions will be some work and may be very innefficient and/or prone to crashes.
Code:
dim w1,w2w1 =ThisComponent.getCurrentController.frame.componentwindow.windows(0)w2 = w1.accessiblecontext.getaccessiblechild(0).accessiblecontext.getaccessiblechild(0)'AccessibleDescription= "Document view"msgbox w2.getAccessibleChild(0).getCaretPosition
Statistics: Posted by JeJe — Sat Jun 01, 2024 11:58 pm