https://bugs.documentfoundation.org/show_bug.cgi?id=173129

            Bug ID: 173129
           Summary: Error in file capitalise.py
           Product: LibreOffice
           Version: 26.8.0.0 alpha0+ master
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: LibreOffice
          Assignee: [email protected]
          Reporter: [email protected]

Error in the `capitalise.py` example file i in LibreOffice (26.8).
Also in older versions of LibreOffice and OpenOffice
The macro crashes if there is a multiple selection. I admit I didn't quite
understand why.
In the code, we find:
Code :
---------------------
xModel = XSCRIPTCONTEXT.getDocument()  # NOQA
    xSelectionSupplier = xModel.getCurrentController()
    xIndexAccess = xSelectionSupplier.getSelection()
    count = xIndexAccess.getCount()
if count >= 1:  # ie we have a selection
        i = 0
    while i < count:
        xTextRange = xIndexAccess.getByIndex(i)
        theString = xTextRange.getString()
        if len(theString)==0 # This is where the ambiguity lies.
-----------------
This works well with a single selection or no selection, but not with multiple
selections, because it is impossible to tell why the string is empty: is it the
first item in a list, or is there no selection?
Indeed, following these instructions, if there is no selection, the macro
selects the word under the cursor and applies the capitalization to it.
In the case of multiple selections, expanding the selection to the word at the
cursor disrupts the rest of the macro.
Therefore, simply replace the ambiguous line with:
---------------------------------
if len(theString)==0 and count == 1: # no sélection
---------------------------------
It gives a bad impression of Python programming with LibreOffice.

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to