Use the same selection expansion logic for Shift-Ctrl-cursor
Expanding the selection from keyboard with Ctrl pressed should move in the same way Ctrl-cursor does, but use the same selection anchor as Shift-cursor does instead of always using the current cell. This makes the expansion work much more intuitively in the grid, e.g. pressing Shift-Ctrl-Down in 1 2 3 4 grid when 1 and 2 are selected now selects all the cells instead of selecting 1 and 3 as it did before.
This commit is contained in:
parent
fe6d07d2d1
commit
69a05b0340
@ -2767,6 +2767,12 @@ 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,
|
||||
|
@ -7914,6 +7914,29 @@ wxKeyboardState DummyKeyboardState(bool expandSelection)
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
bool
|
||||
wxGrid::PrepareForSelectionExpansion(wxGridCellCoords& coords,
|
||||
const wxGridDirectionOperations& diroper)
|
||||
{
|
||||
coords.SetRow(m_selection->GetCurrentBlockCornerRow());
|
||||
coords.SetCol(m_selection->GetCurrentBlockCornerCol());
|
||||
|
||||
if ( coords == wxGridNoCellCoords )
|
||||
coords = m_currentCellCoords;
|
||||
else if ( !diroper.IsValid(coords) )
|
||||
{
|
||||
// The component of the current block corner in our direction
|
||||
// is not valid. This means we can't change the selection block
|
||||
// in this direction.
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( diroper.IsAtBoundary(coords) )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
wxGrid::DoMoveCursorFromKeyboard(const wxKeyboardState& kbdState,
|
||||
const wxGridDirectionOperations& diroper)
|
||||
@ -7937,20 +7960,8 @@ wxGrid::DoMoveCursor(const wxKeyboardState& kbdState,
|
||||
if ( !m_selection )
|
||||
return false;
|
||||
|
||||
wxGridCellCoords coords(m_selection->GetCurrentBlockCornerRow(),
|
||||
m_selection->GetCurrentBlockCornerCol());
|
||||
|
||||
if ( coords == wxGridNoCellCoords )
|
||||
coords = m_currentCellCoords;
|
||||
else if ( !diroper.IsValid(coords) )
|
||||
{
|
||||
// The component of the current block corner in our direction
|
||||
// is not valid. This means we can't change the selection block
|
||||
// in this direction.
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( diroper.IsAtBoundary(coords) )
|
||||
wxGridCellCoords coords;
|
||||
if ( !PrepareForSelectionExpansion(coords, diroper) )
|
||||
return false;
|
||||
|
||||
diroper.Advance(coords);
|
||||
@ -8057,13 +8068,22 @@ bool
|
||||
wxGrid::DoMoveCursorByBlock(const wxKeyboardState& kbdState,
|
||||
const wxGridDirectionOperations& diroper)
|
||||
{
|
||||
if ( !m_table || m_currentCellCoords == wxGridNoCellCoords )
|
||||
if ( !m_table )
|
||||
return false;
|
||||
|
||||
if ( diroper.IsAtBoundary(m_currentCellCoords) )
|
||||
return false;
|
||||
wxGridCellCoords coords;
|
||||
|
||||
// Expand selection if Shift is pressed.
|
||||
if ( kbdState.ShiftDown() )
|
||||
{
|
||||
if ( !PrepareForSelectionExpansion(coords, diroper) )
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
coords = m_currentCellCoords;
|
||||
}
|
||||
|
||||
wxGridCellCoords coords(m_currentCellCoords);
|
||||
if ( m_table->IsEmpty(coords) )
|
||||
{
|
||||
// we are in an empty cell: find the next block of non-empty cells
|
||||
@ -8095,7 +8115,6 @@ wxGrid::DoMoveCursorByBlock(const wxKeyboardState& kbdState,
|
||||
|
||||
if ( kbdState.ShiftDown() )
|
||||
{
|
||||
// TODO: Select the next block every time (not the same as now).
|
||||
if ( m_selection )
|
||||
{
|
||||
if ( m_selection->ExtendOrCreateCurrentBlock(m_currentCellCoords,
|
||||
|
Loading…
Reference in New Issue
Block a user