AltSearch Extension error

I use the AltSearch extension every now and then. Sometimes, I wish to format the results of a search using a particular character style.
There is such an option in the replace options and I’ve being using it for a long time.
Recently, with LO 25.2, I’m having an issue with this. I’m getting an error stating:

Style ‘Endnote anchor’ isn’t included in current document

Can someone suggest a solution or workaround?

This is a bug and a regression from tdf#159549. File it.

But it seems to me, that you wasn’t completely correct when writing your question - just because, I guess, if you would search exactly for Endnote anchor, it wouldn’t fail. My assumption - based on my own experiment - is that you used the procedure like this: in the AltSearch dialog, you clicked the “Replace” drop-down, selected “Character style” element, and then in the “Select style” dialog, chose “Endnote Anchor” element there (with both words capitalized!). That created the replacement string \C{Endnote Anchor}, again with both initial characters capitalized, and that gave the error, which you typed yourself in the question (and overlooked the different character case), instead of copying and pasting? Note that details matter. And note that you can workaround it for now - replacing the capitalization.

The regression can be demonstrated by this Basic code:

  family = ThisComponent.StyleFamilies.getByName("CharacterStyles")
  for each n in family.getElementNames()
    style = family.getByName(n)
    if (not family.hasByName(style.DisplayName)) then MsgBox style.DisplayName
  next n

Previously, hasByName / getByName accepted not only programmatic names, but also display names. This is exploited by AltSearch (its GetStyles produces an array of display names, and these strings are used further). Of course, the extension could be improved by keeping the programmatic name along with display name, and using the programmatic name where needed - but it’s impossible to make sure that countless macros and other extensions do not rely on that. And there is no explicit restriction in StyleFamily service, which names are accepted or not - so this change is an API break.

EDIT:

Hmm, likely it doesn’t make sense to file a bug. This change is documented as an API change in the release notes. So the only way forward is to ask the extension maintainer to fix it.

I couldn’t copy paste the error from the dialog box. Text was not selectable. You are saying that I can work around the issue by using small letters instead of capitals?

Can you upload example ODT with the steps to reproduce the bug? Maybe I could look to AltSearch code and maybe try write some fix during weekend.

1 Like

Sample.odt (32.1 KB)

Try doing a search for any digit (\d) and “replace” it with \C{Endnote Anchor}.

  • AltSearch use the DisplayName attribute of the Character Style, “Endnote Anchor
  • The real name of this Character Style is “Endnote anchor
    If you use the replace expresion \C{Endnote anchor} all is ok

The problem is for the change in the API in the version 25.x as @mikekaganski said

  • I think it is a drastic change and I don’t know if it is very justified.
1 Like

It is an API change, indeed; it was worth of mentioning in release notes (so yes, it is of course significant).

I wonder what this phrase is meant to convey. Literally reading it, if you don’t know, you are welcome to learn. But was that to mean “I claim it wasn’t justified”? It was introduced because there were real problems that required that change.

If I didn’t know, I didn’t know.

If it was to resolve problem, so, it is justified
-(Sorry my bad english)

This is a nice workaround. Where do you see the actual name of the character style?

I can obtain it with some macros but you can see the “Real name” of styles with the extension Styles Reporter by F. Nifenecker

1 Like

Here is another option for displaying all styles of any LibreOffice document (ShowStyles).

Sub ShowStyles(Optional ByVal oDoc As Object)
  Dim arr(9999), indArr As Long, j As Long, styleFamilyName As String, displayName As String
  Dim styleFamily As Object, style As Object
  If IsMissing(oDoc) Then oDoc = ThisComponent
  
  arr(0) = Array("StyleFamily", "DisplayName", "Name", "ParentStyle")
  indArr = 0
  
  On Error Resume Next
  For Each styleFamilyName In oDoc.StyleFamilies.ElementNames
    styleFamily = oDoc.StyleFamilies.getByName(styleFamilyName)
    For j = 0 To styleFamily.count - 1
      style = styleFamily(j)
      indArr = indArr + 1 
      displayName = ""
      displayName = style.DisplayName
      arr(indArr) = Array(styleFamilyName, displayName, style.Name, style.ParentStyle)
    Next j
    
  Next styleFamilyName
  On Error GoTo 0
  
  ReDim Preserve arr(indArr)
  ShowDataArray arr  
End Sub

Sub ShowDataArray(ByVal dataArray)
  Dim oCalcDoc As Object, oRange As Object, oColumns As Object
  Dim oLocale As Object, i As Long
  oCalcDoc = StarDesktop.LoadComponentFromUrl("private:factory/scalc","_default",0, Array())
  oRange = oCalcDoc.Sheets(0).getCellRangeByPosition(0, 0, Ubound(dataArray(0)), Ubound(dataArray))
  oRange.setDataArray dataArray
  
  ' Title style
  oRange.getCellRangeByPosition(0, 0, oRange.Columns.Count-1, 0).CellStyle="Accent"
  
  ' Don't check spelling
  oLocale = oRange.CharLocale
  oLocale.Country = ""
  oLocale.Language = "zxx"
  oRange.CharLocale = oLocale
  
  oColumns = oRange.Spreadsheet.Columns
    
  ' AutoFilter
  oCalcDoc.DatabaseRanges.addNewByName("db_1", oRange.RangeAddress)
  oCalcDoc.DatabaseRanges.getByName("db_1").autoFilter=True
  
  ' OptimalWidth
  For i = 0 To oRange.Columns.Count-1
    oColumns.getByIndex(i).OptimalWidth=True
  Next i
End Sub

As @mikekaganski wrote, use Endnote anchor. Here is macro that shows the .Name : .DisplayName of Character Styles, so use the first names (before :).

sub showCharStyleNames
	dim family as object, style as object, n$, s$
	family = ThisComponent.StyleFamilies.getByName("CharacterStyles")
	for each n in family.getElementNames()
		style = family.getByName(n)
		s=s & n & " : " & style.DisplayName & chr(13) 'Name : DisplayName
	next n
	msgbox s
End Sub

You can fix the AltSearch with the macros from this file - rename the ODT to ZIP and unpack and see _readme.txt → there is one new function and replacement of two functions.
fix-AltSearch.zip.RENAMED.ODT (11.8 kB)

I know it is not comfortable solution, but it isn’t in my possibilities to adopt the AltSearch now - but see Extension AltSearch - bugs and requests.

	for each style in family
		s=s &  style.Name & " : " & style.DisplayName & chr(13) 
	next style
1 Like