sw/inc/txatbase.hxx | 2 +- sw/sdi/swriter.sdi | 4 ++-- sw/source/core/txtnode/atrref.cxx | 19 +++++++++---------- sw/source/uibase/fldui/fldmgr.cxx | 8 ++++++++ sw/source/uibase/inc/fldmgr.hxx | 25 +++++++++++++++---------- sw/source/uibase/shells/basesh.cxx | 19 +++++++++++++++++-- sw/source/uibase/shells/textfld.cxx | 9 ++++++++- 7 files changed, 60 insertions(+), 26 deletions(-)
New commits: commit 28aa0c3d6aeddd1df2a41a1d718ecbb9624d6ac9 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 16 12:24:59 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/+/185350 diff --git a/sw/inc/txatbase.hxx b/sw/inc/txatbase.hxx index 00e2f9b51470..a3d8c22781fd 100644 --- a/sw/inc/txatbase.hxx +++ b/sw/inc/txatbase.hxx @@ -69,7 +69,6 @@ protected: SwTextAttr( SfxPoolItem& 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; } @@ -110,6 +109,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 45750265e8eb..ced2462620e2 100644 --- a/sw/sdi/swriter.sdi +++ b/sw/sdi/swriter.sdi @@ -3012,7 +3012,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, @@ -6777,7 +6777,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 1684e003309e..f8335b7db484 100644 --- a/sw/source/core/txtnode/atrref.cxx +++ b/sw/source/core/txtnode/atrref.cxx @@ -173,11 +173,12 @@ void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, SwWrtShell& rWrtSh, OUString 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); - */ - if (rIDCO.InsertString(aMarkers, "XY")) + + 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())); aPasteEnd.Move(fnMoveBackward, GoInContent); @@ -205,11 +206,9 @@ void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, SwWrtShell& rWrtSh, OUString 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 ec509c92cd0c..790298dbab00 100644 --- a/sw/source/uibase/fldui/fldmgr.cxx +++ b/sw/source/uibase/fldui/fldmgr.cxx @@ -76,6 +76,7 @@ #include <unotools/useroptions.hxx> #include <IDocumentContentOperations.hxx> #include <translatehelper.hxx> +#include <txtrfmrk.hxx> using namespace com::sun::star::uno; using namespace com::sun::star::container; @@ -1089,6 +1090,13 @@ bool SwFieldMgr::InsertField( } pCurShell->SetAttrItem( SwFormatRefMark( rData.m_sPar1 ) ); + if (rData.m_bNeverExpand) + { + SwTextRefMark* xTextRefMark = const_cast<SwTextRefMark*>( + pCurShell->GetRefMark(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 48d4500513c4..ad5ab436ec1f 100644 --- a/sw/source/uibase/inc/fldmgr.hxx +++ b/sw/source/uibase/inc/fldmgr.hxx @@ -83,18 +83,23 @@ struct SwInsertField_Data weld::Widget* m_pParent; // parent widget used for SwWrtShell::StartInputFieldDlg() /// Marks the PostIt field's annotation start/end if it differs from the cursor selection. std::optional<SwPaM> m_oAnnotationRange; + 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 06c753de2366..7c198d5409cb 100644 --- a/sw/source/uibase/shells/basesh.cxx +++ b/sw/source/uibase/shells/basesh.cxx @@ -797,6 +797,13 @@ bool UpdateFieldContents(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; @@ -829,16 +836,24 @@ bool UpdateFieldContents(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++]); auto aName = aMap["Name"].get<OUString>(); pRefMark->GetRefName() = aName; OUString aContent = aMap["Content"].get<OUString>(); - auto pTextRefMark = const_cast<SwTextRefMark*>(pRefMark->GetTextRefMark()); pTextRefMark->UpdateFieldContent(pDoc, rWrtSh, aContent); } diff --git a/sw/source/uibase/shells/textfld.cxx b/sw/source/uibase/shells/textfld.cxx index cc62255af63a..80fe9c13f02b 100644 --- a/sw/source/uibase/shells/textfld.cxx +++ b/sw/source/uibase/shells/textfld.cxx @@ -364,7 +364,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