Bug 168096 - Calc UNO API: cell object's XText methods behave erratically
Summary: Calc UNO API: cell object's XText methods behave erratically
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Mike Kaganski
URL:
Whiteboard: target:26.2.0 target:25.8.1
Keywords:
Depends on:
Blocks:
 
Reported: 2025-08-24 17:35 UTC by Mike Kaganski
Modified: 2025-08-25 12:14 UTC (History)
0 users

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2025-08-24 17:35:57 UTC
Consider this Basic code:

sub testCellXText
  doc = StarDesktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, Array())
  oCell = doc.Sheets(0).getCellByPosition(0,0)
  oCell.getStart()
  oCell.String = "b"
  
  oCell.insertString(oCell.createTextCursor(), "c", false)
  oCell.insertString(oCell.getStart(), "a", false)
  oCell.insertString(oCell.getEnd(), "d", false)
  oCell.insertString(oCell, "e", false)

  oCell.insertString(oCell.createTextCursor(), " 1: ", false)
  oField = doc.createInstance("com.sun.star.text.TextField.URL")
  oField.URL = "http://www.example.org/"
  oField.Representation = "h1"
  oCell.insertTextContent(oCell.createTextCursor(), oField, false)

  oCell.insertString(oCell.getEnd(), " 2: ", false)
  oField = doc.createInstance("com.sun.star.text.TextField.URL")
  oField.URL = "http://www.example.org/"
  oField.Representation = "h2"
  oCell.insertTextContent(oCell.createTextCursor(), oField, false)

  oCell.insertString(oCell, " 3: ", false)
  oField = doc.createInstance("com.sun.star.text.TextField.URL")
  oField.URL = "http://www.example.org/"
  oField.Representation = "h3"
  oCell.insertTextContent(oCell.createTextCursor(), oField, false)
end sub

The expected result of the code is "abcde 1: h1 2: h2 3: h3" (with h1, h2, h3 hyperlinks).

In 25.8.0.4, it produces "abcd 1: h1 2: h3h2"; the problems are silently failing call inserting "e" and " 3: ", and out-of-order insertion of "h3".

Silently failing insertion is related to bug 168073. However, after commits a8ce5af575ea5e05eb7c349d50b4eb08cab983ff and 02c9a71ea5344178b2849d153d0b1d83a681e334, there still is the out-of-order insertion problem: "abcde 1: h1 2:  3: h2h3".
Comment 1 Roman Kuznetsov 2025-08-24 19:42:33 UTC
https://gerrit.libreoffice.org/c/core/+/190142
Comment 2 Commit Notification 2025-08-25 09:55:09 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/e6eeace8879dd68760bc5e09664196e12d8fc9d5

tdf#168096: reset selection each time GetUnoText is called

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Commit Notification 2025-08-25 12:14:31 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "libreoffice-25-8":

https://git.libreoffice.org/core/commit/cd8f79fc01173ce66e84bef7be6bc04912e59fb0

tdf#168096: reset selection each time GetUnoText is called

It will be available in 25.8.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.