Allow clicking autocomplete.

This commit is contained in:
Black Hat 2018-10-23 18:04:07 +08:00
parent 41107bc99b
commit 107f60d55b
1 changed files with 14 additions and 3 deletions

View File

@ -80,6 +80,11 @@ Rectangle {
}
text: modelData.displayName
onClicked: {
userAutoCompleteListView.currentIndex = index
inputField.replaceAutoComplete(displayName)
}
}
}
}
@ -203,9 +208,8 @@ Rectangle {
isAutoCompleting = true
autoCompleteEndPosition = cursorPosition
}
remove(autoCompleteBeginPosition, autoCompleteEndPosition)
autoCompleteEndPosition = autoCompleteBeginPosition + userAutoCompleteListView.currentItem.displayName.length
insert(cursorPosition, userAutoCompleteListView.currentItem.displayName)
replaceAutoComplete(userAutoCompleteListView.currentItem.displayName)
}
onTextChanged: {
@ -215,9 +219,16 @@ Rectangle {
if (cursorPosition !== autoCompleteBeginPosition && cursorPosition !== autoCompleteEndPosition) {
isAutoCompleting = false
userAutoCompleteListView.currentIndex = 0
}
}
function replaceAutoComplete(word) {
remove(autoCompleteBeginPosition, autoCompleteEndPosition)
autoCompleteEndPosition = autoCompleteBeginPosition + word.length
insert(cursorPosition, word)
}
function postMessage(text) {
if (text.trim().length === 0) { return }
if(!currentRoom) { return }