Writer-API: com.sun.star.text.TextRanges service, (cf CurrentSelection). How to add or remove a TextRange?

Drawing objects, images, and frames aside, the .CurrentSelection of a Writer document supports the one service com.sun.star.text.TextRanges.
This service exports three intefaces, but none of them allows for any manipulations like adding or removing a TextRange object to/from the container. They only give access.
This is fundamentally different from other cases of .CurrentSelection objects.

Is there a somehow hidden way to create something containing more than one TextRange, and to pass it to the CurrentController for selection? XSearchable obviously knows how to create a TextRanges container for selection.

(The update only tried to clarify the subject, and eliminated a few minor typos.)

What you want really make?

  1. I want to understand.
  2. I want to be able to create a TextRanges container containing exactly the TextRanges I specified.
  3. I want to be able to pass such a container to another routine, e.g. one for further analysis or to the .select method of the respective CurrentController.
  4. To understand me precisely, think of the SheetCellRanges service in Calc which provides a container for objects each giving a SheetCellRange. There the fundamental methods .addRangeAddress and .removeRangeAddress exist. The respective handling is also supported by the ShapeCollection service in Draw and in Writer as well. In both these cases the containers can be empty.
  5. Based on my current knowledge I only can create a multiselection of TextRanges by direct user interaction with the help of the mouse (Ctrl+), or by a FindAll operation using a SearchDescriptor.
  6. I will also edit now the subject of the topic to make it more clear.

I think it is not possible to create own TextRanges in the Basic. But it is possible to do own TextRanges with the help of some Character Property (maybe the fittest is CharFlash Select multiple text ranges in Writer (View topic) • Apache OpenOffice Community Forum) or by adding the special string to the requested findings. In any case it means the multiple searching, but it seems it is functional.

  1. With property CharFlash: it finds all occurences, but for requested ones sets the CharFlash=true. Then it finds occurences with CharFlash=true and these are own TextRanges. Then it sets the CharFlash=false. And then it is possible to use Select() even though some property (CharFlash) was change.

  2. With special string: it finds all occurences, but for the requested ones it adds some special string to their ends. Then it finds occurences with special string and these are own TextRanges and it selects ones. Then it deletes the special strings, but previous selection will stay.

In the example it tests the property CharFlash before using it for searching; or it also tests the occurence of the special string.
AltTextRanges-en.odt