From 9a328cc53ccae9a7d0c0770dd7072f18e66592b0 Mon Sep 17 00:00:00 2001 From: Kohei Yoshida Date: Fri, 2 Nov 2012 11:01:15 -0400 Subject: Fix incorrect shifting of cell notes upon cell insertion / deletion. Steps to reproduce: 1) Insert a comment at D5. 2) Move cursor to C4. 3) Right-click and select Insert. 4) Choose shift cells down. 5) The comment gets shifted down but it shouldn't. The same thing happens when deleting a cell and shifting content. Change-Id: I5a71845cca6abde6b7c940e152e155da26343cef Signed-off-by: Markus Mohrhard --- sc/source/core/data/table2.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'sc') diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index cd193c142009..afafa10457f8 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -176,6 +176,7 @@ void ScTable::InsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE for (SCCOL j=nStartCol; j<=nEndCol; j++) aCol[j].InsertRow( nStartRow, nSize ); + // Transfer those notes that will get shifted into another container. ScNotes aNotes(pDocument); ScNotes::iterator itr = maNotes.begin(); while( itr != maNotes.end() ) @@ -185,13 +186,14 @@ void ScTable::InsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE ScPostIt* pPostIt = itr->second; ++itr; - if (nRow >= nStartRow) + if (nStartRow <= nRow && nStartCol <= nCol && nCol <= nEndCol) { aNotes.insert(nCol, nRow + nSize, pPostIt); maNotes.ReleaseNote(nCol, nRow); } } + // Re-insert the shifted notes. itr = aNotes.begin(); while( itr != aNotes.end() ) { @@ -256,6 +258,7 @@ void ScTable::DeleteRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE } } + // Transfer those notes that will get shifted into another container. ScNotes aNotes(pDocument); ScNotes::iterator itr = maNotes.begin(); while( itr != maNotes.end() ) @@ -265,18 +268,21 @@ void ScTable::DeleteRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE ScPostIt* pPostIt = itr->second; ++itr; - if (nRow >= nStartRow) + if (nStartRow <= nRow && nStartCol <= nCol && nCol <= nEndCol) { if(nRow - nStartRow > static_cast(nSize)) { + // This note will get shifted. aNotes.insert(nCol, nRow - nSize, pPostIt); maNotes.ReleaseNote(nCol, nRow); } else + // Note is in the deleted area. Remove it. maNotes.erase(nCol, nRow); } } + // Re-insert the shifted notes. itr = aNotes.begin(); while( itr != aNotes.end() ) { -- cgit