Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library sidebar: focus selected item for all keypress events #11712

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/widget/wlibrarysidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ void WLibrarySidebar::keyPressEvent(QKeyEvent* event) {
// TODO(XXX) Should first keyEvent ensure previous item has focus? I.e. if the selected
// item is not focused, require second press to perform the desired action.

// make the selected item the navigation starting point
focusSelectedIndex();

switch (event->key()) {
case Qt::Key_Return:
focusSelectedIndex();
Expand All @@ -252,8 +255,6 @@ void WLibrarySidebar::keyPressEvent(QKeyEvent* event) {
case Qt::Key_PageUp:
case Qt::Key_End:
case Qt::Key_Home: {
// make the selected item the navigation starting point
focusSelectedIndex();
// Let the tree view move up and down for us.
QTreeView::keyPressEvent(event);
// After the selection changed force-activate (click) the newly selected
Expand All @@ -270,14 +271,9 @@ void WLibrarySidebar::keyPressEvent(QKeyEvent* event) {
return;
}
case Qt::Key_Left: {
QModelIndexList selectedIndices = selectionModel()->selectedRows();
if (selectedIndices.isEmpty()) {
return;
}
// If an expanded item is selected let QTreeView collapse it
QModelIndex selIndex = selectedIndex();
VERIFY_OR_DEBUG_ASSERT(selIndex.isValid()) {
qDebug() << "invalid sidebar index";
if (!selIndex.isValid()) {
return;
}
// collapse knot
Expand All @@ -300,8 +296,7 @@ void WLibrarySidebar::keyPressEvent(QKeyEvent* event) {
case kRenameSidebarItemShortcutKey: { // F2
// Rename crate or playlist (internal, external, history)
QModelIndex selIndex = selectedIndex();
VERIFY_OR_DEBUG_ASSERT(selIndex.isValid()) {
qDebug() << "invalid sidebar index";
if (!selIndex.isValid()) {
return;
}
if (isExpanded(selIndex)) {
Expand Down
Loading