don't select contiguously with shift+click; enable multiple selection

https://github.com/ankitects/anki/issues/1011
This commit is contained in:
Damien Elmes 2021-02-09 09:33:03 +10:00
parent 7972fa6493
commit c91d21e18e

View file

@ -299,10 +299,9 @@ class SidebarTreeView(QTreeView):
self.setHeaderHidden(True)
self.setIndentation(15)
self.setAutoExpandDelay(600)
# this doesn't play nicely with shift+click to OR items - we may want
# to put it behind a 'multi-select' mode
# self.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
# pylint: disable=no-member
mode = QAbstractItemView.SelectionMode.ExtendedSelection # type: ignore
self.setSelectionMode(mode)
self.setDragDropMode(QAbstractItemView.InternalMove)
self.setDragDropOverwriteMode(False)
@ -397,6 +396,18 @@ class SidebarTreeView(QTreeView):
else:
super().keyPressEvent(event)
# don't extend selection when shift+clicking with mouse (conflicts
# with OR-ing). User can still shift+up/down to select contiguously.
def selectionCommand(
self, index: QModelIndex, event: QEvent = None
) -> QItemSelectionModel.SelectionFlags:
flags = super().selectionCommand(index, event)
mods = self.mw.app.keyboardModifiers()
if isinstance(event, QMouseEvent) and mods & Qt.ShiftModifier:
# pylint: disable=no-member
flags &= ~QItemSelectionModel.SelectionFlag.Current # type: ignore
return flags
###########
def handle_drag_drop(self, sources: List[SidebarItem], target: SidebarItem) -> bool: