sw/qa/extras/uiwriter/uiwriter.cxx |   95 +++++++++++++++++++++++++++++++++++++
 sw/source/uibase/wrtsh/wrtsh1.cxx  |    7 --
 2 files changed, 95 insertions(+), 7 deletions(-)

New commits:
commit 5f31629d88207b5842eb3dafcbf6948d0d52bb24
Author:     Xisco Fauli <[email protected]>
AuthorDate: Wed Nov 4 17:30:07 2020 +0100
Commit:     Xisco Fauli <[email protected]>
CommitDate: Thu Nov 5 11:55:07 2020 +0100

    tdf#137532: do not reset attributes deleting selection
    
    Regression from 6abed0ea006f3616e40faf2ae782cf64f8ac2914
    
    While at it, extend unittest for tdf#79717 to test another
    regression from the same commit I found while testing the patch:
    type 'a', type bold 'b', select both characters, type 'c'
    -> it should be bold
    
    Change-Id: I5b0b8ce4bfdfb4d52051e25c366827d7b594bb1a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105316
    Tested-by: Mike Kaganski <[email protected]>
    Reviewed-by: Mike Kaganski <[email protected]>
    Signed-off-by: Xisco Fauli <[email protected]>
    
    this also includes commit
    
    tdf#79717: sw_uiwriter: Add unittest
    
    Change-Id: I866cbc057113003e5bbbd20e2e5812a1045b5133
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105300
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <[email protected]>
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105329
    Reviewed-by: Michael Stahl <[email protected]>

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx 
b/sw/qa/extras/uiwriter/uiwriter.cxx
index 0529ef6e4ab9..32788114c15f 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -209,6 +209,8 @@ public:
     void testCreatePortions();
     void testBookmarkUndo();
     void testFdo85876();
+    void testTdf79717();
+    void testTdf137532();
     void testFdo87448();
     void testTextCursorInvalidation();
     void testTdf68183();
@@ -430,6 +432,8 @@ public:
     CPPUNIT_TEST(testCreatePortions);
     CPPUNIT_TEST(testBookmarkUndo);
     CPPUNIT_TEST(testFdo85876);
+    CPPUNIT_TEST(testTdf79717);
+    CPPUNIT_TEST(testTdf137532);
     CPPUNIT_TEST(testFdo87448);
     CPPUNIT_TEST(testTextCursorInvalidation);
     CPPUNIT_TEST(testTdf68183);
@@ -1976,6 +1980,97 @@ void SwUiWriterTest::testFdo85876()
     }
 }
 
+void SwUiWriterTest::testTdf79717()
+{
+    SwDoc* const pDoc = createDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Insert("normal");
+    lcl_setWeight(pWrtShell, WEIGHT_BOLD);
+    pWrtShell->Insert("bold");
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+    // Select 'bol' and replace it
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 3, 
/*bBasicCall=*/false);
+    pWrtShell->Insert("bol");
+
+    // Without the fix in place, 'bol' would have been replaced with normal 
font weight
+
+    auto xText = getParagraph(1)->getText();
+    CPPUNIT_ASSERT(xText.is());
+    {
+        auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 
1)));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("normal"), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, 
getProperty<float>(xCursor, "CharWeight"));
+    }
+    {
+        auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 
2)));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("bold"), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, 
getProperty<float>(xCursor, "CharWeight"));
+    }
+
+    // Now select characters from both runs and replace them
+    pWrtShell->EndPara();
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 5, 
/*bBasicCall=*/false);
+    pWrtShell->Insert("new");
+    {
+        auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 
1)));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("norma"), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, 
getProperty<float>(xCursor, "CharWeight"));
+    }
+    {
+        auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 
2)));
+        CPPUNIT_ASSERT(xCursor.is());
+        CPPUNIT_ASSERT_EQUAL(OUString("new"), xCursor->getString());
+        CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, 
getProperty<float>(xCursor, "CharWeight"));
+    }
+}
+
+void SwUiWriterTest::testTdf137532()
+{
+    SwDoc* const pDoc = createDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Insert("test");
+
+    //Select the word and change it to bold
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 4, 
/*bBasicCall=*/false);
+    lcl_setWeight(pWrtShell, WEIGHT_BOLD);
+
+    // Select first character and replace it
+    pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+    pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, 
/*bBasicCall=*/false);
+    pWrtShell->Insert("x");
+
+    auto xText = getParagraph(1)->getText();
+    CPPUNIT_ASSERT(xText.is());
+    auto xCursor(xText->createTextCursorByRange(getRun(getParagraph(1), 1)));
+
+    CPPUNIT_ASSERT(xCursor.is());
+    CPPUNIT_ASSERT_EQUAL(OUString("xest"), xCursor->getString());
+    CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, getProperty<float>(xCursor, 
"CharWeight"));
+
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+    Scheduler::ProcessEventsToIdle();
+
+    xCursor.set(xText->createTextCursorByRange(getRun(getParagraph(1), 1)));
+    CPPUNIT_ASSERT(xCursor.is());
+    CPPUNIT_ASSERT_EQUAL(OUString("test"), xCursor->getString());
+
+    // Without the fix in place, this test would have failed in
+    // - Expected: 150
+    // - Actual  : 100
+    CPPUNIT_ASSERT_EQUAL(awt::FontWeight::BOLD, getProperty<float>(xCursor, 
"CharWeight"));
+
+    dispatchCommand(mxComponent, ".uno:Undo", {});
+    Scheduler::ProcessEventsToIdle();
+
+    xCursor.set(xText->createTextCursorByRange(getRun(getParagraph(1), 1)));
+    CPPUNIT_ASSERT(xCursor.is());
+    CPPUNIT_ASSERT_EQUAL(OUString("test"), xCursor->getString());
+    CPPUNIT_ASSERT_EQUAL(awt::FontWeight::NORMAL, getProperty<float>(xCursor, 
"CharWeight"));
+}
+
 void SwUiWriterTest::testFdo87448()
 {
     createDoc("fdo87448.odt");
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx 
b/sw/source/uibase/wrtsh/wrtsh1.cxx
index da49506b45f4..44e7391ba207 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -242,13 +242,6 @@ void SwWrtShell::Insert( const OUString &rStr )
         SwPaM aPaM(pEnd->nNode.GetNode(), pEnd->nContent.GetIndex() - 
rStr.getLength(),
                    pEnd->nNode.GetNode(), pEnd->nContent.GetIndex());
 
-        std::set<sal_uInt16> aAttribs;
-        for (sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; ++i)
-            if (i != sal_uInt16(RES_CHRATR_RSID))
-                aAttribs.insert(aAttribs.end(), i);
-        aAttribs.insert(aAttribs.end(), RES_TXTATR_CHARFMT);
-        ResetAttr(aAttribs, &aPaM);
-
         SetAttrSet(aCharAttrSet, SetAttrMode::DEFAULT, &aPaM);
     }
 
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to