fix(mentions): fix @everyone inserting incorrectly sometimes

Fixes #10212

The problem was that we were detecting that the name was empty string and comparing to another empty string and inserting that, which is incorrect.

There was also a problem with the detection of the name being completely written. onKeyPressed didn't take into account the new letter added, onKeyReleased does.
This commit is contained in:
Jonathan Rainville 2023-04-07 15:30:12 -04:00
parent f9250e7dd4
commit fe64d0eb04
2 changed files with 25 additions and 21 deletions

View File

@ -50,8 +50,10 @@ Item {
return
let filter = getFilter()
if (filter === undefined)
if (filter === undefined) {
formattedFilter = ""
return
}
this.lastAtPosition = -1
for (let c = cursorPosition === 0 ? 0 : (cursorPosition-1); c >= 0; c--) {
@ -69,7 +71,7 @@ Item {
let listItem = sourceModelList.itemAtIndex(i)
const item = {
publicKey: listItem.publicKey,
name: listItem.name,
name: listItem.name || listItem.alias,
nickname: listItem.nickname,
alias: listItem.alias,
ensName: listItem.ensName,
@ -82,10 +84,10 @@ Item {
const everyoneItem = {
publicKey: "0x00001",
name: "@everyone",
name: "everyone",
icon: ""
}
if (suggestionsPanelRoot.addSystemSuggestions && isAcceptedItem(filter, everyoneItem)) {
if (suggestionsPanelRoot.addSystemSuggestions && (all || isAcceptedItem(filter, everyoneItem))) {
filterModel.append(everyoneItem)
}
}
@ -123,7 +125,7 @@ Item {
filterWithoutAt = filterWithoutAt.replace(/\*/g, "")
suggestionsPanelRoot.formattedFilter = filterWithoutAt
return !properties.every(p => item[p].toLowerCase().match(filterWithoutAt.toLowerCase()) === null)
return properties.some(p => item[p].toLowerCase().match(filterWithoutAt.toLowerCase()) != null)
&& (lastAtPosition > -1)
}

View File

@ -501,22 +501,6 @@ Rectangle {
}
isColonPressed = event.key === Qt.Key_Colon;
if (suggestionsBox.visible) {
let aliasName = suggestionsBox.formattedPlainTextFilter;
let lastCursorPosition = suggestionsBox.suggestionFilter.cursorPosition;
let lastAtPosition = suggestionsBox.suggestionFilter.lastAtPosition;
let suggestionItem = suggestionsBox.suggestionsModel.get(suggestionsBox.listView.currentIndex);
if (aliasName.toLowerCase() === suggestionItem.name.toLowerCase()
&& (event.key !== Qt.Key_Backspace) && (event.key !== Qt.Key_Delete)) {
d.insertMention(aliasName, suggestionItem.publicKey, lastAtPosition, lastCursorPosition);
} else if (event.key === Qt.Key_Space) {
var plainTextToReplace = messageInputField.getText(lastAtPosition, lastCursorPosition);
messageInputField.remove(lastAtPosition, lastCursorPosition);
messageInputField.insert(lastAtPosition, plainTextToReplace);
suggestionsBox.hide();
}
}
}
function getLineStartPosition(selectionStart) {
@ -717,6 +701,24 @@ Rectangle {
messageInputField.readOnly = false;
messageInputField.cursorPosition = (d.copyTextStart + QClipboardProxy.text.length + d.nbEmojisInClipboard);
}
if (suggestionsBox.visible) {
let aliasName = suggestionsBox.formattedPlainTextFilter;
let lastCursorPosition = suggestionsBox.suggestionFilter.cursorPosition;
let lastAtPosition = suggestionsBox.suggestionFilter.lastAtPosition;
let suggestionItem = suggestionsBox.suggestionsModel.get(suggestionsBox.listView.currentIndex);
if (aliasName !== "" && aliasName.toLowerCase() === suggestionItem.name.toLowerCase()
&& (event.key !== Qt.Key_Backspace) && (event.key !== Qt.Key_Delete)) {
d.insertMention(aliasName, suggestionItem.publicKey, lastAtPosition, lastCursorPosition);
} else if (event.key === Qt.Key_Space) {
var plainTextToReplace = messageInputField.getText(lastAtPosition, lastCursorPosition);
messageInputField.remove(lastAtPosition, lastCursorPosition);
messageInputField.insert(lastAtPosition, plainTextToReplace);
suggestionsBox.hide();
}
}
}
// since emoji length is not 1 we need to match that position that TextArea returns