

Ask Your Question

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

asked 2020-08-28 21:03:55 +0200

Lupp gravatar image

updated 2020-08-29 10:59:34 +0200

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.)

edit retag flag offensive close merge delete


What you want really make?

mauricio gravatar imagemauricio ( 2020-08-28 23:19:43 +0200 )edit

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 ...(more)

Lupp gravatar imageLupp ( 2020-08-29 10:42:23 +0200 )edit

1 Answer

Sort by » oldest newest most voted

answered 2021-03-31 11:08:54 +0200

Kamil Landa gravatar image

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 https://forum.openoffice.org/en/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. C:\fakepath\AltTextRanges-en.odt

edit flag offensive delete link more
Login/Signup to Answer

Question Tools



Asked: 2020-08-28 21:03:55 +0200

Seen: 77 times

Last updated: Mar 31