fix(@chat): move cursor to the end when edit message

fixes #5546
This commit is contained in:
Anthony Laibe 2022-05-02 11:33:54 +02:00 committed by Anthony Laibe
parent a0bebeb78b
commit 12cb76699c
1 changed files with 41 additions and 46 deletions

View File

@ -379,13 +379,39 @@ Item {
anchors.right: parent.right
anchors.rightMargin: chatHorizontalPadding
height: (item !== null && typeof(item)!== 'undefined')? item.height: 0
property string sourceText
sourceComponent: Item {
id: editText
height: childrenRect.height
onActiveChanged: {
if (!active) {
return
property bool suggestionsOpened: false
Keys.onEscapePressed: {
if (!suggestionsOpened) {
cancelBtn.clicked()
}
suggestionsOpened = false
}
StatusChatInput {
id: editTextInput
store: root.store
usersStore: root.usersStore
chatInputPlaceholder: qsTrId("type-a-message-")
chatType: messageStore.getChatType()
isEdit: true
emojiPopup: root.emojiPopup
messageContextMenu: root.messageContextMenu
onSendMessage: {
saveBtn.clicked(null)
}
suggestions.onVisibleChanged: {
if (suggestions.visible) {
editText.suggestionsOpened = true
}
}
Component.onCompleted: {
let mentionsMap = new Map()
let index = 0
while (true) {
@ -418,43 +444,12 @@ Item {
index += linkTag.length
}
sourceText = message
var text = message
for (let [key, value] of mentionsMap) {
sourceText = sourceText.replace(new RegExp(key, 'g'), value)
}
}
sourceComponent: Item {
id: editText
height: childrenRect.height
property bool suggestionsOpened: false
Keys.onEscapePressed: {
if (!suggestionsOpened) {
cancelBtn.clicked()
}
suggestionsOpened = false
}
StatusChatInput {
id: editTextInput
store: root.store
usersStore: root.usersStore
chatInputPlaceholder: qsTrId("type-a-message-")
chatType: messageStore.getChatType()
isEdit: true
emojiPopup: root.emojiPopup
textInput.text: editMessageLoader.sourceText
messageContextMenu: root.messageContextMenu
onSendMessage: {
saveBtn.clicked(null)
}
suggestions.onVisibleChanged: {
if (suggestions.visible) {
editText.suggestionsOpened = true
text = text.replace(new RegExp(key, 'g'), value)
}
editTextInput.textInput.text = text
editTextInput.textInput.cursorPosition = editTextInput.textInput.length
}
}