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,51 +379,6 @@ Item {
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: chatHorizontalPadding anchors.rightMargin: chatHorizontalPadding
height: (item !== null && typeof(item)!== 'undefined')? item.height: 0 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("<a href=", index)
if (index < 0) {
break
}
let startIndex = index
let endIndex = message.indexOf("</a>", index) + 4
if (endIndex < 0) {
index += 8 // "<a href="
continue
}
let addrIndex = message.indexOf("0x", index + 8)
if (addrIndex < 0) {
index += 8 // "<a href="
continue
}
let addrEndIndex = message.indexOf('"', addrIndex)
if (addrEndIndex < 0) {
index += 8 // "<a href="
continue
}
const mentionLink = message.substring(startIndex, endIndex)
const linkTag = message.substring(index, endIndex)
const linkText = linkTag.replace(/(<([^>]+)>)/ig,"").trim()
const atSymbol = linkText.startsWith("@") ? '' : '@'
const mentionTag = Constants.mentionSpanTag + atSymbol + linkText + '</span> '
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 { sourceComponent: Item {
id: editText id: editText
height: childrenRect.height height: childrenRect.height
@ -446,7 +401,6 @@ Item {
chatType: messageStore.getChatType() chatType: messageStore.getChatType()
isEdit: true isEdit: true
emojiPopup: root.emojiPopup emojiPopup: root.emojiPopup
textInput.text: editMessageLoader.sourceText
messageContextMenu: root.messageContextMenu messageContextMenu: root.messageContextMenu
onSendMessage: { onSendMessage: {
saveBtn.clicked(null) saveBtn.clicked(null)
@ -456,6 +410,47 @@ Item {
editText.suggestionsOpened = true editText.suggestionsOpened = true
} }
} }
Component.onCompleted: {
let mentionsMap = new Map()
let index = 0
while (true) {
index = message.indexOf("<a href=", index)
if (index < 0) {
break
}
let startIndex = index
let endIndex = message.indexOf("</a>", index) + 4
if (endIndex < 0) {
index += 8 // "<a href="
continue
}
let addrIndex = message.indexOf("0x", index + 8)
if (addrIndex < 0) {
index += 8 // "<a href="
continue
}
let addrEndIndex = message.indexOf('"', addrIndex)
if (addrEndIndex < 0) {
index += 8 // "<a href="
continue
}
const mentionLink = message.substring(startIndex, endIndex)
const linkTag = message.substring(index, endIndex)
const linkText = linkTag.replace(/(<([^>]+)>)/ig,"").trim()
const atSymbol = linkText.startsWith("@") ? '' : '@'
const mentionTag = Constants.mentionSpanTag + atSymbol + linkText + '</span> '
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 { StatusQControls.StatusFlatButton {