Bug 157141

Summary: Text portion for content control gives empty string
Product: LibreOffice Reporter: Mike Kaganski <mikekaganski>
Component: WriterAssignee: Not Assigned <libreoffice-bugs>
Status: NEW ---    
Severity: minor CC: ilmari.lauhakangas, vmiklos
Priority: medium    
Version: unspecified   
Hardware: All   
OS: All   
Whiteboard:
Crash report or crash signature: Regression By:
Bug Depends on:    
Bug Blocks: 113363    

Description Mike Kaganski 2023-09-07 16:55:43 UTC
Open attachment 189413 [details], and use this code:

sub TestContentControlImportedObjects
  paragraphs = thisComponent.getText().createEnumeration()
  para1 = paragraphs.nextElement()
  runs1 = para1.createEnumeration()
  run1 = runs1.nextElement()
  para2 = paragraphs.nextElement()
  runs2 = para2.createEnumeration()
  run2 = runs2.nextElement()

  MsgBox run1.getString()
  MsgBox run2.getString()
  MsgBox run2.ContentControl.getString()
end sub

The document has two paragraphs, each having a content control with a placeholder text. Because the first one is a block control (which content includes the respective paragraph), and the second is an inline control (contained in the paragraph, and the content includes only a run), these two are imported differently (as of 2023-09-07): the first one as a field, and the second one as a content control.

The three MsgBox calls in the end of the code are expected to show the same "Click or tap here to enter text." string. However, the second call showing "run2.getString()" produces an empty message.

This happens because lcl_CreateContentControlPortion in sw/source/core/unocore/unoportenum.cxx is called with pUnoCursor pointing to the end of the paragraph. Looks like it needs to take into account the values of rAttr (and respective SwContentControl), and pPortions, which may contain the range that should become the actual cursor.
Comment 1 Buovjaga 2023-09-26 06:02:56 UTC
Repro

Arch Linux 64-bit, X11
Version: 24.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 5e9c8d21874eea8cb5adf2ecab1905295af2308f
CPU threads: 8; OS: Linux 6.5; UI render: default; VCL: kf5 (cairo+xcb)
Locale: fi-FI (fi_FI.UTF-8); UI: en-US
Calc: threaded
Built on 26 September 2023