[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.3' - sw/qa sw/source

Mike Kaganski mike.kaganski at collabora.com
Wed Mar 29 15:54:04 UTC 2017


 sw/qa/extras/uiwriter/uiwriter.cxx |   12 +++++++++++-
 sw/source/uibase/wrtsh/delete.cxx  |   24 ++++++++++++++++++++++--
 2 files changed, 33 insertions(+), 3 deletions(-)

New commits:
commit 11c4e8cc28b91e7db7d22e2ab2c8864554291f45
Author: Mike Kaganski <mike.kaganski at collabora.com>
Date:   Wed Feb 1 19:40:43 2017 +0300

    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 at libreoffice.org>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>
    (cherry picked from commit af42aab836626fdf7b29921dff5d344a8b0e47c6)
    Reviewed-on: https://gerrit.libreoffice.org/35859
    Tested-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx
index f758d8a8f640..b60fe47ee9ee 100644
--- a/sw/qa/extras/uiwriter/uiwriter.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter.cxx
@@ -4159,7 +4159,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)
@@ -4173,6 +4175,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;


More information about the Libreoffice-commits mailing list