Skip to content

Commit

Permalink
fix(mentions): fix @everyone inserting incorrectly sometimes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jrainville committed Apr 11, 2023
1 parent f9250e7 commit fe64d0e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
12 changes: 7 additions & 5 deletions ui/app/AppLayouts/Chat/panels/SuggestionFilterPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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--) {
Expand All @@ -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,
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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)
}

Expand Down
34 changes: 18 additions & 16 deletions ui/imports/shared/status/StatusChatInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fe64d0e

Please sign in to comment.