Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mentions): fix @everyone inserting incorrectly sometimes #10245

Merged
merged 1 commit into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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) {
Expand Down Expand Up @@ -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
Expand Down