sw/inc/txatbase.hxx                 |    4 ++--
 sw/sdi/swriter.sdi                  |    4 ++--
 sw/source/core/txtnode/atrref.cxx   |   20 +++++++++++---------
 sw/source/uibase/fldui/fldmgr.cxx   |    9 +++++++++
 sw/source/uibase/inc/fldmgr.hxx     |   25 +++++++++++++++----------
 sw/source/uibase/shells/basesh.cxx  |   20 ++++++++++++++++++--
 sw/source/uibase/shells/textfld.cxx |    9 ++++++++-
 7 files changed, 65 insertions(+), 26 deletions(-)

New commits:
commit 3b379b6dfd8b9400ae5412b00ae3be1d8851669d
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Wed May 14 19:24:15 2025 +0530
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri May 23 10:13:42 2025 +0200

    sw: avoid front expansion of field with NeverExpand flag
    
    improvment on d6b8e20c9cdca69d684390c264e775a708777846
    
    Change-Id: I572090466f4df7c93099244d7f07e62c1468176e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185316
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185351
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185555
    Tested-by: Jenkins

diff --git a/sw/inc/txatbase.hxx b/sw/inc/txatbase.hxx
index 4fccc588d112..9069e2a6952b 100644
--- a/sw/inc/txatbase.hxx
+++ b/sw/inc/txatbase.hxx
@@ -71,7 +71,6 @@ protected:
     void SetDontMoveAttr( bool bFlag )      { m_bDontMoveAttr = bFlag; }
     void SetCharFormatAttr( bool bFlag )       { m_bCharFormatAttr = bFlag; }
     void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
-    void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
     void SetNesting(const bool bFlag)       { m_bNesting = bFlag; }
     void SetHasDummyChar(const bool bFlag)  { m_bHasDummyChar = bFlag; }
     void SetHasContent( const bool bFlag )  { m_bHasContent = bFlag; }
@@ -109,6 +108,7 @@ public:
     void SetFormatIgnoreEnd  (bool bFlag)   { m_bFormatIgnoreEnd   = bFlag; }
     bool HasContent() const                 { return m_bHasContent; }
     void SetLockExpandFlag(bool bFlag)      { m_bLockExpandFlag = bFlag; }
+    void SetDontExpandStartAttr(bool bFlag) { m_bDontExpandStart = bFlag; }
 
     inline const SfxPoolItem& GetAttr() const;
     inline       SfxPoolItem& GetAttr();
diff --git a/sw/source/core/txtnode/atrref.cxx 
b/sw/source/core/txtnode/atrref.cxx
index 70baf422388d..6230fe40b136 100644
--- a/sw/source/core/txtnode/atrref.cxx
+++ b/sw/source/core/txtnode/atrref.cxx
@@ -175,8 +175,10 @@ void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, 
SwWrtShell& rWrtSh, const OU
 
     bool oldLockValue = this->IsLockExpandFlag();
     bool oldDontExpandValue = this->DontExpand();
+    bool oldDontExpandStartAttr = this->IsDontExpandStartAttr();
     this->SetLockExpandFlag(false);
     this->SetDontExpand(false);
+    this->SetDontExpandStartAttr(false);
     if (rIDCO.InsertString(aMarkers, u"XY"_ustr))
     {
         SwPaM aPasteEnd(SwPosition(rTextNode, *this->End()));
@@ -207,6 +209,7 @@ void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, 
SwWrtShell& rWrtSh, const OU
     }
     this->SetDontExpand(oldDontExpandValue);
     this->SetLockExpandFlag(oldLockValue);
+    this->SetDontExpandStartAttr(oldDontExpandStartAttr);
 
 }
 
diff --git a/sw/source/uibase/fldui/fldmgr.cxx 
b/sw/source/uibase/fldui/fldmgr.cxx
index 75e7fc49fb68..a150cb86b498 100644
--- a/sw/source/uibase/fldui/fldmgr.cxx
+++ b/sw/source/uibase/fldui/fldmgr.cxx
@@ -1107,6 +1107,7 @@ bool SwFieldMgr::InsertField(
                         
pCurShell->GetRefMark(SwMarkName(rData.m_sPar1))->GetTextRefMark());
                     xTextRefMark->SetDontExpand(true);
                     xTextRefMark->SetLockExpandFlag(true);
+                    xTextRefMark->SetDontExpandStartAttr(true);
                 }
 
                 if (!bHadMark && !rRefmarkText.isEmpty())
diff --git a/sw/source/uibase/shells/basesh.cxx 
b/sw/source/uibase/shells/basesh.cxx
index d9a23dd52b8c..4a378a02d337 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -847,6 +847,7 @@ bool UpdateFieldContents(const SfxRequest& rReq, 
SwWrtShell& rWrtSh)
         {
             pTextRefMark->SetDontExpand(true);
             pTextRefMark->SetLockExpandFlag(true);
+            pTextRefMark->SetDontExpandStartAttr(true);
         }
 
         if (nFieldIndex >= aFields.getLength())
commit 6c3c9d3d94a4835943a852d9a94a2573acb4258d
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Mon Apr 28 16:26:05 2025 +0530
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri May 23 10:13:34 2025 +0200

    sw: introduce field parameter to avoid expanding field
    
    problem:
    in online when a reference mark field is inserted and you start
    typing after it, field always expanded.
    
    problem was detected when using zotero citations
    
    patch reverts some part of 58e5e3208a4257a8d9f2e28d8e2d304677aa6980
    
    Change-Id: Ia664b82dae7a2385d9d0a3cf16276bb3ef39e61c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184711
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185554
    Tested-by: Jenkins

diff --git a/sw/inc/txatbase.hxx b/sw/inc/txatbase.hxx
index 014b04c5739a..4fccc588d112 100644
--- a/sw/inc/txatbase.hxx
+++ b/sw/inc/txatbase.hxx
@@ -68,7 +68,6 @@ protected:
     SwTextAttr(const SfxPoolItemHolder& rAttr, sal_Int32 nStart );
     virtual ~SwTextAttr() COVERITY_NOEXCEPT_FALSE;
 
-    void SetLockExpandFlag( bool bFlag )    { m_bLockExpandFlag = bFlag; }
     void SetDontMoveAttr( bool bFlag )      { m_bDontMoveAttr = bFlag; }
     void SetCharFormatAttr( bool bFlag )       { m_bCharFormatAttr = bFlag; }
     void SetOverlapAllowedAttr( bool bFlag ){ m_bOverlapAllowedAttr = bFlag; }
@@ -109,6 +108,7 @@ public:
     void SetFormatIgnoreStart(bool bFlag)   { m_bFormatIgnoreStart = bFlag; }
     void SetFormatIgnoreEnd  (bool bFlag)   { m_bFormatIgnoreEnd   = bFlag; }
     bool HasContent() const                 { return m_bHasContent; }
+    void SetLockExpandFlag(bool bFlag)      { m_bLockExpandFlag = bFlag; }
 
     inline const SfxPoolItem& GetAttr() const;
     inline       SfxPoolItem& GetAttr();
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index 6e80a639c5ab..80b14c9af945 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -3030,7 +3030,7 @@ SfxVoidItem InsertEnvelope FN_ENVELOP
 ]
 
 SfxVoidItem InsertField FN_INSERT_FIELD
-(SfxUInt16Item Type FN_PARAM_FIELD_TYPE,SfxUInt16Item SubType 
FN_PARAM_FIELD_SUBTYPE,SfxStringItem Name FN_INSERT_FIELD,SfxStringItem Content 
FN_PARAM_FIELD_CONTENT,SfxUInt32Item Format FN_PARAM_FIELD_FORMAT,SfxStringItem 
Separator FN_PARAM_3, SfxStringItem TypeName FN_PARAM_4, SfxStringItem Wrapper 
FN_PARAM_5)
+(SfxUInt16Item Type FN_PARAM_FIELD_TYPE,SfxUInt16Item SubType 
FN_PARAM_FIELD_SUBTYPE,SfxStringItem Name FN_INSERT_FIELD,SfxStringItem Content 
FN_PARAM_FIELD_CONTENT,SfxUInt32Item Format FN_PARAM_FIELD_FORMAT,SfxStringItem 
Separator FN_PARAM_3, SfxStringItem TypeName FN_PARAM_4, SfxStringItem Wrapper 
FN_PARAM_5, SfxBoolItem NeverExpand FN_PARAM_6)
 [
     AutoUpdate = FALSE,
     FastCall = FALSE,
@@ -6808,7 +6808,7 @@ SfxVoidItem UpdateCurIndex FN_UPDATE_CUR_TOX
 ]
 
 SfxVoidItem UpdateFields FN_UPDATE_FIELDS
-(SfxStringItem TypeName FN_PARAM_1, SfxStringItem NamePrefix FN_PARAM_2, 
SfxUnoAnyItem Fields FN_PARAM_3)
+(SfxStringItem TypeName FN_PARAM_1, SfxStringItem NamePrefix FN_PARAM_2, 
SfxUnoAnyItem Fields FN_PARAM_3, SfxBoolItem NeverExpand FN_PARAM_6)
 [
     AutoUpdate = FALSE,
     FastCall = TRUE,
diff --git a/sw/source/core/txtnode/atrref.cxx 
b/sw/source/core/txtnode/atrref.cxx
index c617dffcab5c..70baf422388d 100644
--- a/sw/source/core/txtnode/atrref.cxx
+++ b/sw/source/core/txtnode/atrref.cxx
@@ -172,10 +172,11 @@ void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, 
SwWrtShell& rWrtSh, const OU
     const SwTextNode& rTextNode = this->GetTextNode();
     SwPaM aMarkers(SwPosition(rTextNode, *this->End()));
     IDocumentContentOperations& rIDCO = pDoc->getIDocumentContentOperations();
-  /* FIXME: see above re: expanding behavior
-   *this->SetLockExpandFlag(false);
-   *this->SetDontExpand(false);
-   */
+
+    bool oldLockValue = this->IsLockExpandFlag();
+    bool oldDontExpandValue = this->DontExpand();
+    this->SetLockExpandFlag(false);
+    this->SetDontExpand(false);
     if (rIDCO.InsertString(aMarkers, u"XY"_ustr))
     {
         SwPaM aPasteEnd(SwPosition(rTextNode, *this->End()));
@@ -204,11 +205,9 @@ void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, 
SwWrtShell& rWrtSh, const OU
         rIDCO.DeleteAndJoin(aStartMarker);
         rIDCO.DeleteAndJoin(aEndMarker);
     }
-    // Restore flags.
-  /* FIXME: see above re: expanding behavior
-   *this->SetDontExpand(true);
-   *this->SetLockExpandFlag(true);
-   */
+    this->SetDontExpand(oldDontExpandValue);
+    this->SetLockExpandFlag(oldLockValue);
+
 }
 
 
diff --git a/sw/source/uibase/fldui/fldmgr.cxx 
b/sw/source/uibase/fldui/fldmgr.cxx
index beb8cf522854..75e7fc49fb68 100644
--- a/sw/source/uibase/fldui/fldmgr.cxx
+++ b/sw/source/uibase/fldui/fldmgr.cxx
@@ -80,6 +80,7 @@
 #include <txtfld.hxx>
 #endif
 #include <translatehelper.hxx>
+#include <txtrfmrk.hxx>
 
 using namespace com::sun::star::uno;
 using namespace com::sun::star::container;
@@ -1100,6 +1101,13 @@ bool SwFieldMgr::InsertField(
                 }
 
                 pCurShell->SetAttrItem( SwFormatRefMark( 
SwMarkName(rData.m_sPar1) ) );
+                if (rData.m_bNeverExpand)
+                {
+                    SwTextRefMark* xTextRefMark = const_cast<SwTextRefMark*>(
+                        
pCurShell->GetRefMark(SwMarkName(rData.m_sPar1))->GetTextRefMark());
+                    xTextRefMark->SetDontExpand(true);
+                    xTextRefMark->SetLockExpandFlag(true);
+                }
 
                 if (!bHadMark && !rRefmarkText.isEmpty())
                 {
diff --git a/sw/source/uibase/inc/fldmgr.hxx b/sw/source/uibase/inc/fldmgr.hxx
index 6afddcafb4bf..dd327933b4b7 100644
--- a/sw/source/uibase/inc/fldmgr.hxx
+++ b/sw/source/uibase/inc/fldmgr.hxx
@@ -79,18 +79,23 @@ struct SwInsertField_Data
     /// Marks the PostIt field's annotation start/end if it differs from the 
cursor selection.
     std::optional<SwPaM> m_oAnnotationRange;
     std::optional<std::tuple<sal_uInt32, sal_uInt32, SwMarkName>> m_oParentId;
+    bool m_bNeverExpand;
 
     SwInsertField_Data(SwFieldTypesEnum nType, sal_uInt16 nSub, OUString 
aPar1, OUString aPar2,
-                    sal_uInt32 nFormatId, SwWrtShell* pShell = nullptr, 
sal_Unicode cSep = ' ', bool bIsAutoLanguage = true) :
-        m_nTypeId(nType),
-        m_nSubType(nSub),
-        m_sPar1(std::move(aPar1)),
-        m_sPar2(std::move(aPar2)),
-        m_nFormatId(nFormatId),
-        m_pSh(pShell),
-        m_cSeparator(cSep),
-        m_bIsAutomaticLanguage(bIsAutoLanguage),
-        m_pParent(nullptr) {}
+                       sal_uInt32 nFormatId, SwWrtShell* pShell = nullptr, 
sal_Unicode cSep = ' ',
+                       bool bIsAutoLanguage = true, bool bNeverExpand = false)
+        : m_nTypeId(nType)
+        , m_nSubType(nSub)
+        , m_sPar1(std::move(aPar1))
+        , m_sPar2(std::move(aPar2))
+        , m_nFormatId(nFormatId)
+        , m_pSh(pShell)
+        , m_cSeparator(cSep)
+        , m_bIsAutomaticLanguage(bIsAutoLanguage)
+        , m_pParent(nullptr)
+        , m_bNeverExpand(bNeverExpand)
+    {
+    }
 };
 
 class SW_DLLPUBLIC SwFieldMgr
diff --git a/sw/source/uibase/shells/basesh.cxx 
b/sw/source/uibase/shells/basesh.cxx
index 69b5e5190559..d9a23dd52b8c 100644
--- a/sw/source/uibase/shells/basesh.cxx
+++ b/sw/source/uibase/shells/basesh.cxx
@@ -807,6 +807,13 @@ bool UpdateFieldContents(const SfxRequest& rReq, 
SwWrtShell& rWrtSh)
     {
         return false;
     }
+
+    bool bNeverExpand = false;
+    const SfxBoolItem* pNeverExpand = rReq.GetArg<SfxBoolItem>(FN_PARAM_6);
+    if (pNeverExpand)
+    {
+        bNeverExpand = pNeverExpand->GetValue();
+    }
     uno::Sequence<beans::PropertyValues> aFields;
     pFields->GetValue() >>= aFields;
 
@@ -835,14 +842,22 @@ bool UpdateFieldContents(const SfxRequest& rReq, 
SwWrtShell& rWrtSh)
             continue;
         }
 
+        auto pTextRefMark = 
const_cast<SwTextRefMark*>(pRefMark->GetTextRefMark());
+        if (bNeverExpand)
+        {
+            pTextRefMark->SetDontExpand(true);
+            pTextRefMark->SetLockExpandFlag(true);
+        }
+
         if (nFieldIndex >= aFields.getLength())
         {
-            break;
+            // earlier we used to break here
+            // but now we need to set expand flags for each refmark
+            continue;
         }
         comphelper::SequenceAsHashMap aMap(aFields[nFieldIndex++]);
         pRefMark->GetRefName() = 
SwMarkName(aMap[u"Name"_ustr].get<OUString>());
 
-        auto pTextRefMark = 
const_cast<SwTextRefMark*>(pRefMark->GetTextRefMark());
         pTextRefMark->UpdateFieldContent(pDoc, rWrtSh, 
aMap[u"Content"_ustr].get<OUString>());
     }
 
diff --git a/sw/source/uibase/shells/textfld.cxx 
b/sw/source/uibase/shells/textfld.cxx
index 34b0f464a48a..2b6862d3a8f3 100644
--- a/sw/source/uibase/shells/textfld.cxx
+++ b/sw/source/uibase/shells/textfld.cxx
@@ -403,7 +403,14 @@ void SwTextShell::ExecField(SfxRequest &rReq)
                         GetShellPtr()->InsertFootnote(OUString(), 
/*bEndNote=*/true);
                     }
                 }
-                SwInsertField_Data aData(nType, nSubType, aPar1, aPar2, 
nFormat, GetShellPtr(), cSeparator );
+                bool bNeverExpand = false;
+                const SfxBoolItem* pNeverExpand = 
rReq.GetArg<SfxBoolItem>(FN_PARAM_6);
+                if (pNeverExpand)
+                {
+                    bNeverExpand = pNeverExpand->GetValue();
+                }
+                SwInsertField_Data aData(nType, nSubType, aPar1, aPar2, 
nFormat, GetShellPtr(),
+                                         cSeparator, true, bNeverExpand);
                 bRes = aFieldMgr.InsertField( aData );
             }
             else

Reply via email to