From 3167657be687ac8d7bf42d0ecf98ce3d125d95d6 Mon Sep 17 00:00:00 2001 From: Quin Gillespie Date: Sat, 26 Sep 2026 07:07:17 -0600 Subject: [PATCH] Handle Cmd-Up and Cmd-Down in the generic wxListCtrl under Mac These keys should work as Home/End under Mac. Closes #27096. --- src/generic/listctrl.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/generic/listctrl.cpp b/src/generic/listctrl.cpp index 1074a9b48d..748c50ef7a 100644 --- a/src/generic/listctrl.cpp +++ b/src/generic/listctrl.cpp @@ -2971,8 +2971,9 @@ void wxListMainWindow::OnArrowChar(size_t newCurrent, const wxKeyEvent& event) { // all previously selected items are unselected unless ctrl is held in // a multi-selection control. in single selection mode we must always - // have a selected item. - if ( !event.ControlDown() || IsSingleSel() ) + // have a selected item. note that we use the real Ctrl key here and + // not Cmd under macOS, where Cmd-arrows have a different meaning. + if ( !event.RawControlDown() || IsSingleSel() ) { HighlightOnly(m_current, oldCurrent); @@ -3080,6 +3081,20 @@ void wxListMainWindow::OnChar( wxKeyEvent &event ) } int keyCode = event.GetKeyCode(); + +#ifdef __WXOSX__ + // Cmd-Up and Cmd-Down are the standard shortcuts for going to the first and + // the last item under macOS, where the keyboards often don't have Home and + // End keys at all, so handle them in the same way as those keys. + if ( event.CmdDown() && (keyCode == WXK_UP || keyCode == WXK_DOWN) ) + { + if ( !IsEmpty() ) + OnArrowChar(keyCode == WXK_UP ? 0 : GetItemCount() - 1, event); + + return; + } +#endif // __WXOSX__ + switch ( keyCode ) { case WXK_UP: