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

            Bug ID: 169169
           Summary: Writer Comment/Annotation not inserted "correctly"
                    using `insertTextContent`
           Product: LibreOffice
           Version: unspecified
          Hardware: All
                OS: All
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: Writer
          Assignee: [email protected]
          Reporter: [email protected]

Description:
Consider the following code:

```
Sub CreateComments(searchText as String, commentText as String)
    doc = ThisComponent
    search = doc.createSearchDescriptor()
    search.searchString = searchText
    ranges = doc.findAll(search)

    For i = 0 To ranges.Count - 1
        note = doc.createInstance("com.sun.star.text.textfield.Annotation")
        note.Content = commentText
        range = ranges.getByIndex(i)
        cursor = range.Text.createTextCursorByRange(range)
        cursor.CharWeight = com.sun.star.awt.FontWeight.BOLD ' for debugging
purposes
        range.Text.insertTextContent(cursor, note, False)
    Next
End Sub

Sub PromptAndCreateComments()
    Dim searchText As String
    searchText = InputBox("Enter text to search for:", "Search")
    If Len(Trim(searchText)) = 0 Then
        MsgBox "No search text entered. Aborting."
        Exit Sub
    End If
    CreateComments(searchText, searchText)
End Sub
```

Steps to Reproduce:
Run `PromptAndCreateComments` on a Writer document which contains the string
that is supplied to the search prompt

Actual Results:
The script will create comments referencing only the beginnings of the found
ranges.

Expected Results:
I would expect the `insertTextContent` to use the range pointed to by the
cursor, not only its start. I.e., I would expect the resulting comments to
reference the whole ranges.


Reproducible: Always


User Profile Reset: No

Additional Info:
It can be shown by the bold text that the cursor references the correct ranges,
and it is simply not used by the `insertTextContent`.

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

Reply via email to