fix: [re-add] The text entry box shouldn't highlight invalid @mentions

Fixes #4678

The text input in chat was highlighting whatever was starting
with @. Fixed to highlight only valid user mentions.
This commit is contained in:
Jonathan Rainville 2022-02-09 13:19:46 -05:00
parent 7268ec3773
commit 3b43d2f9ea
1 changed files with 13 additions and 5 deletions

View File

@ -237,11 +237,19 @@ Rectangle {
isColonPressed = (event.key === Qt.Key_Colon) && (event.modifiers & Qt.ShiftModifier); isColonPressed = (event.key === Qt.Key_Colon) && (event.modifiers & Qt.ShiftModifier);
if (event.key === Qt.Key_Space && suggestionsBox.formattedPlainTextFilter.length > 1 && suggestionsBox.formattedPlainTextFilter.trim().split(" ").length === 1) { if (suggestionsBox.visible) {
let aliasName = suggestionsBox.formattedPlainTextFilter let aliasName = suggestionsBox.formattedPlainTextFilter;
let lastCursorPosition = suggestionsBox.suggestionFilter.cursorPosition let lastCursorPosition = suggestionsBox.suggestionFilter.cursorPosition;
let lastAtPosition = suggestionsBox.suggestionFilter.lastAtPosition let lastAtPosition = suggestionsBox.suggestionFilter.lastAtPosition;
insertMention(aliasName, lastAtPosition, lastCursorPosition) if (aliasName.toLowerCase() === suggestionsBox.suggestionsModel.get(suggestionsBox.listView.currentIndex).name.toLowerCase()
&& (event.key !== Qt.Key_Backspace) && (event.key !== Qt.Key_Delete)) {
insertMention(aliasName, 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();
}
} }
} }