Slightly clarify ExtendOrCreateCurrentBlock() code

Don't use long-lived non-const "block" reference, this makes it
difficult to see that it's never changed until the very end of the
function, when it's updated.

Compare "blockStart" with "block" itself instead of comparing it with
"newBlock" which is initially its copy but gets modified later (however
these modifications don't affect the comparisons involving it).

Add a comment explaining why are we doing what we do here.
This commit is contained in:
Vadim Zeitlin
2020-04-11 15:04:32 +02:00
parent 7d0b352485
commit f3ff89601f

View File

@@ -475,19 +475,23 @@ bool wxGridSelection::ExtendOrCreateCurrentBlock(const wxGridCellCoords& blockSt
return true;
}
wxGridBlockCoords& block = *m_selection.rbegin();
const wxGridBlockCoords& block = *m_selection.rbegin();
wxGridBlockCoords newBlock = block;
bool editBlock = false;
if ( blockEnd.GetRow() != -1 )
{
if ( newBlock.GetTopRow() == blockStart.GetRow() )
// If the new block starts at the same top row as the current one, the
// end block coordinates must correspond to the new bottom row -- and
// vice versa, if the new block starts at the bottom, its other end
// must correspond to the top.
if ( blockStart.GetRow() == block.GetTopRow() )
{
newBlock.SetBottomRow(blockEnd.GetRow());
editBlock = true;
}
else if ( newBlock.GetBottomRow() == blockStart.GetRow() )
else if ( blockStart.GetRow() == block.GetBottomRow() )
{
newBlock.SetTopRow(blockEnd.GetRow());
editBlock = true;
@@ -529,8 +533,8 @@ bool wxGridSelection::ExtendOrCreateCurrentBlock(const wxGridCellCoords& blockSt
}
}
// Edit the current block.
block = newBlock;
// Update the current block in place.
*m_selection.rbegin() = newBlock;
// Send Event.
wxGridRangeSelectEvent gridEvt(m_grid->GetId(),