Reduce useless setTypingState calls on lost focus

This commit is contained in:
miruka
2019-05-17 16:01:42 -04:00
parent 2e5b846695
commit de9140cdb2
2 changed files with 13 additions and 3 deletions

View File

@@ -31,13 +31,23 @@ HRectangle {
backgroundColor: "transparent"
area.focus: true
property bool textChangedSinceLostFocus: false
function setTyping(typing) {
Backend.clients.get(chatPage.userId)
.setTypingState(chatPage.roomId, typing)
}
onTextChanged: setTyping(Boolean(text))
area.onEditingFinished: setTyping(false) // when lost focus
onTextChanged: {
setTyping(Boolean(text))
textChangedSinceLostFocus = true
}
area.onEditingFinished: { // when lost focus
if (text && textChangedSinceLostFocus) {
setTyping(false)
textChangedSinceLostFocus = false
}
}
Keys.onReturnPressed: {
event.accepted = true