diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index 309791efeebd..39d678dad4d4 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -4277,7 +4277,9 @@ void SwUiWriterTest::testTdf105625() SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); uno::Reference xComponentContext(comphelper::getProcessComponentContext()); // Ensure correct initial setting - comphelper::ConfigurationHelper::writeDirectKey(xComponentContext, "org.openoffice.Office.Writer/", "Cursor/Option", "IgnoreProtectedArea", css::uno::Any(false), comphelper::EConfigurationModes::Standard); + comphelper::ConfigurationHelper::writeDirectKey(xComponentContext, + "org.openoffice.Office.Writer/", "Cursor/Option", "IgnoreProtectedArea", + css::uno::Any(false), comphelper::EConfigurationModes::Standard); // We should be able to edit at positions adjacent to fields. // Check if the start and the end of the 1st paragraph are not protected // (they are adjacent to FORMCHECKBOX) @@ -4291,6 +4293,14 @@ void SwUiWriterTest::testTdf105625() pWrtShell->SttPara(); pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); CPPUNIT_ASSERT_EQUAL(true, pWrtShell->HasReadonlySel()); + // Test deletion of whole field with single backspace + // Previously it only removed right boundary of FORMTEXT, or failed removal at all + const IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess(); + sal_Int32 nMarksBefore = pMarksAccess->getAllMarksCount(); + pWrtShell->EndPara(); + pWrtShell->DelLeft(); + sal_Int32 nMarksAfter = pMarksAccess->getAllMarksCount(); + CPPUNIT_ASSERT_EQUAL(nMarksBefore, nMarksAfter + 1); } CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx index 17362738422b..27edcce0822c 100644 --- a/sw/source/uibase/wrtsh/delete.cxx +++ b/sw/source/uibase/wrtsh/delete.cxx @@ -209,8 +209,19 @@ long SwWrtShell::DelLeft() } else { + // If we are just to the right to a fieldmark, then remove it completely + const SwPosition* aCurPos = GetCursor()->GetPoint(); + SwPosition aPrevChar(*aCurPos); + --aPrevChar.nContent; + sw::mark::IFieldmark* pFm = getIDocumentMarkAccess()->getFieldmarkFor(aPrevChar); + if (pFm && pFm->GetMarkEnd() == *aCurPos) + { + getIDocumentMarkAccess()->deleteMark(pFm); + return 1; + } + OpenMark(); - SwCursorShell::Left(1,CRSR_SKIP_CHARS); + SwCursorShell::Left(1, CRSR_SKIP_CHARS); } long nRet = Delete(); if( !nRet && bSwap ) @@ -329,10 +340,19 @@ long SwWrtShell::DelRight() // restore cursor SwCursorShell::Pop( false ); } + + // If we are just ahead of a fieldmark, then remove it completely + sw::mark::IFieldmark* pFm = GetCurrentFieldmark(); + if (pFm && pFm->GetMarkStart() == *GetCursor()->GetPoint()) + { + getIDocumentMarkAccess()->deleteMark(pFm); + nRet = 1; + break; + } } OpenMark(); - SwCursorShell::Right(1,CRSR_SKIP_CELLS); + SwCursorShell::Right(1, CRSR_SKIP_CELLS); nRet = Delete(); CloseMark( 0 != nRet ); break;