From b9a5c7f8579c51a3a6c5723099fb32fc50244142 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 7 Apr 2023 15:30:12 -0400 Subject: [PATCH] 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. --- .../Chat/panels/SuggestionFilterPanel.qml | 12 ++++--- ui/imports/shared/status/StatusChatInput.qml | 34 ++++++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/ui/app/AppLayouts/Chat/panels/SuggestionFilterPanel.qml b/ui/app/AppLayouts/Chat/panels/SuggestionFilterPanel.qml index c85823ada34..e58ca6f011d 100644 --- a/ui/app/AppLayouts/Chat/panels/SuggestionFilterPanel.qml +++ b/ui/app/AppLayouts/Chat/panels/SuggestionFilterPanel.qml @@ -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) } diff --git a/ui/imports/shared/status/StatusChatInput.qml b/ui/imports/shared/status/StatusChatInput.qml index 3b5b0c7990e..5c19abd170a 100644 --- a/ui/imports/shared/status/StatusChatInput.qml +++ b/ui/imports/shared/status/StatusChatInput.qml @@ -498,22 +498,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) { @@ -714,6 +698,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