From cd6d328266dd23f04000ddf6c8f0dbc60012fcf8 Mon Sep 17 00:00:00 2001 From: Zaidhaan Date: Fri, 3 Mar 2023 04:07:28 +0800 Subject: [PATCH] fix: only use username part of mention (#1843) --- components/publish/PublishWidget.vue | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index ba7c0e54..ea723803 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -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) => {