From 60ea887d5fc0dd4765e230dbd9ec3017f2604d08 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 4 Aug 2023 13:48:15 +0300 Subject: [PATCH] QmlDesigner: Improve keyboard navigation on assets view keyboard navigation now works when you focus the tab without requiring to also click on the treeview itself. Fixes: QDS-10397 Change-Id: I2cda08365c1a68c72121166d4fd50f1786f913bc Reviewed-by: Mahmoud Badri --- .../assetsLibraryQmlSources/Assets.qml | 1 + .../assetsLibraryQmlSources/AssetsView.qml | 43 +++++++------------ .../assetslibrary/assetslibrarywidget.cpp | 2 + 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/Assets.qml b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/Assets.qml index 211d3449a85..502b67f6c65 100644 --- a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/Assets.qml +++ b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/Assets.qml @@ -264,6 +264,7 @@ Item { contextMenu: contextMenu width: parent.width height: parent.height - assetsView.y + focus: true } } } diff --git a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsView.qml b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsView.qml index ede7f58cafb..e4380a19b39 100644 --- a/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsView.qml +++ b/share/qtcreator/qmldesigner/assetsLibraryQmlSources/AssetsView.qml @@ -348,22 +348,21 @@ TreeView { root.currentFilePath = filePath } - Keys.enabled: true - - Keys.onUpPressed: { - if (!root.currentFilePath) + function moveSelection(amount) + { + if (!assetsModel.haveFiles || !amount) return - let index = assetsModel.indexForPath(root.currentFilePath) + let index = root.currentFilePath ? assetsModel.indexForPath(root.currentFilePath) + : root.__modelIndex(root.firstRow) let row = root.rowAtIndex(index) let nextRow = row let nextIndex = index do { - if (nextRow <= root.firstRow) - return // don't select hidden rows - - nextRow-- + nextRow = nextRow + amount + if ((amount < 0 && nextRow < root.firstRow) || (amount > 0 && nextRow > root.lastRow)) + return nextIndex = root.__modelIndex(nextRow) } while (assetsModel.isDirectory(nextIndex)) @@ -371,26 +370,14 @@ TreeView { root.positionViewAtRow(nextRow, TableView.Contain) } + Keys.enabled: true + + Keys.onUpPressed: { + moveSelection(-1) + } + Keys.onDownPressed: { - if (!root.currentFilePath) - return - - let index = assetsModel.indexForPath(root.currentFilePath) - let row = root.rowAtIndex(index) - - let nextRow = row - let nextIndex = index - - do { - if (nextRow >= root.lastRow) - return // don't select hidden rows - - nextRow++ - nextIndex = root.__modelIndex(nextRow) - } while (assetsModel.isDirectory(nextIndex)) - - root.__selectRow(nextRow) - root.positionViewAtRow(nextRow, TableView.Contain) + moveSelection(1) } ConfirmDeleteFilesDialog { diff --git a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp index 9a8a611c664..48d10a34d20 100644 --- a/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp +++ b/src/plugins/qmldesigner/components/assetslibrary/assetslibrarywidget.cpp @@ -151,6 +151,8 @@ AssetsLibraryWidget::AssetsLibraryWidget(AsynchronousImageCache &asynchronousFon // init the first load of the QML UI elements reloadQmlSource(); + + setFocusProxy(m_assetsWidget->quickWidget()); } void AssetsLibraryWidget::contextHelp(const Core::IContext::HelpCallback &callback) const