From 68ccc77e2041f9149a3e6e4c5b85b76aa7bccefa Mon Sep 17 00:00:00 2001 From: Ilya Sinitsyn Date: Tue, 28 Jan 2020 01:37:12 +0700 Subject: [PATCH] Fix wxGrid Home and End keys handling Take into account that rows and columns may be hidden and columns also can be reordered. --- src/generic/grid.cpp | 62 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 97a493056e..b48715d05d 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -5563,15 +5563,65 @@ void wxGrid::OnKeyDown( wxKeyEvent& event ) break; case WXK_HOME: - GoToCell(event.ControlDown() ? 0 - : m_currentCellCoords.GetRow(), - 0); + { + if ( m_currentCellCoords == wxGridNoCellCoords ) + break; + + int row = m_currentCellCoords.GetRow(); + if ( event.ControlDown() ) + { + row = 0; + + // Find visible row. + for ( ; row < m_numRows; ++row ) + { + if ( IsRowShown(row) ) + break; + } + } + + int col = 0; + // Find visible column. + for ( ; col < m_numCols; ++col ) + { + if ( IsColShown(GetColAt(col)) ) + break; + } + + ClearSelection(); + GoToCell(row, GetColAt(col)); + } break; case WXK_END: - GoToCell(event.ControlDown() ? m_numRows - 1 - : m_currentCellCoords.GetRow(), - m_numCols - 1); + { + if ( m_currentCellCoords == wxGridNoCellCoords ) + break; + + int row = m_currentCellCoords.GetRow(); + if ( event.ControlDown() ) + { + row = m_numRows - 1; + + // Find visible row. + for ( ; row >= 0; --row ) + { + if ( IsRowShown(row) ) + break; + } + } + + int col = m_numCols - 1; + // Find visible column. + for ( ; col >= 0; --col ) + { + if ( IsColShown(GetColAt(col)) ) + break; + } + + ClearSelection(); + GoToCell(row, GetColAt(col)); + } break; case WXK_PAGEUP: