[Libreoffice-commits] .: 2 commits - sw/source

Caolán McNamara caolan at kemper.freedesktop.org
Mon Jul 4 06:51:31 PDT 2011


 sw/source/ui/uiview/viewsrch.cxx |   67 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 59 insertions(+), 8 deletions(-)

New commits:
commit 68a014dbca8bbd25056f75ef551fb81a0dbfb1b7
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Mon Jul 4 14:45:50 2011 +0100

    drop apparent optimization to handle regexp's the same way

diff --git a/sw/source/ui/uiview/viewsrch.cxx b/sw/source/ui/uiview/viewsrch.cxx
index 2e56362..8865a5b 100644
--- a/sw/source/ui/uiview/viewsrch.cxx
+++ b/sw/source/ui/uiview/viewsrch.cxx
@@ -594,51 +594,41 @@ void SwView::Replace()
 
         if(pWrtShell->HasSelection())
         {
-            /* check that the selection has the same length as the required string */
-            if (pWrtShell->SwCrsrShell::GetSelTxt().Len() != pSrchItem->GetSearchString().Len() )
+            /* check that the selection match the search string*/
+            //save state
+            SwPosition aStartPos = (* pWrtShell->GetSwCrsr()->Start());
+            SwPosition aEndPos = (* pWrtShell->GetSwCrsr()->End());
+            sal_Bool   bHasSelection = pSrchItem->GetSelection();
+            sal_uInt16 nOldCmd = pSrchItem->GetCommand();
+
+            //set state for checking if current selection has a match
+            pSrchItem->SetCommand( SVX_SEARCHCMD_FIND );
+            pSrchItem->SetSelection(true);
+
+            //check if it matchs
+            SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
+            if( ! FUNC_Search(aOpts) )
             {
-                //it differs, therefore do not replace the selection
-                bReqReplace = false;
-                //next call to replace will find the next matching string
-            }
-            else
-            {
-                /* check that the selection match the search string*/
-                //save state
-                SwPosition aStartPos = (* pWrtShell->GetSwCrsr()->Start());
-                SwPosition aEndPos = (* pWrtShell->GetSwCrsr()->End());
-                sal_Bool   bHasSelection = pSrchItem->GetSelection();
-                sal_uInt16 nOldCmd = pSrchItem->GetCommand();
-
-                //set state for checking if current selection has a match
-                pSrchItem->SetCommand( SVX_SEARCHCMD_FIND );
-                pSrchItem->SetSelection(true);
-
-                //check if it matchs
-                SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
-                if( ! FUNC_Search(aOpts) )
-                {
 
-                    //no matching therefore should not replace selection
-                    // => remove selection
+                //no matching therefore should not replace selection
+                // => remove selection
 
-                    if(! pSrchItem->GetBackward() )
-                    {
-                        (* pWrtShell->GetSwCrsr()->Start()) = aStartPos;
-                        (* pWrtShell->GetSwCrsr()->End()) = aEndPos;
-                    }
-                    else
-                    {
-                        (* pWrtShell->GetSwCrsr()->Start()) = aEndPos;
-                        (* pWrtShell->GetSwCrsr()->End()) = aStartPos;
-                    }
-                    bReqReplace = false;
+                if(! pSrchItem->GetBackward() )
+                {
+                    (* pWrtShell->GetSwCrsr()->Start()) = aStartPos;
+                    (* pWrtShell->GetSwCrsr()->End()) = aEndPos;
                 }
-
-                //set back old search state
-                pSrchItem->SetCommand( nOldCmd );
-                pSrchItem->SetSelection(bHasSelection);
+                else
+                {
+                    (* pWrtShell->GetSwCrsr()->Start()) = aEndPos;
+                    (* pWrtShell->GetSwCrsr()->End()) = aStartPos;
+                }
+                bReqReplace = false;
             }
+
+            //set back old search state
+            pSrchItem->SetCommand( nOldCmd );
+            pSrchItem->SetSelection(bHasSelection);
         }
         /*
          * remove current selection
commit fe29981d4a0400600ee9ee86f0d182121d6e3fad
Author: Dolives Benoit <benoit.dolives at gmail.com>
Date:   Mon Jul 4 14:44:58 2011 +0100

    writer: bug correction : selected text was always replaced (fdo#36181)

diff --git a/sw/source/ui/uiview/viewsrch.cxx b/sw/source/ui/uiview/viewsrch.cxx
index b3e8d6e..2e56362 100644
--- a/sw/source/ui/uiview/viewsrch.cxx
+++ b/sw/source/ui/uiview/viewsrch.cxx
@@ -589,17 +589,78 @@ void SwView::Replace()
     {
         if (GetPostItMgr()->HasActiveSidebarWin())
             GetPostItMgr()->Replace(pSrchItem);
-        sal_Bool bReplaced = pWrtShell->SwEditShell::Replace( pSrchItem->GetReplaceString(),
-                                            pSrchItem->GetRegExp());
 
-        if( bReplaced && pReplList && pReplList->Count() && pWrtShell->HasSelection() )
+        sal_Bool bReqReplace = true;
+
+        if(pWrtShell->HasSelection())
         {
-            SfxItemSet aReplSet( pWrtShell->GetAttrPool(),
-                                    aTxtFmtCollSetRange );
-            if( pReplList->Get( aReplSet ).Count() )
+            /* check that the selection has the same length as the required string */
+            if (pWrtShell->SwCrsrShell::GetSelTxt().Len() != pSrchItem->GetSearchString().Len() )
+            {
+                //it differs, therefore do not replace the selection
+                bReqReplace = false;
+                //next call to replace will find the next matching string
+            }
+            else
             {
-                ::SfxToSwPageDescAttr( *pWrtShell, aReplSet );
-                pWrtShell->SwEditShell::SetAttr( aReplSet );
+                /* check that the selection match the search string*/
+                //save state
+                SwPosition aStartPos = (* pWrtShell->GetSwCrsr()->Start());
+                SwPosition aEndPos = (* pWrtShell->GetSwCrsr()->End());
+                sal_Bool   bHasSelection = pSrchItem->GetSelection();
+                sal_uInt16 nOldCmd = pSrchItem->GetCommand();
+
+                //set state for checking if current selection has a match
+                pSrchItem->SetCommand( SVX_SEARCHCMD_FIND );
+                pSrchItem->SetSelection(true);
+
+                //check if it matchs
+                SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() );
+                if( ! FUNC_Search(aOpts) )
+                {
+
+                    //no matching therefore should not replace selection
+                    // => remove selection
+
+                    if(! pSrchItem->GetBackward() )
+                    {
+                        (* pWrtShell->GetSwCrsr()->Start()) = aStartPos;
+                        (* pWrtShell->GetSwCrsr()->End()) = aEndPos;
+                    }
+                    else
+                    {
+                        (* pWrtShell->GetSwCrsr()->Start()) = aEndPos;
+                        (* pWrtShell->GetSwCrsr()->End()) = aStartPos;
+                    }
+                    bReqReplace = false;
+                }
+
+                //set back old search state
+                pSrchItem->SetCommand( nOldCmd );
+                pSrchItem->SetSelection(bHasSelection);
+            }
+        }
+        /*
+         * remove current selection
+         * otherwise it is always replaced
+         * no matter if the search string exists or not in the selection
+         * Now the selection is removed and the next matching string is selected
+         */
+
+        if( bReqReplace )
+        {
+
+            sal_Bool bReplaced = pWrtShell->SwEditShell::Replace( pSrchItem->GetReplaceString(),
+                                                                  pSrchItem->GetRegExp());
+            if( bReplaced && pReplList && pReplList->Count() && pWrtShell->HasSelection() )
+            {
+                SfxItemSet aReplSet( pWrtShell->GetAttrPool(),
+                                     aTxtFmtCollSetRange );
+                if( pReplList->Get( aReplSet ).Count() )
+                {
+                    ::SfxToSwPageDescAttr( *pWrtShell, aReplSet );
+                    pWrtShell->SwEditShell::SetAttr( aReplSet );
+                }
             }
         }
     }


More information about the Libreoffice-commits mailing list