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 f72b866c9c and
c34fc4520d, 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>
This commit is contained in:
Mike Kaganski
2017-02-01 19:40:43 +03:00
parent 4ec3d8cede
commit af42aab836
2 changed files with 33 additions and 3 deletions

View File

@@ -4277,7 +4277,9 @@ void SwUiWriterTest::testTdf105625()
SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell(); SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext()); uno::Reference<uno::XComponentContext> xComponentContext(comphelper::getProcessComponentContext());
// Ensure correct initial setting // 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. // 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 // Check if the start and the end of the 1st paragraph are not protected
// (they are adjacent to FORMCHECKBOX) // (they are adjacent to FORMCHECKBOX)
@@ -4291,6 +4293,14 @@ void SwUiWriterTest::testTdf105625()
pWrtShell->SttPara(); pWrtShell->SttPara();
pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false); pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/true, 1, /*bBasicCall=*/false);
CPPUNIT_ASSERT_EQUAL(true, pWrtShell->HasReadonlySel()); 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); CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest);

View File

@@ -209,6 +209,17 @@ long SwWrtShell::DelLeft()
} }
else 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(); OpenMark();
SwCursorShell::Left(1, CRSR_SKIP_CHARS); SwCursorShell::Left(1, CRSR_SKIP_CHARS);
} }
@@ -329,6 +340,15 @@ long SwWrtShell::DelRight()
// restore cursor // restore cursor
SwCursorShell::Pop( false ); 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(); OpenMark();