Somewhat better autocompletion.
This commit is contained in:
parent
d9e778fe0c
commit
98b99e49f2
|
@ -37,7 +37,6 @@ Menu {
|
||||||
text: "Reply"
|
text: "Reply"
|
||||||
|
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
roomPanelInput.clear()
|
|
||||||
roomPanelInput.isReply = true
|
roomPanelInput.isReply = true
|
||||||
roomPanelInput.replyUserID = model.author.id
|
roomPanelInput.replyUserID = model.author.id
|
||||||
roomPanelInput.replyEventID = model.eventId
|
roomPanelInput.replyEventID = model.eventId
|
||||||
|
|
|
@ -18,6 +18,10 @@ Rectangle {
|
||||||
property string replyEventID
|
property string replyEventID
|
||||||
property string replyContent
|
property string replyContent
|
||||||
|
|
||||||
|
property bool isAutoCompleting
|
||||||
|
property var autoCompleteModel
|
||||||
|
property int autoCompleteBeginPosition
|
||||||
|
property int autoCompleteEndPosition
|
||||||
|
|
||||||
color: MSettings.darkTheme ? "#303030" : "#fafafa"
|
color: MSettings.darkTheme ? "#303030" : "#fafafa"
|
||||||
|
|
||||||
|
@ -37,9 +41,13 @@ Rectangle {
|
||||||
|
|
||||||
id: userAutoComplete
|
id: userAutoComplete
|
||||||
|
|
||||||
|
visible: isAutoCompleting
|
||||||
|
|
||||||
contentItem: ListView {
|
contentItem: ListView {
|
||||||
id: userAutoCompleteListView
|
id: userAutoCompleteListView
|
||||||
|
|
||||||
|
model: autoCompleteModel
|
||||||
|
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
orientation: ListView.Horizontal
|
orientation: ListView.Horizontal
|
||||||
|
@ -176,10 +184,6 @@ Rectangle {
|
||||||
Keys.onReturnPressed: {
|
Keys.onReturnPressed: {
|
||||||
if (event.modifiers & Qt.ShiftModifier) {
|
if (event.modifiers & Qt.ShiftModifier) {
|
||||||
insert(cursorPosition, "\n")
|
insert(cursorPosition, "\n")
|
||||||
} else if (userAutoComplete.visible) {
|
|
||||||
remove(text.lastIndexOf(" ") + 1, text.length)
|
|
||||||
insert(cursorPosition, userAutoCompleteListView.currentItem.displayName + " ")
|
|
||||||
userAutoComplete.visible = false
|
|
||||||
} else {
|
} else {
|
||||||
postMessage(text)
|
postMessage(text)
|
||||||
text = ""
|
text = ""
|
||||||
|
@ -187,17 +191,21 @@ Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
Keys.onTabPressed: {
|
Keys.onTabPressed: {
|
||||||
if (userAutoComplete.visible) {
|
if (isAutoCompleting) {
|
||||||
if (userAutoCompleteListView.currentIndex + 1 == userAutoCompleteListView.count) userAutoCompleteListView.currentIndex = 0
|
if (userAutoCompleteListView.currentIndex + 1 == userAutoCompleteListView.count) userAutoCompleteListView.currentIndex = 0
|
||||||
else userAutoCompleteListView.currentIndex++
|
else userAutoCompleteListView.currentIndex++
|
||||||
} else {
|
} else {
|
||||||
var lastWord = text.substring(0, cursorPosition).split(" ").pop()
|
autoCompleteBeginPosition = text.substring(0, cursorPosition).lastIndexOf(" ") + 1
|
||||||
if (!lastWord) return
|
var autoCompletePrefix = text.substring(0, cursorPosition).split(" ").pop()
|
||||||
var model = currentRoom.getUsers(lastWord)
|
if (!autoCompletePrefix) return
|
||||||
if (model.length === 0) return
|
autoCompleteModel = currentRoom.getUsers(autoCompletePrefix)
|
||||||
userAutoCompleteListView.model = model
|
if (autoCompleteModel.length === 0) return
|
||||||
userAutoComplete.visible = true
|
isAutoCompleting = true
|
||||||
|
autoCompleteEndPosition = cursorPosition
|
||||||
}
|
}
|
||||||
|
remove(autoCompleteBeginPosition, autoCompleteEndPosition)
|
||||||
|
autoCompleteEndPosition = autoCompleteBeginPosition + userAutoCompleteListView.currentItem.displayName.length
|
||||||
|
insert(cursorPosition, userAutoCompleteListView.currentItem.displayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
|
@ -205,7 +213,7 @@ Rectangle {
|
||||||
repeatTimer.start()
|
repeatTimer.start()
|
||||||
currentRoom.cachedInput = text
|
currentRoom.cachedInput = text
|
||||||
|
|
||||||
if (userAutoComplete.visible) userAutoComplete.visible = false
|
if (cursorPosition < autoCompleteBeginPosition || cursorPosition > autoCompleteEndPosition) isAutoCompleting = false
|
||||||
}
|
}
|
||||||
|
|
||||||
function postMessage(text) {
|
function postMessage(text) {
|
||||||
|
|
Loading…
Reference in New Issue