fix: make sure the mention and emoji pickers close when pressing escape

This commit is contained in:
Jonathan Rainville 2020-11-18 12:14:29 -05:00
parent 89b45146fc
commit 537ae7991b
2 changed files with 23 additions and 7 deletions

View File

@ -35,13 +35,24 @@ Rectangle {
property int cursorPosition
signal itemSelected(var item, int lastAtPosition, int lastCursorPosition)
property alias listView: listView
property bool shouldHide: false
onCursorPositionChanged: {
if (shouldHide) {
shouldHide = false
}
}
function hide() {
shouldHide = true
}
function selectCurrentItem() {
container.itemSelected(listView.model.get(listView.currentIndex), filterItem.lastAtPosition, filterItem.cursorPosition)
}
z: parent.z + 100
visible: filter.length > 0 && suggestionsModel.count > 0
visible: !shouldHide && filter.length > 0 && suggestionsModel.count > 0
height: Math.min(400, listView.contentHeight + Style.current.smallPadding)
opacity: visible ? 1.0 : 0
@ -49,7 +60,7 @@ Rectangle {
NumberAnimation { }
}
color:Style.current.background
color: Style.current.background
radius: Style.current.radius
border.width: 0
layer.enabled: true

View File

@ -79,7 +79,7 @@ Rectangle {
return msg
}
function onEnter(event){
function onKeyPress(event){
if (event.modifiers === Qt.NoModifier && (event.key === Qt.Key_Enter || event.key === Qt.Key_Return)) {
if (emojiSuggestions.visible) {
emojiSuggestions.addEmoji();
@ -111,6 +111,9 @@ Rectangle {
suggestionsBox.listView.decrementCurrentIndex()
return emojiSuggestions.listView.decrementCurrentIndex()
}
if (event.key === Qt.Key_Escape) {
suggestionsBox.hide()
}
isColonPressed = (event.key === Qt.Key_Colon) && (event.modifiers & Qt.ShiftModifier);
}
@ -124,9 +127,11 @@ Rectangle {
interrogateMessage();
}
emojiEvent = emojiHandler(event);
if (!emojiEvent) {
emojiSuggestions.close()
if (event.key !== Qt.Key_Escape) {
emojiEvent = emojiHandler(event);
if (!emojiEvent) {
emojiSuggestions.close()
}
}
}
@ -579,7 +584,7 @@ Rectangle {
color: Style.current.textColor
topPadding: Style.current.smallPadding
bottomPadding: 12
Keys.onPressed: onEnter(event)
Keys.onPressed: onKeyPress(event)
Keys.onReleased: onRelease(event) // gives much more up to date cursorPosition
leftPadding: 0
background: Rectangle {