fix: only use username part of mention (#1843)
This commit is contained in:
parent
dbfb450e23
commit
cd6d328266
|
@ -71,6 +71,9 @@ const characterCount = $computed(() => {
|
|||
// taken from https://github.com/mastodon/mastodon/blob/07f8b4d1b19f734d04e69daeb4c3421ef9767aac/app/lib/text_formatter.rb
|
||||
const linkRegex = /(https?:\/\/(www\.)?|xmpp:)\S+/g
|
||||
|
||||
// taken from https://github.com/mastodon/mastodon/blob/af578e/app/javascript/mastodon/features/compose/util/counter.js
|
||||
const countableMentionRegex = /(^|[^/\w])@(([a-z0-9_]+)@[a-z0-9.-]+[a-z0-9]+)/ig
|
||||
|
||||
// maximum of 23 chars per link
|
||||
// https://github.com/elk-zone/elk/issues/1651
|
||||
const maxLength = 23
|
||||
|
@ -78,6 +81,9 @@ const characterCount = $computed(() => {
|
|||
for (const [fullMatch] of text.matchAll(linkRegex))
|
||||
length -= fullMatch.length - Math.min(maxLength, fullMatch.length)
|
||||
|
||||
for (const [fullMatch, before, handle, username] of text.matchAll(countableMentionRegex))
|
||||
length -= fullMatch.length - (before + username).length - 1 // - 1 for the @
|
||||
|
||||
if (draft.mentions) {
|
||||
// + 1 is needed as mentions always need a space seperator at the end
|
||||
length += draft.mentions.map((mention) => {
|
||||
|
|
Loading…
Reference in a new issue