Fix Shift-Ctrl-arrows handling
Extending the selection with Ctrl-arrows is different from all the other cases, as we need to combine both the selection anchor and the current cell coordinates when doing it. This means that we can't reuse the same PrepareForSelectionExpansion() helper for this case, so this function is not useful finally and this commit removes it entirely. It also replaces GetCurrentBlockCornerRow() and GetCurrentBlockCornerCol() functions with GetExtensionAnchor() which combines both of them. Finally, it adds wxGridDirectionOperations::TryToAdvance() helper to avoid repeating the IsAtBoundary() check which was previously part of PrepareForSelectionExpansion() in multiple places. And because the "extending" and normal parts of DoMoveCursorByBlock() are so different now, it also factors out AdvanceByBlock() helper which can be used to keep these parts well separate from each other instead of intermixing them together. With all these preparatory changes, it's finally possible to implement the "extending selection by block" logic relatively easily, with the bulk of this branch actually taken by comments explaining why do we have to do what we do. Add unit tests verifying that the functions used by Shift-Ctrl-arrow work as expected.
This commit is contained in:
@@ -2767,12 +2767,6 @@ private:
|
||||
wxGridWindow *gridWindow) const;
|
||||
int PosToEdgeOfLine(int pos, const wxGridOperations& oper) const;
|
||||
|
||||
// Fill the coords with the cell coordinates to use for the movement
|
||||
// extending the current selection. Return false if, for whatever reason,
|
||||
// we can't expand the selection at all.
|
||||
bool PrepareForSelectionExpansion(wxGridCellCoords& coords,
|
||||
const wxGridDirectionOperations& diroper);
|
||||
|
||||
void DoMoveCursorFromKeyboard(const wxKeyboardState& kbdState,
|
||||
const wxGridDirectionOperations& diroper);
|
||||
bool DoMoveCursor(const wxKeyboardState& kbdState,
|
||||
@@ -2782,6 +2776,8 @@ private:
|
||||
const wxGridDirectionOperations& diroper);
|
||||
void AdvanceToNextNonEmpty(wxGridCellCoords& coords,
|
||||
const wxGridDirectionOperations& diroper);
|
||||
bool AdvanceByBlock(wxGridCellCoords& coords,
|
||||
const wxGridDirectionOperations& diroper);
|
||||
|
||||
// common part of {Insert,Delete}{Rows,Cols}
|
||||
bool DoModifyLines(bool (wxGridTableBase::*funcModify)(size_t, size_t),
|
||||
|
@@ -86,12 +86,12 @@ public:
|
||||
const wxKeyboardState& kbd);
|
||||
|
||||
|
||||
// Return the row of the current selection block if it exists and we can
|
||||
// edit the block vertically. Otherwise return -1.
|
||||
int GetCurrentBlockCornerRow() const;
|
||||
// Return the column of the current selection block if it exists and we can
|
||||
// edit the block horizontally. Otherwise return -1.
|
||||
int GetCurrentBlockCornerCol() const;
|
||||
// Return the coordinates of the cell from which the selection should
|
||||
// continue to be extended. This is normally the opposite corner of the
|
||||
// last selected block from the current cell coordinates.
|
||||
//
|
||||
// If there is no selection, just returns the current cell coordinates.
|
||||
wxGridCellCoords GetExtensionAnchor() const;
|
||||
|
||||
wxGridCellCoordsArray GetCellSelection() const;
|
||||
wxGridCellCoordsArray GetBlockSelectionTopLeft() const;
|
||||
|
@@ -807,8 +807,23 @@ public:
|
||||
}
|
||||
|
||||
// Increment the component of this point in our direction
|
||||
//
|
||||
// Note that this can't be called if IsAtBoundary() is true, use
|
||||
// TryToAdvance() if this might be the case.
|
||||
virtual void Advance(wxGridCellCoords& coords) const = 0;
|
||||
|
||||
// Try to advance in our direction, return true if succeeded or false
|
||||
// otherwise, i.e. if the coordinates are already at the grid boundary.
|
||||
bool TryToAdvance(wxGridCellCoords& coords) const
|
||||
{
|
||||
if ( IsAtBoundary(coords) )
|
||||
return false;
|
||||
|
||||
Advance(coords);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Find the line at the given distance, in pixels, away from this one
|
||||
// (this uses clipping, i.e. anything after the last line is counted as the
|
||||
// last one and anything before the first one as 0)
|
||||
|
Reference in New Issue
Block a user