summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Stahl <michael.stahl@allotropia.de>2022-06-10 18:25:05 +0200
committerThorsten Behrens <thorsten.behrens@allotropia.de>2022-06-21 23:41:51 +0200
commit88eedf2043759ff52be6887235bb8ced044d9d66 (patch)
treefa803656af09dd6f05dae7aa1fade305504c9879
parenttdf#139982 sw: preserve flys in Replace with redlining enabled (diff)
downloadcore-88eedf2043759ff52be6887235bb8ced044d9d66.tar.gz
core-88eedf2043759ff52be6887235bb8ced044d9d66.zip
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.stahl@allotropia.de> Reviewed-by: Michael Stahl <michael.stahl@allotropia.de> (cherry picked from commit d72bee64a97650507d042f17846b6fc427b8434c) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135839 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@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 <xiscofauli@libreoffice.org> (cherry picked from commit 4e8295638e68295d73b49ddb80e23c3509a49b3e) Change-Id: I8cf9459e5a7ec7754ce8fe323cd158c7e84a5c93 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136221 Tested-by: Michael Stahl <michael.stahl@allotropia.de> Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r--sw/qa/extras/uiwriter/data/tdf148868.odtbin0 -> 11112 bytes
-rw-r--r--sw/qa/extras/uiwriter/uiwriter.cxx19
-rw-r--r--sw/source/uibase/inc/wrtsh.hxx2
-rw-r--r--sw/source/uibase/wrtsh/delete.cxx4
-rw-r--r--sw/source/uibase/wrtsh/wrtsh1.cxx5
5 files changed, 25 insertions, 5 deletions
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
--- /dev/null
+++ b/sw/qa/extras/uiwriter/data/tdf148868.odt
Binary files 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 );