Ignore stationary pointer hover in clipboard

This commit is contained in:
David Heinemeier Hansson
2026-06-29 11:44:31 -05:00
parent a0abb1e0d1
commit a3f8c494e3
2 changed files with 56 additions and 5 deletions
+33 -5
View File
@@ -14,6 +14,8 @@ Item {
property string filterText: ""
property int selectedIndex: 0
property bool cursorActive: false
property real lastPointerX: -1
property real lastPointerY: -1
property bool clearConfirmOpen: false
property var history: []
@@ -45,6 +47,7 @@ Item {
root.filterText = ""
root.selectedIndex = 0
root.cursorActive = true
root.disarmPointer()
root.rebuildDisplay()
Qt.callLater(function() { keyCatcher.forceActiveFocus() })
}
@@ -97,6 +100,7 @@ Item {
function cancelClearHistory() {
root.clearConfirmOpen = false
root.disarmPointer()
Qt.callLater(function() { keyCatcher.forceActiveFocus() })
}
@@ -105,6 +109,7 @@ Item {
root.saveHistory()
root.selectedIndex = 0
root.cursorActive = false
root.disarmPointer()
root.clearConfirmOpen = false
root.rebuildDisplay()
Qt.callLater(function() { keyCatcher.forceActiveFocus() })
@@ -124,6 +129,7 @@ Item {
root.selectedIndex = displayModel.count - 2
}
root.disarmPointer()
root.rebuildDisplay()
}
@@ -155,6 +161,7 @@ Item {
function select(delta) {
if (displayModel.count === 0) return
root.disarmPointer()
if (!cursorActive) {
cursorActive = true
selectedIndex = delta < 0 ? displayModel.count - 1 : 0
@@ -168,9 +175,30 @@ Item {
root.filterText = nextFilter
root.selectedIndex = 0
root.cursorActive = true
root.disarmPointer()
root.rebuildDisplay()
}
function disarmPointer() {
root.lastPointerX = -1
root.lastPointerY = -1
}
function pointerMovedInCard(item, mouse) {
var point = item.mapToItem(card, mouse.x, mouse.y)
var moved = root.lastPointerX >= 0
&& (Math.abs(point.x - root.lastPointerX) > 1 || Math.abs(point.y - root.lastPointerY) > 1)
root.lastPointerX = point.x
root.lastPointerY = point.y
return moved
}
function selectFromPointer(index, item, mouse) {
if (!root.pointerMovedInCard(item, mouse)) return
root.cursorActive = true
root.selectedIndex = index
}
function activateIndex(index) {
if (index < 0 || index >= displayModel.count) return
var row = displayModel.get(index)
@@ -406,6 +434,7 @@ Item {
boundsBehavior: Flickable.StopAtBounds
delegate: Rectangle {
id: row
required property int index
required property string entryType
required property string previewText
@@ -455,14 +484,13 @@ Item {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onContainsMouseChanged: if (containsMouse) {
root.cursorActive = true
root.selectedIndex = index
onPositionChanged: function(mouse) {
root.selectFromPointer(row.index, row, mouse)
}
onClicked: {
root.cursorActive = true
root.selectedIndex = index
root.activateIndex(index)
root.selectedIndex = row.index
root.activateIndex(row.index)
}
}
}
+23
View File
@@ -5,7 +5,9 @@ set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
run_node_test <<'JS'
const fs = require('fs')
const clipboard = requireFromRoot('shell/plugins/clipboard/ClipboardHistory.js')
const clipboardQml = fs.readFileSync(path.join(root, 'shell/plugins/clipboard/Clipboard.qml'), 'utf8')
assertDeepEqual(
clipboard.normalizeEntry('hello'),
@@ -123,6 +125,27 @@ assertDeepEqual(
assertDeepEqual(clipboard.displayRows(history, '', 0), [], 'clipboard display rows supports zero result limit')
assertDeepEqual(clipboard.addEntry(history, 'next', 0), [], 'clipboard addEntry supports zero history limit')
assert(
/function select\(delta\)[\s\S]*root\.disarmPointer\(\)[\s\S]*selectedIndex =/.test(clipboardQml),
'clipboard keyboard navigation disarms pointer selection'
)
assert(
/function pointerMovedInCard\(item, mouse\)[\s\S]*item\.mapToItem\(card, mouse\.x, mouse\.y\)/.test(clipboardQml),
'clipboard compares pointer movement in card coordinates'
)
assert(
/function selectFromPointer\(index, item, mouse\)[\s\S]*pointerMovedInCard\(item, mouse\)[\s\S]*root\.selectedIndex = index/.test(clipboardQml),
'clipboard only selects from pointer after real movement'
)
assert(
/onPositionChanged: function\(mouse\) \{\s*root\.selectFromPointer\(row\.index, row, mouse\)\s*\}/.test(clipboardQml),
'clipboard row hover routes through pointer movement gate'
)
assert(
!/onContainsMouseChanged:[\s\S]*root\.selectedIndex/.test(clipboardQml),
'clipboard does not select rows from containsMouse'
)
JS
TMPDIR=$(mktemp -d)