diff options
| author | Felix Ernst <[email protected]> | 2024-05-18 22:18:14 +0000 |
|---|---|---|
| committer | Felix Ernst <[email protected]> | 2024-05-18 22:18:14 +0000 |
| commit | 122fee5625f0285ec4ebda79162c72390989eb2a (patch) | |
| tree | 151d7137aa4775de1c37509a751daeca492ff10f /src/kitemviews/kitemlistcontroller.cpp | |
| parent | dfac2e02c1fde267449a0738b7b96369e8bc0db3 (diff) | |
Avoid implicitly selecting items
Items should only be selected if the user wants to act on them.
However, previous to this commit we sometimes selected items even
when there is no reason to assume that the user would like to act
on them. Such selections are dangerous because they make it more
likely that the user manipulates items by accident which they
never even explicitly selected.
Example: The "Up" action is used to navigate to the parent folder.
This will implicitly select the folder one emerged from after
opening the parent folder, so just one accidental press of the
Delete key will lead to data loss if the press goes unnoticed. This
scenario would have been avoided if no folder had been selected
automatically.
The above example becomes even more dangerous if the user is acting
with elevated privileges.
The following implicit selections of items are being removed:
- Selecting items that are being activated
- Selecting folders one emerges from
Even though these items will no longer be selected after these
actions, they will still be marked as current.
The only downside I see is that our indication of which item is "current" is a lot weaker than the selection highlight, so it might be more difficult to spot which folder one has emerged from. However, this could be counter-acted with some other temporary indication if this really turns out to be a problem.
The only downside I see is that our indication of which item is
"current" is a lot weaker than the selection highlight, so it might be
more difficult to spot which folder one has emerged from. However, this
could be counter-acted with some other temporary indication if this
really turns out to be a problem.
BUG: 424723
Diffstat (limited to 'src/kitemviews/kitemlistcontroller.cpp')
| -rw-r--r-- | src/kitemviews/kitemlistcontroller.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/kitemviews/kitemlistcontroller.cpp b/src/kitemviews/kitemlistcontroller.cpp index b25c73843..392dc410e 100644 --- a/src/kitemviews/kitemlistcontroller.cpp +++ b/src/kitemviews/kitemlistcontroller.cpp @@ -723,6 +723,9 @@ bool KItemListController::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event, const bool emitItemActivated = index.has_value() && index.value() < m_model->count() && !m_view->isAboveExpansionToggle(index.value(), pos); if (emitItemActivated) { + if (!QApplication::keyboardModifiers()) { + m_selectionManager->clearSelection(); // The user does not want to manage/manipulate the item currently, only activate it. + } Q_EMIT itemActivated(index.value()); } return false; @@ -1661,10 +1664,14 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier // or we just keep going for double-click activation if (m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) || m_singleClickActivationEnforced) { if (!pressedItemAlreadySelected) { - // An unselected item was clicked directly while deselecting multiple other items so we select it. - m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Toggle); + // An unselected item was clicked directly while deselecting multiple other items so we mark it "current". m_selectionManager->setCurrentItem(m_pressedIndex.value()); m_selectionManager->beginAnchoredSelection(m_pressedIndex.value()); + if (!leftClick) { + // We select the item here because this press is not meant to directly activate the item. + // We do not want to select items unless the user wants to edit them. + m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Toggle); + } } return true; // event handled, don't create rubber band } @@ -1731,7 +1738,10 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier break; case SingleSelection: - m_selectionManager->setSelected(m_pressedIndex.value()); + if (!leftClick || shiftOrControlPressed + || (!m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) && !m_singleClickActivationEnforced)) { + m_selectionManager->setSelected(m_pressedIndex.value()); + } break; case MultiSelection: @@ -1752,7 +1762,10 @@ bool KItemListController::onPress(const QPointF &pos, const Qt::KeyboardModifier } } else if (!shiftPressed || !m_selectionManager->isAnchoredSelectionActive()) { // Select the pressed item and start a new anchored selection - m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Select); + if (!leftClick || shiftOrControlPressed + || (!m_view->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick) && !m_singleClickActivationEnforced)) { + m_selectionManager->setSelected(m_pressedIndex.value(), 1, KItemListSelectionManager::Select); + } m_selectionManager->beginAnchoredSelection(m_pressedIndex.value()); } break; |
