sw/qa/extras/uiwriter/uiwriter.cxx | 67 +++++++++++++++++++++++++++++++++++-- sw/source/uibase/wrtsh/wrtsh1.cxx | 7 --- 2 files changed, 65 insertions(+), 9 deletions(-)
New commits: commit 12eac5bcbc9b71bf00cb88b918988826229cca35 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Wed Nov 4 22:05:52 2020 +0100 Commit: Mike Kaganski <mike.kagan...@collabora.com> CommitDate: Thu Nov 5 06:55:34 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 <mike.kagan...@collabora.com> Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 49bbb7fe9eb7..2e23f46b3314 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -214,6 +214,7 @@ public: void testBookmarkUndo(); void testFdo85876(); void testTdf79717(); + void testTdf137532(); void testFdo87448(); void testTextCursorInvalidation(); void testTdf68183(); @@ -442,6 +443,7 @@ public: CPPUNIT_TEST(testBookmarkUndo); CPPUNIT_TEST(testFdo85876); CPPUNIT_TEST(testTdf79717); + CPPUNIT_TEST(testTdf137532); CPPUNIT_TEST(testFdo87448); CPPUNIT_TEST(testTextCursorInvalidation); CPPUNIT_TEST(testTdf68183); @@ -2020,11 +2022,11 @@ void SwUiWriterTest::testTdf79717() lcl_setWeight(pWrtShell, WEIGHT_BOLD); pWrtShell->Insert("bold"); pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, /*bBasicCall=*/false); - // Select 'bol' and rewrite it + // 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 rewritten with normal font weight + // Without the fix in place, 'bol' would have been replaced with normal font weight auto xText = getParagraph(1)->getText(); CPPUNIT_ASSERT(xText.is()); @@ -2040,6 +2042,67 @@ void SwUiWriterTest::testTdf79717() 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() diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index be6eb5cfb897..8251a9978142 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -245,13 +245,6 @@ void SwWrtShell::Insert( const OUString &rStr ) SwPaM aPaM(pEnd->nNode.GetNode(), pEnd->nContent.GetIndex() - rStr.getLength(), pEnd->nNode.GetNode(), pEnd->nContent.GetIndex()); - o3tl::sorted_vector<sal_uInt16> aAttribs; - for (sal_uInt16 i = RES_CHRATR_BEGIN; i < RES_CHRATR_END; ++i) - if (i != sal_uInt16(RES_CHRATR_RSID)) - aAttribs.insert(i); - aAttribs.insert(RES_TXTATR_CHARFMT); - ResetAttr(aAttribs, &aPaM); - SetAttrSet(aCharAttrSet, SetAttrMode::DEFAULT, &aPaM); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits