mirror of
https://github.com/elk-zone/elk.git
synced 2024-11-07 01:19:57 +00:00
fix: only count 23 characters per link when composing (#1660)
This commit is contained in:
parent
65bbc7c790
commit
f1087fd270
1 changed files with 13 additions and 1 deletions
|
@ -64,7 +64,19 @@ const { editor } = useTiptap({
|
||||||
})
|
})
|
||||||
|
|
||||||
const characterCount = $computed(() => {
|
const characterCount = $computed(() => {
|
||||||
let length = stringLength(htmlToText(editor.value?.getHTML() || ''))
|
const text = htmlToText(editor.value?.getHTML() || '')
|
||||||
|
|
||||||
|
let length = stringLength(text)
|
||||||
|
|
||||||
|
// taken from https://github.com/mastodon/mastodon/blob/07f8b4d1b19f734d04e69daeb4c3421ef9767aac/app/lib/text_formatter.rb
|
||||||
|
const linkRegex = /(https?:\/\/(www\.)?|xmpp:)\S+/g
|
||||||
|
|
||||||
|
// maximum of 23 chars per link
|
||||||
|
// https://github.com/elk-zone/elk/issues/1651
|
||||||
|
const maxLength = 23
|
||||||
|
|
||||||
|
for (const [fullMatch] of text.matchAll(linkRegex))
|
||||||
|
length -= fullMatch.length - Math.min(maxLength, fullMatch.length)
|
||||||
|
|
||||||
if (draft.mentions) {
|
if (draft.mentions) {
|
||||||
// + 1 is needed as mentions always need a space seperator at the end
|
// + 1 is needed as mentions always need a space seperator at the end
|
||||||
|
|
Loading…
Reference in a new issue