diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2017-02-01 19:40:43 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2017-02-01 22:24:35 +0000 |
commit | af42aab836626fdf7b29921dff5d344a8b0e47c6 (patch) | |
tree | 00c82df7f5b8dda97b669c40d28e5f89201c7a69 | |
parent | 4ec3d8cedebb83700e3254486d6d3a502584c9b1 (diff) |
tdf#105625: Allow Delete/Backspace to delete whole fieldmark
Previously, the fieldmarks couldn't be removed with backspace or
deletee when cursor was right/left to them.
After commits f72b866c9cf4f07fce6744fbf482c4c6488106e2 and
c34fc4520dfee4ca068f249ee0756dacaa7a60cf, deletion worked wrong
(it didn't delete the mark from mark manager; in case of text
field, it removed one field's boundary).
Now single backspace/delete properly removes the whole fieldmark,
replacing it with its contents if applicable.
Change-Id: Id26e6e4e40e274d9fd6f0224f3e2b4fe33c369b7
Reviewed-on: https://gerrit.libreoffice.org/33812
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 12 | ||||
-rw-r--r-- | sw/source/uibase/wrtsh/delete.cxx | 24 |
2 files changed, 33 insertions, 3 deletions
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<uno::XComponentContext> 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; |