diff --git a/shell/plugins/clipboard/Clipboard.qml b/shell/plugins/clipboard/Clipboard.qml index d9f28dce..0b53c4c4 100644 --- a/shell/plugins/clipboard/Clipboard.qml +++ b/shell/plugins/clipboard/Clipboard.qml @@ -169,6 +169,14 @@ Item { resultList.positionViewAtIndex(selectedIndex, ListView.Contain) } + function selectAbsolute(index) { + if (displayModel.count === 0) return + root.disarmPointer() + root.cursorActive = true + root.selectedIndex = Math.max(0, Math.min(index, displayModel.count - 1)) + resultList.positionViewAtIndex(root.selectedIndex, ListView.Contain) + } + function setFilter(nextFilter) { root.filterText = nextFilter root.selectedIndex = 0 @@ -345,6 +353,12 @@ Item { } else if (event.key === Qt.Key_PageDown) { root.select(6) event.accepted = true + } else if (event.key === Qt.Key_Home) { + root.selectAbsolute(0) + event.accepted = true + } else if (event.key === Qt.Key_End) { + root.selectAbsolute(displayModel.count - 1) + event.accepted = true } else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { if (root.cursorActive && (event.modifiers & Qt.AltModifier)) root.openIndex(root.selectedIndex) else if (root.cursorActive && (event.modifiers & Qt.ShiftModifier)) root.copyIndex(root.selectedIndex) diff --git a/test/shell.d/clipboard-test.sh b/test/shell.d/clipboard-test.sh index bf8636be..edcb45c4 100644 --- a/test/shell.d/clipboard-test.sh +++ b/test/shell.d/clipboard-test.sh @@ -130,6 +130,18 @@ assert( /function select\(delta\)[\s\S]*root\.disarmPointer\(\)[\s\S]*selectedIndex =/.test(clipboardQml), 'clipboard keyboard navigation disarms pointer selection' ) +assert( + /function selectAbsolute\(index\)[\s\S]*root\.disarmPointer\(\)[\s\S]*root\.selectedIndex = Math\.max\(0, Math\.min\(index, displayModel\.count - 1\)\)/.test(clipboardQml), + 'clipboard absolute navigation disarms pointer selection' +) +assert( + /event\.key === Qt\.Key_Home[\s\S]*root\.selectAbsolute\(0\)[\s\S]*event\.accepted = true/.test(clipboardQml), + 'clipboard Home selects the first entry' +) +assert( + /event\.key === Qt\.Key_End[\s\S]*root\.selectAbsolute\(displayModel\.count - 1\)[\s\S]*event\.accepted = true/.test(clipboardQml), + 'clipboard End selects the last entry' +) assert( /PointerMoveGate\s*\{[\s\S]*id: pointerGate[\s\S]*referenceItem: card[\s\S]*\}/.test(clipboardQml), 'clipboard uses shared pointer movement gate in card coordinates'