Inconsistent find and replace

I am writing a libreoffice basic macro which is supposed to shrink and hide all text which is not bold and not highlighted. I am taking inspiration from Andrew Pitonyak’s OOME_4 document, listing 368. However, when I run the macro, it behaves inconsistently. When a paragraph has one, or two areas that are highlighted, it works perfectly. However, on three or more, it only hides the first part of the paragraph (see images below). Also, sometimes it will hide bolded text. I have no idea why it is acting in this way, is there another way to accomplish this?

Before macro:

After macro:

Before macro:

After macro:

Here is the code:

Sub InvisibiliyOn
  REM original code : Alex Savitsky
  REM modified by : Laurent Godard
  REM modified by : Andrew Pitonyak
  REM The purpose of this macro is to surround all BOLD elements with {{ }}
  REM and change the Bold attribute to NORMAL by using a regular expression.

  Dim oReplace
  Dim SrchAttributes(1) as new
  Dim ReplAttributes(1) as new

  oReplace = ThisComponent.createReplaceDescriptor()

  oReplace.SearchString = ".*"           'Regular expression. Match any text
  oReplace.ReplaceString = "&"     'Note the & places the found text back
  oReplace.SearchRegularExpression=True  'Use regular expressions
  oReplace.searchStyles=True             'We want to search styles
  oReplace.searchAll=True                'Do the entire document

  REM This is the attribute to find
  SrchAttributes(0).Name = "CharBackTransparent"
  SrchAttributes(0).Value = true
  SrchAttributes(1).Name = "CharWeight"

  REM This is the attribute to replace it with
  ReplAttributes(0).Name = "CharColor"
  ReplAttributes(0).Value =16777215
  ReplAttributes(1).Name = "CharHeight"
  ReplAttributes(1).Value = 4
  REM Set the attributes in the replace descriptor

  REM Now do the work!
End Sub

Which LO version do you use? recently we had changed some operation of search/replace. But if it’s a recent version, it’s useful to file a bug report.

I’m on
Build ID: 6.4.4-1

By the way: why searchStyles? you don’t search for styles here.

It was in the original macro

Also, I tried downgrading to, but the bug persisted.

so as I said - please do file a bug report.