From dcce505ebe1471f81803b9b336710b368e08f2e9 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Wed, 10 Apr 2013 17:59:40 +0200 Subject: fdo#51615: Further tweaks in the jumping to the next cell. Joren has improved this, but the behavior was unexpected when the user did not start in a cell that contained the string to replace. This commits changes it further that when the user hits Replace: * in a cell that does not contain the string to replace, it jumps to the cell that contains it, replaces the string, and stays there * in a cell that contains only one occurrence of the string to replace, it replaces it, and jumps to the next cell that contains such a string * in a cell that contains multiple occurrences, it replaces it, but does not move the cursor (so that the further occurences in that cell can still be replaced) This seems to be the most intuitive behavior. Change-Id: If6c10069b8dff933a035780732a7d7b6e0740383 --- sc/source/ui/view/viewfun2.cxx | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) (limited to 'sc/source/ui/view') diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 1e01df5fb262..a097ca64ff5e 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -61,6 +61,7 @@ #include "rangenam.hxx" #include "rangeutl.hxx" #include "refundo.hxx" +#include "table.hxx" #include "tablink.hxx" #include "tabvwsh.hxx" #include "uiitems.hxx" @@ -1575,13 +1576,16 @@ void ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem, if (bAddUndo && !pDoc->IsUndoEnabled()) bAddUndo = false; - SCCOL nCol = GetViewData()->GetCurX(); - SCROW nRow = GetViewData()->GetCurY(); - SCTAB nTab = GetViewData()->GetTabNo(); + SCCOL nCol, nOldCol; + SCROW nRow, nOldRow; + SCTAB nTab, nOldTab; + nCol = nOldCol = GetViewData()->GetCurX(); + nRow = nOldRow = GetViewData()->GetCurY(); + nTab = nOldTab = GetViewData()->GetTabNo(); + sal_uInt16 nCommand = pSearchItem->GetCommand(); bool bAllTables = pSearchItem->IsAllTables(); std::set aOldSelectedTables; - SCTAB nOldTab = nTab; SCTAB nLastTab = pDoc->GetTableCount() - 1; SCTAB nStartTab, nEndTab; if ( bAllTables ) @@ -1769,10 +1773,24 @@ void ScViewFunc::SearchAndReplace( const SvxSearchItem* pSearchItem, if ( nCommand == SVX_SEARCHCMD_REPLACE ) { pDocSh->PostPaint( nCol,nRow,nTab, nCol,nRow,nTab, PAINT_GRID ); - SvxSearchItem aSearchItem = ScGlobal::GetSearchItem(); - aSearchItem.SetCommand(SVX_SEARCHCMD_FIND); - aSearchItem.SetWhich(SID_SEARCH_ITEM); - GetViewData()->GetDispatcher().Execute( FID_SEARCH_NOW, SFX_CALLMODE_STANDARD, &aSearchItem, 0L ); + + // jump to next cell if we replaced everything in the cell + // where the cursor was positioned (but avoid switching tabs) + if ( nCol == nOldCol && nRow == nOldRow && nTab == nOldTab ) + { + SvxSearchItem aSearchItem = ScGlobal::GetSearchItem(); + aSearchItem.SetCommand(SVX_SEARCHCMD_FIND); + aSearchItem.SetWhich(SID_SEARCH_ITEM); + + ScRangeList aMatchedRanges; + ScTable::UpdateSearchItemAddressForReplace( aSearchItem, nCol, nRow ); + if ( pDoc->SearchAndReplace( aSearchItem, nCol, nRow, nTab, rMark, aMatchedRanges, aUndoStr, NULL ) && + ( nTab == nOldTab ) && + ( nCol != nOldCol || nRow != nOldRow ) ) + { + SetCursor( nCol, nRow, true ); + } + } } else pDocSh->PostPaintGridAll(); -- cgit