From 1115fe354659c335bdbfb7eff66ab0f8eaf24382 Mon Sep 17 00:00:00 2001 From: Cyril Date: Wed, 15 Apr 2026 10:11:26 +0200 Subject: [PATCH] =?UTF-8?q?fixup!=20=F0=9F=90=9B(frontend)=20sanitize=20pa?= =?UTF-8?q?sted=20toolbar=20links?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docs/doc-editor/components/BlockNoteEditor.tsx | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx index a28922bc..dcd3e69f 100644 --- a/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx +++ b/src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx @@ -93,8 +93,6 @@ interface BlockNoteEditorProps { * BlockNote copies links in Markdown autolink format; pasting into the link * toolbar input keeps the brackets, producing broken hrefs. */ -const stripAngleBrackets = (text: string): string => - text.replace(/^<(.+)>$/, '$1'); const handlePasteUrlBrackets = (e: React.ClipboardEvent) => { const target = e.target; @@ -105,18 +103,14 @@ const handlePasteUrlBrackets = (e: React.ClipboardEvent) => { return; } const text = e.clipboardData?.getData('text/plain') ?? ''; - const cleaned = stripAngleBrackets(text.trim()); + const cleaned = text.replace(/^\s*<([^<>]+)>\s*$/, '$1'); if (cleaned === text) { return; } e.preventDefault(); - // Use the native value setter (input/textarea) so React-controlled fields pick up the pasted value change. - const proto = - target instanceof HTMLInputElement - ? HTMLInputElement.prototype - : HTMLTextAreaElement.prototype; - const setter = Object.getOwnPropertyDescriptor(proto, 'value')?.set; - setter?.call(target, cleaned); + const start = target.selectionStart ?? target.value.length; + const end = target.selectionEnd ?? target.value.length; + target.setRangeText(cleaned, start, end, 'end'); target.dispatchEvent(new Event('input', { bubbles: true })); };