fix(@desktop/mentions): editing mentions

This commit is contained in:
Andrei Smirnov 2021-09-24 14:40:02 +03:00 committed by Iuri Matias
parent 4ddb50573c
commit b3d551eeb2
3 changed files with 24 additions and 37 deletions

View File

@ -271,9 +271,12 @@ Item {
index += 8 // "<a href=" index += 8 // "<a href="
continue continue
} }
let address = message.substring(addrIndex, addrEndIndex) const address = '@' + message.substring(addrIndex, addrEndIndex)
let linkTag = message.substring(index, endIndex + 5) // "</a>" const linkTag = message.substring(index, endIndex + 5)
mentionsMap.set(address, linkTag) const linkText = linkTag.replace(/(<([^>]+)>)/ig,"").trim()
const atSymbol = linkText.startsWith("@") ? '' : '@'
const mentionTag = Constants.mentionSpanTag + atSymbol + linkText + '</span> '
mentionsMap.set(address, mentionTag)
index += linkTag.length index += linkTag.length
} }

View File

@ -107,7 +107,6 @@ Rectangle {
cursorPosition: container.cursorPosition cursorPosition: container.cursorPosition
} }
ListView { ListView {
id: listView id: listView
model: mentionsListDelegate model: mentionsListDelegate

View File

@ -12,12 +12,9 @@ Item {
property int lastAtPosition: 0 property int lastAtPosition: 0
property var property: ([]) property var property: ([])
Connections {
onFilterChanged: invalidateFilter() onFilterChanged: invalidateFilter()
onPropertyChanged: invalidateFilter() onPropertyChanged: invalidateFilter()
onSourceModelChanged: invalidateFilter() onSourceModelChanged: invalidateFilter()
}
Component.onCompleted: invalidateFilter() Component.onCompleted: invalidateFilter()
ListModel { ListModel {
@ -25,13 +22,23 @@ Item {
} }
function invalidateFilter() { function invalidateFilter() {
filterModel.clear(); filterModel.clear()
if (!isFilteringPropertyOk()) if (!isFilteringPropertyOk())
return return
var filter = getFilter() let filter = getFilter()
if (!isFilterReady(filter)) if (filter === undefined)
return
this.lastAtPosition = -1
for (let c = cursorPosition; c >= 0; c--) {
if (filter.charAt(c) === "@") {
this.lastAtPosition = c
break
}
}
if (this.lastAtPosition === -1)
return return
const all = shouldShowAll(filter) const all = shouldShowAll(filter)
@ -69,41 +76,19 @@ Item {
(hasAtBeforeCursor && hasWhiteSpaceBeforeAt && hasWhiteSpaceAfterAt) || (hasAtBeforeCursor && hasWhiteSpaceBeforeAt && hasWhiteSpaceAfterAt) ||
(this.cursorPosition === 1 && hasAtBeforeCursor && hasWhiteSpaceAfterAt) || (this.cursorPosition === 1 && hasAtBeforeCursor && hasWhiteSpaceAfterAt) ||
(cursorAtEnd && filter.endsWith("@") && hasWhiteSpaceBeforeAt)) { (cursorAtEnd && filter.endsWith("@") && hasWhiteSpaceBeforeAt)) {
this.lastAtPosition = this.cursorPosition - 1;
return true return true
} }
return false return false
} }
function isFilterReady(filter) {
if (filter === undefined) {
return false
}
// Prevents suggestions to show up at all
if (filter.indexOf("@") === -1) {
return false
}
let hasWhiteSpaceBeforeCursor = filter.charAt(this.cursorPosition - 1) === " "
if (filter.charAt(this.cursorPosition - 2) === "@" && hasWhiteSpaceBeforeCursor) {
return false
}
return true
}
function isAcceptedItem(filter, item) { function isAcceptedItem(filter, item) {
let properties = this.property let properties = this.property.filter(p => !!item[p])
.filter(p => !!item[p])
if (properties.length === 0) { if (properties.length === 0) {
return false return false
} }
let filterWithoutAt = filter.substring(lastAtPosition + 1, this.cursorPosition) let filterWithoutAt = filter.substring(this.lastAtPosition + 1, this.cursorPosition)
filterWithoutAt = filterWithoutAt.replace(/\*/g, "") filterWithoutAt = filterWithoutAt.replace(/\*/g, "")
component.formattedFilter = filterWithoutAt component.formattedFilter = filterWithoutAt