diff options
author | Michael Stahl <mstahl@redhat.com> | 2011-11-18 14:12:42 +0100 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2011-12-09 19:10:08 +0100 |
commit | 4eec19b1d634b66580423eb995621f87b422a46a (patch) | |
tree | 9555bcd7a0e5d87b58853f4a1023a83268e3b5d3 | |
parent | f4fb39640571fd588299ecd603733eaf94e61605 (diff) |
fdo#40831: SwView::ExecSearch:
Replace may delete nodes, so the current cursor position must be stored
in a way so that it is corrected when nodes are removed.
Signed-off-by: Michael Meeks <michael.meeks@suse.com>
-rw-r--r-- | sw/source/ui/uiview/viewsrch.cxx | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/sw/source/ui/uiview/viewsrch.cxx b/sw/source/ui/uiview/viewsrch.cxx index b3e8d6ea2e..cf4e14acb8 100644 --- a/sw/source/ui/uiview/viewsrch.cxx +++ b/sw/source/ui/uiview/viewsrch.cxx @@ -30,6 +30,9 @@ #include "precompiled_sw.hxx" #include <string> + +#include <boost/scoped_ptr.hpp> + #include <hintids.hxx> #include <com/sun/star/util/SearchOptions.hpp> #include <svl/cjkoptions.hxx> @@ -57,6 +60,8 @@ #include <uitool.hxx> #include <cmdid.h> #include <docsh.hxx> +#include <doc.hxx> +#include <unocrsr.hxx> #include <view.hrc> #include <SwRewriter.hxx> @@ -283,7 +288,14 @@ void SwView::ExecSearch(SfxRequest& rReq, sal_Bool bNoMessage) case SVX_SEARCHCMD_REPLACE_ALL: { SwSearchOptions aOpts( pWrtShell, pSrchItem->GetBackward() ); - SwCrsrSaveState aSaveCursor( *pWrtShell->GetSwCrsr()); + + // Fix for i#8288: "Replace all" should leave the cursor at the place it was + // before executing the command, rather than at the site of the final replacement. + // To do this take note of the current cursor position before replace all begins: + // note: must be stored so that it is corrected by PamCorr* + ::boost::scoped_ptr<SwUnoCrsr> const pTmpCursor( + pWrtShell->GetDoc()->CreateUnoCrsr( + *pWrtShell->GetSwCrsr()->GetPoint())); if( !pSrchItem->GetSelection() ) { @@ -304,7 +316,8 @@ void SwView::ExecSearch(SfxRequest& rReq, sal_Bool bNoMessage) pWrtShell->StartAllAction(); nFound = FUNC_Search( aOpts ); // #i8288# Now that everything has been replaced, restore the original cursor position. - pWrtShell->GetSwCrsr()->RestoreSavePos(); // (position saved by SwCrsrSaveState above) + *(pWrtShell->GetSwCrsr()->GetPoint()) = + *pTmpCursor->GetPoint(); pWrtShell->EndAllAction(); } |