diff options
author | Jan Holesovsky <kendy@suse.cz> | 2013-04-10 17:59:40 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2013-04-10 18:11:26 +0200 |
commit | dcce505ebe1471f81803b9b336710b368e08f2e9 (patch) | |
tree | 186f14d6fbd6fe1cbdaf5ab15a77231f949c6389 /sc | |
parent | 5b981e1dbfc1460e00bf35e0dd63e0c77a8119d9 (diff) |
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
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/table.hxx | 8 | ||||
-rw-r--r-- | sc/source/core/data/table6.cxx | 24 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 34 |
3 files changed, 49 insertions, 17 deletions
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 10785cf7bfdd..f238b432b777 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -820,6 +820,14 @@ public: ScRefCellValue GetRefCellValue( SCCOL nCol, SCROW nRow ); + /** Replace behaves differently to the Search; adjust the rCol and rRow accordingly. + + 'Replace' replaces at the 'current' position, but in order to achieve + that, we have to 'shift' the rCol / rRow to the 'previous' position - + what it is depends on various settings in rSearchItem. + */ + static void UpdateSearchItemAddressForReplace( const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow ); + private: void FillSeries( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, sal_uLong nFillCount, FillDir eFillDir, FillCmd eFillCmd, diff --git a/sc/source/core/data/table6.cxx b/sc/source/core/data/table6.cxx index 788c1509ac77..e9c916a64914 100644 --- a/sc/source/core/data/table6.cxx +++ b/sc/source/core/data/table6.cxx @@ -442,26 +442,32 @@ bool ScTable::SearchAll(const SvxSearchItem& rSearchItem, const ScMarkData& rMar return bEverFound; } -bool ScTable::Replace(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow, - const ScMarkData& rMark, OUString& rUndoStr, ScDocument* pUndoDoc) +void ScTable::UpdateSearchItemAddressForReplace( const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow ) { - bool bFound = false; - SCCOL nCol = rCol; - SCROW nRow = rRow; if (rSearchItem.GetBackward()) { if (rSearchItem.GetRowDirection()) - nCol += 1; + rCol += 1; else - nRow += 1; + rRow += 1; } else { if (rSearchItem.GetRowDirection()) - nCol -= 1; + rCol -= 1; else - nRow -= 1; + rRow -= 1; } +} + +bool ScTable::Replace(const SvxSearchItem& rSearchItem, SCCOL& rCol, SCROW& rRow, + const ScMarkData& rMark, OUString& rUndoStr, ScDocument* pUndoDoc) +{ + bool bFound = false; + SCCOL nCol = rCol; + SCROW nRow = rRow; + + UpdateSearchItemAddressForReplace( rSearchItem, nCol, nRow ); bFound = Search(rSearchItem, nCol, nRow, rMark, rUndoStr, pUndoDoc); if (bFound) { 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<SCTAB> 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(); |