[Libreoffice-commits] core.git: Branch 'libreoffice-7-6' - sw/qa sw/source

2023-10-20 Thread Matti Tyrväinen (via logerrit)
 sw/qa/core/txtnode/txtnode.cxx|   79 +++---
 sw/source/core/txtnode/atrref.cxx |   20 ++---
 2 files changed, 55 insertions(+), 44 deletions(-)

New commits:
commit 01134e5742f362b0dced135fd49c2213001d15eb
Author: Matti Tyrväinen 
AuthorDate: Mon Oct 16 09:23:15 2023 -0700
Commit: Xisco Fauli 
CommitDate: Fri Oct 20 21:07:52 2023 +0200

Revert change to Reference Mark behavior to avoid regression

Hotfix for tdf#157287, unfixes tdf#81720.

Setting the DontExpand flag would solve tdf#81720, but
causes regression due to other code that depends on the
old behavior. This patch restores the old behavior
without reverting the UpdateFieldContent refactor included
in 146941; testDontExpandRefmark is commented out for now.

Change-Id: Ibaeacabec304473db63df9334e2fef46c6d9acc5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158059
Reviewed-by: Matti 
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 
(cherry picked from commit 58e5e3208a4257a8d9f2e28d8e2d304677aa6980)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/158164
Reviewed-by: Xisco Fauli 

diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx
index 4a4bf9901a2f..757d6c830247 100644
--- a/sw/qa/core/txtnode/txtnode.cxx
+++ b/sw/qa/core/txtnode/txtnode.cxx
@@ -247,44 +247,47 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, 
testSplitNodeSuperscriptCopy)
 CPPUNIT_ASSERT(!aSet.HasItem(RES_CHRATR_ESCAPEMENT));
 }
 
-CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testDontExpandRefmark)
-{
-// Given a document with a refmark:
-createSwDoc();
-
-uno::Sequence aArgs = {
-comphelper::makePropertyValue("TypeName", 
uno::Any(OUString("SetRef"))),
-comphelper::makePropertyValue(
-"Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} 
RNDpyJknp173F"))),
-comphelper::makePropertyValue("Content", uno::Any(OUString("foo"))),
-};
-dispatchCommand(mxComponent, ".uno:InsertField", aArgs);
-
-SwDoc* pDoc = getSwDoc();
-SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
-SwPosition& rCursor = *pWrtShell->GetCursor()->GetPoint();
-SwTextNode* pTextNode = rCursor.GetNode().GetTextNode();
-std::vector aAttrs
-= pTextNode->GetTextAttrsAt(rCursor.GetContentIndex(), 
RES_TXTATR_REFMARK);
-
-auto& rRefmark = const_cast(aAttrs[0]->GetRefMark());
-auto pTextRefMark = const_cast(rRefmark.GetTextRefMark());
-
-// When typing after the refmark...
-pWrtShell->SttEndDoc(/*bStt=*/true);
-pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 3, 
/*bBasicCall=*/false);
-pWrtShell->Insert(" bar");
-
-// and skipping back to insert a comma after the refmark
-pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 4, 
/*bBasicCall=*/false);
-pWrtShell->Insert(",");
-
-// Without the accompanying fix in place, this test would have failed with:
-// - Expected: 3
-// - Actual  : 4
-// i.e. the reference mark expanded
-CPPUNIT_ASSERT_EQUAL(3, static_cast(*pTextRefMark->End()));
-}
+/* FIXME: behavior change reverted due to regression;
+ * see sw/source/core/txtnode/atrref.cxx
+ *CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testDontExpandRefmark)
+ *{
+ *// Given a document with a refmark:
+ *createSwDoc();
+ *
+ *uno::Sequence aArgs = {
+ *comphelper::makePropertyValue("TypeName", 
uno::Any(OUString("SetRef"))),
+ *comphelper::makePropertyValue(
+ *"Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} 
RNDpyJknp173F"))),
+ *comphelper::makePropertyValue("Content", uno::Any(OUString("foo"))),
+ *};
+ *dispatchCommand(mxComponent, ".uno:InsertField", aArgs);
+ *
+ *SwDoc* pDoc = getSwDoc();
+ *SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+ *SwPosition& rCursor = *pWrtShell->GetCursor()->GetPoint();
+ *SwTextNode* pTextNode = rCursor.GetNode().GetTextNode();
+ *std::vector aAttrs
+ *= pTextNode->GetTextAttrsAt(rCursor.GetContentIndex(), 
RES_TXTATR_REFMARK);
+ *
+ *auto& rRefmark = const_cast(aAttrs[0]->GetRefMark());
+ *auto pTextRefMark = 
const_cast(rRefmark.GetTextRefMark());
+ *
+ *// When typing after the refmark...
+ *pWrtShell->SttEndDoc(true);
+ *pWrtShell->Right(SwCursorSkipMode::Chars, false, 3, false);
+ *pWrtShell->Insert(" bar");
+ *
+ *// and skipping back to insert a comma after the refmark
+ *pWrtShell->Left(SwCursorSkipMode::Chars, false, 4, false);
+ *pWrtShell->Insert(",");
+ *
+ *// Without the accompanying fix in place, this test would have failed 
with:
+ *// - Expected: 3
+ *// - Actual  : 4
+ *// i.e. the reference mark expanded
+ *CPPUNIT_ASSERT_EQUAL(3, static_cast(*pTextRefMark->End()));
+ *}
+ */
 
 CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testInsertDropDownContentControlTwice)
 {
diff --git a/sw/source/core/txtnode/atrref.cxx 

[Libreoffice-commits] core.git: sw/inc sw/qa sw/source

2023-05-19 Thread Matti Tyrväinen (via logerrit)
 sw/inc/txtrfmrk.hxx|3 +
 sw/qa/core/txtnode/txtnode.cxx |   41 ++
 sw/source/core/txtnode/atrref.cxx  |   52 +++
 sw/source/uibase/shells/basesh.cxx |   81 -
 4 files changed, 98 insertions(+), 79 deletions(-)

New commits:
commit 384a80fc56e75e3d1ee18ffc303db85490716829
Author: Matti Tyrväinen 
AuthorDate: Mon Feb 13 21:04:56 2023 +0200
Commit: Miklos Vajna 
CommitDate: Fri May 19 12:28:35 2023 +0200

tdf#81720 Don't expand Reference Marks

Make Reference Marks behave like nesting attributes such as
Hyperlinks. This is described as the ideal behavior in


Change-Id: I34ddfb3a6aa0147ba4bc281ebbb6342089b7bd08
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146941
Reviewed-by: Matti 
Tested-by: Jenkins
Reviewed-by: Miklos Vajna 

diff --git a/sw/inc/txtrfmrk.hxx b/sw/inc/txtrfmrk.hxx
index f73f8cf71019..c01387998392 100644
--- a/sw/inc/txtrfmrk.hxx
+++ b/sw/inc/txtrfmrk.hxx
@@ -21,6 +21,8 @@
 
 #include "txatbase.hxx"
 
+class SwDoc;
+class SwWrtShell;
 class SwTextNode;
 
 // Attribute for content-/position references in text.
@@ -37,6 +39,7 @@ public:
 
 virtual const sal_Int32* GetEnd() const override;   // SwTextAttr
 virtual void SetEnd(sal_Int32) override;   // SwTextAttr
+void UpdateFieldContent(SwDoc* pDoc, SwWrtShell& rWrtSh, OUString 
aContent);
 
 // get and set TextNode pointer
 inline const SwTextNode& GetTextNode() const;
diff --git a/sw/qa/core/txtnode/txtnode.cxx b/sw/qa/core/txtnode/txtnode.cxx
index f99cc3dd54dd..640df69ed211 100644
--- a/sw/qa/core/txtnode/txtnode.cxx
+++ b/sw/qa/core/txtnode/txtnode.cxx
@@ -11,6 +11,7 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -31,6 +32,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /// Covers sw/source/core/txtnode/ fixes.
 class SwCoreTxtnodeTest : public SwModelTestBase
@@ -219,6 +221,45 @@ CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, 
testSplitNodeSuperscriptCopy)
 CPPUNIT_ASSERT(!aSet.HasItem(RES_CHRATR_ESCAPEMENT));
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testDontExpandRefmark)
+{
+// Given a document with a refmark:
+createSwDoc();
+
+uno::Sequence aArgs = {
+comphelper::makePropertyValue("TypeName", 
uno::Any(OUString("SetRef"))),
+comphelper::makePropertyValue(
+"Name", uno::Any(OUString("ZOTERO_ITEM CSL_CITATION {} 
RNDpyJknp173F"))),
+comphelper::makePropertyValue("Content", uno::Any(OUString("foo"))),
+};
+dispatchCommand(mxComponent, ".uno:InsertField", aArgs);
+
+SwDoc* pDoc = getSwDoc();
+SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+SwPosition& rCursor = *pWrtShell->GetCursor()->GetPoint();
+SwTextNode* pTextNode = rCursor.GetNode().GetTextNode();
+std::vector aAttrs
+= pTextNode->GetTextAttrsAt(rCursor.GetContentIndex(), 
RES_TXTATR_REFMARK);
+
+auto& rRefmark = const_cast(aAttrs[0]->GetRefMark());
+auto pTextRefMark = const_cast(rRefmark.GetTextRefMark());
+
+// When typing after the refmark...
+pWrtShell->SttEndDoc(/*bStt=*/true);
+pWrtShell->Right(SwCursorSkipMode::Chars, /*bSelect=*/false, 3, 
/*bBasicCall=*/false);
+pWrtShell->Insert(" bar");
+
+// and skipping back to insert a comma after the refmark
+pWrtShell->Left(SwCursorSkipMode::Chars, /*bSelect=*/false, 4, 
/*bBasicCall=*/false);
+pWrtShell->Insert(",");
+
+// Without the accompanying fix in place, this test would have failed with:
+// - Expected: 3
+// - Actual  : 4
+// i.e. the reference mark expanded
+CPPUNIT_ASSERT_EQUAL(3, static_cast(*pTextRefMark->End()));
+}
+
 CPPUNIT_TEST_FIXTURE(SwCoreTxtnodeTest, testInsertDropDownContentControlTwice)
 {
 // Given an already selected dropdown content control:
diff --git a/sw/source/core/txtnode/atrref.cxx 
b/sw/source/core/txtnode/atrref.cxx
index b93b62e7433a..ffb4509aee70 100644
--- a/sw/source/core/txtnode/atrref.cxx
+++ b/sw/source/core/txtnode/atrref.cxx
@@ -32,6 +32,9 @@
 #include 
 #include 
 #include 
+#include 
+#include 
+#include 
 
 SwFormatRefMark::~SwFormatRefMark( )
 {
@@ -118,6 +121,8 @@ SwTextRefMark::SwTextRefMark( SwFormatRefMark& rAttr,
 }
 SetDontMoveAttr( true );
 SetOverlapAllowedAttr( true );
+SetDontExpand( true );  // like hyperlinks, reference markers shouldn't 
expand
+SetLockExpandFlag( true ); // protect the flag
 }
 
 SwTextRefMark::~SwTextRefMark()
@@ -153,6 +158,53 @@ void SwTextRefMark::SetEnd(sal_Int32 n)
 m_pHints->EndPosChanged();
 }
 
+void SwTextRefMark::UpdateFieldContent(SwDoc* pDoc, SwWrtShell& rWrtSh, 
OUString aContent)
+{
+if (!this->End())
+{
+return;
+}
+
+// Insert markers to remember where the paste positions are.
+const SwTextNode& rTextNode = this->GetTextNode();
+SwPaM