sw/qa/extras/uiwriter/data/tdf148868.odt |binary sw/qa/extras/uiwriter/uiwriter.cxx | 19 +++++++++++++++++++ sw/source/uibase/inc/wrtsh.hxx | 2 +- sw/source/uibase/wrtsh/delete.cxx | 4 ++-- sw/source/uibase/wrtsh/wrtsh1.cxx | 5 +++-- 5 files changed, 25 insertions(+), 5 deletions(-)
New commits: commit 88eedf2043759ff52be6887235bb8ced044d9d66 Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Fri Jun 10 18:25:05 2022 +0200 Commit: Thorsten Behrens <thorsten.behr...@allotropia.de> CommitDate: Tue Jun 21 23:41:51 2022 +0200 tdf#148868 sw: handle selection then Insert similar to Replace ... if the selection is inside one paragraph, to avoid deleting flys anchored in the selection. From a code point of view it's a bit inconsistent to do this, but from user point of view there are some ways to conveniently create a selection such as by double clicking a word. (see also tdf#133957) Also in SwWrtShell::AutoCorrect(), which oddly enough might get called with a selection from textsh*.cxx, at least in theory. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135606 Tested-by: Michael Stahl <michael.st...@allotropia.de> Reviewed-by: Michael Stahl <michael.st...@allotropia.de> (cherry picked from commit d72bee64a97650507d042f17846b6fc427b8434c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135839 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> (cherry picked from commit 67eec140556edb42280def88e987448aaa221c5e) tdf#148868: sw_uiwriter3: Add unittest Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135827 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> (cherry picked from commit 4e8295638e68295d73b49ddb80e23c3509a49b3e) Change-Id: I8cf9459e5a7ec7754ce8fe323cd158c7e84a5c93 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136221 Tested-by: Michael Stahl <michael.st...@allotropia.de> Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/qa/extras/uiwriter/data/tdf148868.odt b/sw/qa/extras/uiwriter/data/tdf148868.odt new file mode 100644 index 000000000000..7ebf68a82ea3 Binary files /dev/null and b/sw/qa/extras/uiwriter/data/tdf148868.odt differ diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 5e99211ea450..007a597cf61c 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -7750,6 +7750,25 @@ void SwUiWriterTest::testTdf38394() CPPUNIT_ASSERT_EQUAL(sReplaced, static_cast<SwTextNode*>(pDoc->GetNodes()[nIndex])->GetText()); } +CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf148868) +{ + SwDoc* pDoc = createDoc("tdf148868.odt"); + SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); + + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); + + pWrtShell->EndPg(/*bSelect=*/false); + pWrtShell->Left(CRSR_SKIP_CHARS, /*bSelect=*/true, 5, /*bBasicCall=*/false); + pWrtShell->Insert("X"); + + // Without the fix in place, this test would have failed with + // - Expected: 1 + // - Actual : 0 + CPPUNIT_ASSERT_EQUAL(1, getShapes()); + CPPUNIT_ASSERT_EQUAL(1, getPages()); +} + CPPUNIT_TEST_FIXTURE(SwUiWriterTest, testTdf134021) { load(DATA_DIRECTORY, "tdf134021.docx"); diff --git a/sw/source/uibase/inc/wrtsh.hxx b/sw/source/uibase/inc/wrtsh.hxx index 049cb3d9ae5c..cf780df77cf0 100644 --- a/sw/source/uibase/inc/wrtsh.hxx +++ b/sw/source/uibase/inc/wrtsh.hxx @@ -279,7 +279,7 @@ typedef bool (SwWrtShell:: *FNSimpleMove)(); bool DelLeft(); // also deletes the frame or sets the cursor in the frame when bDelFrame == false - bool DelRight(); + bool DelRight(bool isReplaceHeuristic = false); void DelToEndOfPara(); void DelToStartOfPara(); bool DelToEndOfSentence(); diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx index 5358876d204d..bf165d4d66a2 100644 --- a/sw/source/uibase/wrtsh/delete.cxx +++ b/sw/source/uibase/wrtsh/delete.cxx @@ -282,7 +282,7 @@ bool SwWrtShell::DelLeft() return bRet; } -bool SwWrtShell::DelRight() +bool SwWrtShell::DelRight(bool const isReplaceHeuristic) { // Will be or'ed, if a tableselection exists; // will here be implemented on SelectionType::Table @@ -309,7 +309,7 @@ bool SwWrtShell::DelRight() { SwActContext aActContext(this); ResetCursorStack(); - Delete(false); + Delete(isReplaceHeuristic); UpdateAttr(); } if( IsBlockMode() ) diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx b/sw/source/uibase/wrtsh/wrtsh1.cxx index 0840ed3cd407..53e8ae7a2fbd 100644 --- a/sw/source/uibase/wrtsh/wrtsh1.cxx +++ b/sw/source/uibase/wrtsh/wrtsh1.cxx @@ -244,7 +244,8 @@ void SwWrtShell::Insert( const OUString &rStr ) StartUndo(SwUndoId::REPLACE, &aRewriter); bStarted = true; Push(); - bDeleted = DelRight(); + // let's interpret a selection within the same node as "replace" + bDeleted = DelRight(GetCursor()->GetPoint()->nNode == GetCursor()->GetMark()->nNode); Pop(SwCursorShell::PopMode::DeleteCurrent); // Restore selection (if tracking changes) NormalizePam(false); // tdf#127635 put point at the end of deletion ClearMark(); @@ -1667,7 +1668,7 @@ void SwWrtShell::AutoCorrect( SvxAutoCorrect& rACorr, sal_Unicode cChar ) StartUndo( SwUndoId::REPLACE, &aRewriter ); bStarted = true; - DelRight(); + DelRight(true); } SwEditShell::AutoCorrect( rACorr, IsInsMode(), cChar );