From 4b437b8cb9130d4ae607cdf7debd92e9d6f9fed8 Mon Sep 17 00:00:00 2001 From: David Bailes Date: Sat, 29 Jun 2019 13:47:33 +0100 Subject: [PATCH] Bug 2146: Keyboard preferences: mouse can select wrong item Steps to reproduce: 1. Open preferences 2. Select the keyboard category 3. Scroll down the list by any amount 4. Select an item using the mouse. The list scrolls to the top and the wrong item is selected. The problem occurs because if the list of shortcuts is currently not the focus, then after a left mouse click, KeyView::OnSetFocus() is called, and setting the selection in that function interferes with the mouse selection. Fix: In KeyView::OnSetFocus(), if there has been a left down event, don't select anything. --- src/widgets/KeyView.cpp | 13 +++++++++++-- src/widgets/KeyView.h | 2 ++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/widgets/KeyView.cpp b/src/widgets/KeyView.cpp index d8afcefdc..4d2ddd253 100644 --- a/src/widgets/KeyView.cpp +++ b/src/widgets/KeyView.cpp @@ -1346,8 +1346,13 @@ KeyView::OnSetFocus(wxFocusEvent & event) { if (mLines.size() > 0) { - // if no selection, select first line, if there is one - SelectNode(LineToIndex(0)); + // If mThereHasBeenALeftDown is true, then there is mouse + // selection in progress, so don't select anything here + // as this interferes with the mouse selection. (Bug 2146) + if (!mThereHasBeenALeftDown) { + // if no selection, select first line + SelectNode(LineToIndex(0)); + } } else { @@ -1373,6 +1378,8 @@ KeyView::OnKillFocus(wxFocusEvent & event) { RefreshRow(GetSelection()); } + + mThereHasBeenALeftDown = false; } // @@ -1618,6 +1625,8 @@ KeyView::OnKeyDown(wxKeyEvent & event) void KeyView::OnLeftDown(wxMouseEvent & event) { + mThereHasBeenALeftDown = true; + // Only check if for tree view if (mViewType != ViewByTree) { diff --git a/src/widgets/KeyView.h b/src/widgets/KeyView.h index 939e8bcaa..4f0836891 100644 --- a/src/widgets/KeyView.h +++ b/src/widgets/KeyView.h @@ -164,6 +164,8 @@ private: int mCommandWidth; wxCoord mKeyWidth; + bool mThereHasBeenALeftDown{}; + #if wxUSE_ACCESSIBILITY KeyViewAx *mAx; #endif