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>
This commit is contained in:
parent
4ec3d8cede
commit
af42aab836
@ -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);
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user