API for xIndexAccess of text selection

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
User avatar
jeanmi2403
Posts: 33
Joined: Tue Jan 29, 2008 12:37 pm
Location: Sucy en Brie (France)

API for xIndexAccess of text selection

Post by jeanmi2403 »

Hello,
What intrigues me is the structure of the selection list, and the fact that this was what caused the error in the `capitalise.py` example.
So, it is the behavior (and design logic) of `xIndexAccess` that I am struggling to understand.
Reminder:
No selection : one element at index 0 (empty)
One selected object : one element at index 0 (contains the selection)
N objects (N>1) : N+1 elements, the first (index 0) being empty.
This strange behavior (in my view) is visible in the short exercise that follows.
TestSelectionsPython-en.odt
Traverse the selected zones
(22.54 KiB) Downloaded 169 times
Can anyone explain this behavior?
Last edited by MrProgrammer on Fri Aug 14, 2026 4:33 am, edited 1 time in total.
Reason: Edited topic's subject
Jean-Michel
LibO 26.2 and AOO 4.1.16 on Windows 11 & Ubuntu 22.04
LibO 26.8 on OpenSuse & Linux MX
User avatar
karolus
Volunteer
Posts: 1252
Joined: Sat Jul 02, 2011 9:47 am

Re: API for xIndexAccess of text selection

Post by karolus »

jeanmi2403 wrote: Fri Aug 14, 2026 12:05 am
No selection : one element at index 0 (empty)
There is no »no Selection« in writer, at least one selection exists (probably empty) at the position of the View-Cursor!
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
User avatar
jeanmi2403
Posts: 33
Joined: Tue Jan 29, 2008 12:37 pm
Location: Sucy en Brie (France)

Re: API for xIndexAccess of text selection

Post by jeanmi2403 »

karolus wrote: Mon Aug 17, 2026 6:41 pm There is no »no Selection« in writer, at least one selection exists (probably empty) at the position of the View-Cursor!
Ok.
My question is : Why do two selections produce a 3-element array where the first element is empty?
Jean-Michel
LibO 26.2 and AOO 4.1.16 on Windows 11 & Ubuntu 22.04
LibO 26.8 on OpenSuse & Linux MX
User avatar
karolus
Volunteer
Posts: 1252
Joined: Sat Jul 02, 2011 9:47 am

Re: API for xIndexAccess of text selection

Post by karolus »

jeanmi2403 wrote: Mon Aug 17, 2026 9:43 pm
karolus wrote: Mon Aug 17, 2026 6:41 pm There is no »no Selection« in writer, at least one selection exists (probably empty) at the position of the View-Cursor!
Ok.
My question is : Why do two selections produce a 3-element array where the first element is empty?
because your »two-selections-container« is in real a »three-selections-container« (including the »empty« …ViewCursor-object)
Libreoffice 25.2… on Debian 13 (trixie) (on RaspberryPI5)
Libreoffice 25.8… flatpak on Debian 13 (trixie) (on RaspberryPI5)
User avatar
jeanmi2403
Posts: 33
Joined: Tue Jan 29, 2008 12:37 pm
Location: Sucy en Brie (France)

Re: API for xIndexAccess of text selection

Post by jeanmi2403 »

And doesn't a lonely selection have an empty counterpart?
It is hard to find any consistency.
Jean-Michel
LibO 26.2 and AOO 4.1.16 on Windows 11 & Ubuntu 22.04
LibO 26.8 on OpenSuse & Linux MX
Post Reply