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