(as they appear in the Navigator, not what is retrieved by the api textsections list which isn't in document order)
Uses Lupp's method of getting the position from the viewcursor (as applied to annotation anchors here:
viewtopic.php?t=111343
Limited tested on OO only. In the past I have had issues with Writer not always updating the viewcursor position - so may occur here.
Code: Select all
REM ***** BASIC *****
Option Explicit
Sub GetTextSectionInDocOrder
dim cont,vc,ts, i as long,y as long,ub as long,j as long,k as long, found as boolean
ts = thiscomponent.textsections
ub=ts.count -1
cont = thiscomponent.currentcontroller
vc= cont.viewcursor
dim ps(ub) as long,nms(ub) as string
for i = 0 to ub
cont.select ts(i).getanchor.getstart
y = vc.position.y
found = false
if i = 0 then
ps(0) =y
nms(0) = ts(0).getname
else
for j= i -1 to 0 step -1
k = j+1
if ps(j)>y then
ps(k) = ps(j)
nms(k) =nms(j)
else
nms(k) = ts(i).getname
ps(k)=y
found = true
exit for
end if
next
if not found then
ps(0) = y
nms(0) = ts(i).getname
end if
end if
next
mri nms
mri ps
' mri thiscomponent.textsections.elementnames
End Sub
* Edit: 14/3/24
CORRECTED ERROR IN THE SORTING ROUTINE