fix(message): removed extra markup when typing before mention

Closes #8495
This commit is contained in:
Alexandra Betouni 2023-01-18 22:21:25 +02:00 committed by Alexandra Betouni
parent 7a1c768898
commit 7f2563edf4
2 changed files with 11 additions and 10 deletions

View File

@ -54,7 +54,7 @@ Item {
return return
this.lastAtPosition = -1 this.lastAtPosition = -1
for (let c = cursorPosition; c >= 0; c--) { for (let c = cursorPosition === 0 ? 0 : (cursorPosition-1); c >= 0; c--) {
if (filter.charAt(c) === "@") { if (filter.charAt(c) === "@") {
this.lastAtPosition = c this.lastAtPosition = c
break break
@ -119,12 +119,12 @@ Item {
if (properties.length === 0) { if (properties.length === 0) {
return false return false
} }
let filterWithoutAt = filter.substring(this.lastAtPosition + 1, this.cursorPosition) let filterWithoutAt = filter.substring(this.lastAtPosition + 1, this.cursorPosition)
filterWithoutAt = filterWithoutAt.replace(/\*/g, "") filterWithoutAt = filterWithoutAt.replace(/\*/g, "")
suggestionsPanelRoot.formattedFilter = filterWithoutAt suggestionsPanelRoot.formattedFilter = filterWithoutAt
return !properties.every(p => item[p].toLowerCase().match(filterWithoutAt.toLowerCase()) === null) return !properties.every(p => item[p].toLowerCase().match(filterWithoutAt.toLowerCase()) === null)
&& (lastAtPosition > -1)
} }
function isFilteringPropertyOk() { function isFilteringPropertyOk() {

View File

@ -367,7 +367,7 @@ Rectangle {
event.key !== Qt.Key_Backspace && event.key !== Qt.Key_Backspace &&
event.key !== Qt.Key_Delete && event.key !== Qt.Key_Delete &&
event.key !== Qt.Key_Escape event.key !== Qt.Key_Escape
if (mentionsPos.length > 0 && symbolPressed) { if ((mentionsPos.length > 0) && symbolPressed && (messageInputField.selectedText.length === 0)) {
for (var i = 0; i < mentionsPos.length; i++) { for (var i = 0; i < mentionsPos.length; i++) {
if (messageInputField.cursorPosition === mentionsPos[i].leftIndex) { if (messageInputField.cursorPosition === mentionsPos[i].leftIndex) {
d.leftOfMentionIndex = i d.leftOfMentionIndex = i
@ -1223,6 +1223,7 @@ Rectangle {
TextArea { TextArea {
id: messageInputField id: messageInputField
objectName: "messageInputField" objectName: "messageInputField"
property var lastClick: 0 property var lastClick: 0
@ -1260,21 +1261,21 @@ Rectangle {
} }
onCursorPositionChanged: { onCursorPositionChanged: {
if(mentionsPos.length > 0) { if(mentionsPos.length > 0 && ((keyEvent.key === Qt.Key_Left) || (keyEvent.key === Qt.Key_Right)
|| (selectedText.length>0))) {
const mention = d.getMentionAtPosition(cursorPosition) const mention = d.getMentionAtPosition(cursorPosition)
if(mention) { if (mention) {
const cursorMovingLeft = cursorPosition < previousCursorPosition const cursorMovingLeft = (cursorPosition < previousCursorPosition);
const newCursorPosition = cursorMovingLeft ? const newCursorPosition = cursorMovingLeft ?
mention.leftIndex : mention.leftIndex :
mention.rightIndex mention.rightIndex
const isSelection = selectionStart != selectionEnd const isSelection = (selectedText.length>0);
isSelection ? moveCursorSelection(newCursorPosition, TextEdit.SelectCharacters) : isSelection ? moveCursorSelection(newCursorPosition, TextEdit.SelectCharacters) :
cursorPosition = newCursorPosition cursorPosition = newCursorPosition
} }
} }
inputScrollView.ensureVisible(cursorRectangle) inputScrollView.ensureVisible(cursorRectangle)
previousCursorPosition = cursorPosition previousCursorPosition = cursorPosition
} }