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="
continue
}
let address = message.substring(addrIndex, addrEndIndex)
let linkTag = message.substring(index, endIndex + 5) // "</a>"
mentionsMap.set(address, linkTag)
const address = '@' + message.substring(addrIndex, addrEndIndex)
const linkTag = message.substring(index, endIndex + 5)
const linkText = linkTag.replace(/(<([^>]+)>)/ig,"").trim()
const atSymbol = linkText.startsWith("@") ? '' : '@'
const mentionTag = Constants.mentionSpanTag + atSymbol + linkText + '</span> '
mentionsMap.set(address, mentionTag)
index += linkTag.length
}

View File

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

View File

@ -12,12 +12,9 @@ Item {
property int lastAtPosition: 0
property var property: ([])
Connections {
onFilterChanged: invalidateFilter()
onPropertyChanged: invalidateFilter()
onSourceModelChanged: invalidateFilter()
}
onFilterChanged: invalidateFilter()
onPropertyChanged: invalidateFilter()
onSourceModelChanged: invalidateFilter()
Component.onCompleted: invalidateFilter()
ListModel {
@ -25,13 +22,23 @@ Item {
}
function invalidateFilter() {
filterModel.clear();
filterModel.clear()
if (!isFilteringPropertyOk())
return
var filter = getFilter()
if (!isFilterReady(filter))
let filter = getFilter()
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
const all = shouldShowAll(filter)
@ -69,41 +76,19 @@ Item {
(hasAtBeforeCursor && hasWhiteSpaceBeforeAt && hasWhiteSpaceAfterAt) ||
(this.cursorPosition === 1 && hasAtBeforeCursor && hasWhiteSpaceAfterAt) ||
(cursorAtEnd && filter.endsWith("@") && hasWhiteSpaceBeforeAt)) {
this.lastAtPosition = this.cursorPosition - 1;
return true
}
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) {
let properties = this.property
.filter(p => !!item[p])
let properties = this.property.filter(p => !!item[p])
if (properties.length === 0) {
return false
}
let filterWithoutAt = filter.substring(lastAtPosition + 1, this.cursorPosition)
let filterWithoutAt = filter.substring(this.lastAtPosition + 1, this.cursorPosition)
filterWithoutAt = filterWithoutAt.replace(/\*/g, "")
component.formattedFilter = filterWithoutAt