From 998fa9ccb11f0ecb1101fb74b11abac9264914be Mon Sep 17 00:00:00 2001 From: Emily Medhurst Date: Mon, 16 Jan 2023 10:24:29 +0000 Subject: [PATCH] fix: post length should account for draft mentions (#1202) --- components/publish/PublishWidget.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/publish/PublishWidget.vue b/components/publish/PublishWidget.vue index cb803a0f..9bafb1ad 100644 --- a/components/publish/PublishWidget.vue +++ b/components/publish/PublishWidget.vue @@ -61,7 +61,19 @@ const { editor } = useTiptap({ }, onPaste: handlePaste, }) -const characterCount = $computed(() => htmlToText(editor.value?.getHTML() || '').length) +const characterCount = $computed(() => { + let length = htmlToText(editor.value?.getHTML() || '').length + + if (draft.mentions) { + // + 1 is needed as mentions always need a space seperator at the end + length += draft.mentions.map((mention) => { + const [handle] = mention.split('@') + return `@${handle}` + }).join(' ').length + 1 + } + + return length +}) async function handlePaste(evt: ClipboardEvent) { const files = evt.clipboardData?.files