fix(StatusChatInput): infinite loop when pasting mention

This commit is contained in:
Michał Cieślak 2022-08-19 10:46:48 +02:00 committed by Michał
parent f45275bb1a
commit 7ef4a2d257
1 changed files with 16 additions and 13 deletions

View File

@ -430,14 +430,15 @@ Rectangle {
property string copiedTextPlain: "" property string copiedTextPlain: ""
property string copiedTextFormatted: "" property string copiedTextFormatted: ""
StatusListView { Instantiator {
id: dummyContactList id: dummyContactList
model: control.usersStore ? control.usersStore.usersModel : [] model: control.usersStore ? control.usersStore.usersModel : []
delegate: Item { delegate: QtObject {
property string contactName: model.name || "" property string contactName: model.displayName
} }
} }
function onRelease(event) { function onRelease(event) {
if (event.key === Qt.Key_Backspace && textFormatMenu.opened) { if (event.key === Qt.Key_Backspace && textFormatMenu.opened) {
textFormatMenu.close() textFormatMenu.close()
@ -447,25 +448,27 @@ Rectangle {
if (paste) { if (paste) {
if (copiedTextPlain.includes("@")) { if (copiedTextPlain.includes("@")) {
copiedTextFormatted = copiedTextFormatted.replace(/underline/g, "none").replace(/span style="/g, "span style=\" text-decoration:none;"); copiedTextFormatted = copiedTextFormatted.replace(/underline/g, "none").replace(/span style="/g, "span style=\" text-decoration:none;")
for (var j = 0; j < dummyContactList.count; j++) { for (let j = 0; j < dummyContactList.count; j++) {
var name = dummyContactList.itemAtIndex(j).contactName; const name = dummyContactList.objectAt(j).contactName
if (copiedTextPlain.indexOf(name) > -1) { if (copiedTextPlain.indexOf(name) > -1) {
var subStr = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); const subStr = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
var regex = new RegExp(subStr, 'gi'), result, indices = []; const regex = new RegExp(subStr, 'gi')
let result = null
while ((result = regex.exec(copiedTextPlain))) { while ((result = regex.exec(copiedTextPlain))) {
mentionsPos.push({"name": name, "leftIndex": (result.index + copyTextStart - 1), "rightIndex": (result.index + copyTextStart + name.length)}); mentionsPos.push({"name": name, "leftIndex": (result.index + copyTextStart - 1), "rightIndex": (result.index + copyTextStart + name.length)})
} }
} }
} }
} }
messageInputField.remove(copyTextStart, (copyTextStart + copiedTextPlain.length)); messageInputField.remove(copyTextStart, (copyTextStart + copiedTextPlain.length))
insertInTextInput(copyTextStart, copiedTextFormatted); insertInTextInput(copyTextStart, copiedTextFormatted)
paste = false; paste = false
} }
if (event.key !== Qt.Key_Escape) { if (event.key !== Qt.Key_Escape) {
emojiEvent = emojiHandler(event); emojiEvent = emojiHandler(event)
if (!emojiEvent) { if (!emojiEvent) {
emojiSuggestions.close() emojiSuggestions.close()
} }