fix(@desktop/chat): adjust chat input logic to allow emojis
Fixes #7622
This commit is contained in:
parent
f40ef4613e
commit
c931f716e8
|
@ -151,6 +151,15 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sortMentions() {
|
||||||
|
if (mentionsPos.length < 2) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mentionsPos = mentionsPos.sort(function(a, b){
|
||||||
|
return a.leftIndex - b.leftIndex
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function updateMentionsPositions() {
|
function updateMentionsPositions() {
|
||||||
if (mentionsPos.length == 0) {
|
if (mentionsPos.length == 0) {
|
||||||
return
|
return
|
||||||
|
@ -167,10 +176,15 @@ Rectangle {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lastRightIndex = -1
|
||||||
for (var k = 0; k < mentionsPos.length; k++) {
|
for (var k = 0; k < mentionsPos.length; k++) {
|
||||||
const aliasIndex = unformattedText.indexOf(mentionsPos[k].name)
|
const aliasIndex = unformattedText.indexOf(mentionsPos[k].name, lastRightIndex)
|
||||||
|
if (aliasIndex === -1) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
lastRightIndex = aliasIndex + mentionsPos[k].name.length
|
||||||
|
|
||||||
if ((aliasIndex !== -1) && (aliasIndex - 1 !== mentionsPos[k].leftIndex)) {
|
if (aliasIndex - 1 !== mentionsPos[k].leftIndex) {
|
||||||
mentionsPos[k].leftIndex = aliasIndex - 1
|
mentionsPos[k].leftIndex = aliasIndex - 1
|
||||||
mentionsPos[k].rightIndex = aliasIndex + mentionsPos[k].name.length
|
mentionsPos[k].rightIndex = aliasIndex + mentionsPos[k].name.length
|
||||||
}
|
}
|
||||||
|
@ -240,6 +254,7 @@ Rectangle {
|
||||||
messageInputField.cursorPosition = messageInputField.length
|
messageInputField.cursorPosition = messageInputField.length
|
||||||
}
|
}
|
||||||
mentionsPos.push({name: aliasName, pubKey: publicKey, leftIndex: lastAtPosition, rightIndex: (lastAtPosition+aliasName.length + 1)});
|
mentionsPos.push({name: aliasName, pubKey: publicKey, leftIndex: lastAtPosition, rightIndex: (lastAtPosition+aliasName.length + 1)});
|
||||||
|
d.sortMentions()
|
||||||
}
|
}
|
||||||
|
|
||||||
function isUploadFilePressed(event) {
|
function isUploadFilePressed(event) {
|
||||||
|
@ -482,29 +497,15 @@ Rectangle {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTextWithPublicKeys() {
|
function getTextWithPublicKeys() {
|
||||||
let result = messageInputField.getText(0, messageInputField.length)
|
let result = messageInputField.text
|
||||||
|
|
||||||
if (mentionsPos.length > 0) {
|
if (mentionsPos.length > 0) {
|
||||||
let lastIndex = messageInputField.length
|
for (var k = 0; k < mentionsPos.length; k++) {
|
||||||
while (lastIndex > 0) {
|
let leftIndex = result.indexOf(mentionsPos[k].name)
|
||||||
|
let rightIndex = leftIndex + mentionsPos[k].name.length
|
||||||
let currentMax = -1
|
result = result.substring(0, leftIndex)
|
||||||
let maxIndex = -1
|
+ mentionsPos[k].pubKey
|
||||||
|
+ result.substring(rightIndex, result.length)
|
||||||
for (var i = 0; i < mentionsPos.length; i++) {
|
|
||||||
if (mentionsPos[i].rightIndex < lastIndex && mentionsPos[i].rightIndex > currentMax) {
|
|
||||||
currentMax = mentionsPos[i].rightIndex
|
|
||||||
maxIndex = i
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
lastIndex = 0
|
|
||||||
if (currentMax >= 0) {
|
|
||||||
result = result.substring(0, mentionsPos[maxIndex].leftIndex + 1)
|
|
||||||
+ mentionsPos[maxIndex].pubKey
|
|
||||||
+ result.substring(mentionsPos[maxIndex].rightIndex, result.length)
|
|
||||||
lastIndex = mentionsPos[maxIndex].leftIndex
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -608,6 +609,7 @@ Rectangle {
|
||||||
rightIndex: (result.index + d.copyTextStart + name.length)
|
rightIndex: (result.index + d.copyTextStart + name.length)
|
||||||
}
|
}
|
||||||
mentionsPos.push(mention)
|
mentionsPos.push(mention)
|
||||||
|
d.sortMentions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1120,6 +1122,7 @@ Rectangle {
|
||||||
&& (event.key === Qt.Key_Delete)) {
|
&& (event.key === Qt.Key_Delete)) {
|
||||||
messageInputField.remove(mentionsPos[i].rightIndex, mentionsPos[i].leftIndex)
|
messageInputField.remove(mentionsPos[i].rightIndex, mentionsPos[i].leftIndex)
|
||||||
mentionsPos.pop(i)
|
mentionsPos.pop(i)
|
||||||
|
d.sortMentions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1150,6 +1153,7 @@ Rectangle {
|
||||||
} else if ((keyEvent.key === Qt.Key_Backspace) || (keyEvent.key === Qt.Key_Delete)) {
|
} else if ((keyEvent.key === Qt.Key_Backspace) || (keyEvent.key === Qt.Key_Delete)) {
|
||||||
messageInputField.remove(mentionsPos[i].rightIndex, mentionsPos[i].leftIndex);
|
messageInputField.remove(mentionsPos[i].rightIndex, mentionsPos[i].leftIndex);
|
||||||
mentionsPos.pop(i);
|
mentionsPos.pop(i);
|
||||||
|
d.sortMentions()
|
||||||
}
|
}
|
||||||
} else if (((messageInputField.cursorPosition > mentionsPos[i].leftIndex) &&
|
} else if (((messageInputField.cursorPosition > mentionsPos[i].leftIndex) &&
|
||||||
(messageInputField.cursorPosition < mentionsPos[i].rightIndex)) &&
|
(messageInputField.cursorPosition < mentionsPos[i].rightIndex)) &&
|
||||||
|
|
Loading…
Reference in New Issue