From 12cb76699c6deac29bb021ed0875ae1359b1777e Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Mon, 2 May 2022 11:33:54 +0200 Subject: [PATCH] fix(@chat): move cursor to the end when edit message fixes #5546 --- .../shared/views/chat/CompactMessageView.qml | 87 +++++++++---------- 1 file changed, 41 insertions(+), 46 deletions(-) diff --git a/ui/imports/shared/views/chat/CompactMessageView.qml b/ui/imports/shared/views/chat/CompactMessageView.qml index 59520eaa34..68b7056668 100644 --- a/ui/imports/shared/views/chat/CompactMessageView.qml +++ b/ui/imports/shared/views/chat/CompactMessageView.qml @@ -379,51 +379,6 @@ Item { anchors.right: parent.right anchors.rightMargin: chatHorizontalPadding height: (item !== null && typeof(item)!== 'undefined')? item.height: 0 - property string sourceText - - onActiveChanged: { - if (!active) { - return - } - - let mentionsMap = new Map() - let index = 0 - while (true) { - index = message.indexOf("", index) + 4 - if (endIndex < 0) { - index += 8 // " ' - mentionsMap.set(mentionLink, mentionTag) - index += linkTag.length - } - - sourceText = message - for (let [key, value] of mentionsMap) { - sourceText = sourceText.replace(new RegExp(key, 'g'), value) - } - } - sourceComponent: Item { id: editText height: childrenRect.height @@ -446,7 +401,6 @@ Item { chatType: messageStore.getChatType() isEdit: true emojiPopup: root.emojiPopup - textInput.text: editMessageLoader.sourceText messageContextMenu: root.messageContextMenu onSendMessage: { saveBtn.clicked(null) @@ -456,6 +410,47 @@ Item { editText.suggestionsOpened = true } } + + Component.onCompleted: { + let mentionsMap = new Map() + let index = 0 + while (true) { + index = message.indexOf("", index) + 4 + if (endIndex < 0) { + index += 8 // " ' + mentionsMap.set(mentionLink, mentionTag) + index += linkTag.length + } + + var text = message + for (let [key, value] of mentionsMap) { + text = text.replace(new RegExp(key, 'g'), value) + } + editTextInput.textInput.text = text + editTextInput.textInput.cursorPosition = editTextInput.textInput.length + } } StatusQControls.StatusFlatButton {