Skip to content

Commit 56f63a0

Browse files
committed
fix(frontend): suppress stale hover
1 parent 45ecd50 commit 56f63a0

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

‎whatkevr/src/qml/components/MessageComposer.qml‎

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ Frame {
3737
property string suggestionMode: "emoji"
3838
readonly property bool suggestionsActive: suggestionBar.visible && root.suggestionResults.length > 0
3939

40+
// Hover may not steal the selection until the pointer really moves: the
41+
// HoverHandlers re-fire under a stationary cursor both when the bar appears
42+
// and on every results refresh (each keystroke resets suggestionIndex to 0),
43+
// which would silently override the keyboard selection.
44+
property bool suggestionHoverArmed: false
45+
property var suggestionHoverBasePos: undefined
46+
onSuggestionResultsChanged: {
47+
suggestionHoverArmed = false
48+
suggestionHoverBasePos = undefined
49+
}
50+
4051
// @-mention authoring. Members are cached per chat and filtered in-memory;
4152
// pendingMentions records the {jid, displayName} pairs inserted so submit can
4253
// rewrite each "@DisplayName" run to the on-wire "@<userpart>" + JID list.
@@ -524,6 +535,26 @@ Frame {
524535
border.width: 1
525536
border.color: Qt.alpha(Kirigami.Theme.textColor, 0.09)
526537

538+
HoverHandler {
539+
// Arms hover selection only once the pointer moves away from
540+
// where it sat when the bar (re)appeared: one pointChanged is
541+
// delivered on appearance without any actual mouse motion.
542+
onPointChanged: {
543+
if (root.suggestionHoverArmed) {
544+
return
545+
}
546+
const p = point.scenePosition
547+
if (root.suggestionHoverBasePos === undefined) {
548+
root.suggestionHoverBasePos = Qt.point(p.x, p.y)
549+
return
550+
}
551+
if (Math.abs(p.x - root.suggestionHoverBasePos.x) > 2
552+
|| Math.abs(p.y - root.suggestionHoverBasePos.y) > 2) {
553+
root.suggestionHoverArmed = true
554+
}
555+
}
556+
}
557+
527558
RowLayout {
528559
anchors.fill: parent
529560
anchors.margins: Kirigami.Units.smallSpacing / 2
@@ -606,7 +637,15 @@ Frame {
606637
}
607638

608639
HoverHandler {
609-
onHoveredChanged: if (hovered) root.suggestionIndex = suggestionCell.index
640+
onHoveredChanged: if (hovered && root.suggestionHoverArmed) root.suggestionIndex = suggestionCell.index
641+
// Arming happens mid-hover (hovered won't re-fire),
642+
// but the same motion delivers pointChanged here.
643+
onPointChanged: {
644+
if (hovered && root.suggestionHoverArmed
645+
&& root.suggestionIndex !== suggestionCell.index) {
646+
root.suggestionIndex = suggestionCell.index
647+
}
648+
}
610649
}
611650
}
612651
}

0 commit comments

Comments
 (0)