Conversation
Strip < and > from pasted BlockNote links to keep valid external URLs.
b6777f9 to
598a6ad
Compare
|
Size Change: 0 B Total Size: 4.26 MB 📦 View Changed
|
WalkthroughThe PR updates CHANGELOG.md with a new "[Unreleased] → Fixed" entry for sanitizing pasted toolbar links and minor formatting tweaks to existing bullets. In the frontend, BlockNoteEditor gains an Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx (1)
99-106: Scope this paste sanitizer to the link toolbar field only.Because capture is attached at Line 302 on the editor root, any nested input/textarea can be affected. Consider guarding by a specific attribute/class for the link URL input to avoid side effects in unrelated controls.
Also applies to: 302-302
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@src/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx`:
- Around line 112-120: The paste handler currently replaces the entire
input/textarea value with the sanitized text; instead, read the element's
existing value and selection (use target.selectionStart and target.selectionEnd
on HTMLInputElement/HTMLTextAreaElement), construct a newValue by inserting the
cleaned text between those indices, use the native value setter (as you already
get from Object.getOwnPropertyDescriptor(proto, 'value')?.set) to set newValue,
then restore/update the caret/selection to sit after the inserted text (set
selectionStart/selectionEnd to start + cleaned.length) before dispatching the
input event; apply these changes in the paste handling logic inside
BlockNoteEditor so surrounding content is preserved and caret semantics are
correct.
- Around line 107-111: The code trims pasted text before stripping angle
brackets which causes unchanged content with leading/trailing spaces to be
rewritten; in BlockNoteEditor replace const cleaned =
stripAngleBrackets(text.trim()) with const cleaned = stripAngleBrackets(text) so
you do not remove whitespace when there are no angle brackets, and keep the
existing comparison if (cleaned === text) return; (handle any trimming later
only when you actually need normalized content).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5db157d4-5c20-4ac3-a869-bfd13f71fd67
📒 Files selected for processing (2)
CHANGELOG.mdsrc/frontend/apps/impress/src/features/docs/doc-editor/components/BlockNoteEditor.tsx
There was a problem hiding this comment.
I think we should open a issue on Blocknote because it is a problem on their side at the base.
I am not huge fan of the patch, because we fix the symptom (paste), but not the root cause (copy), if you paste the link somewhere else (e.g: in the browser url input) you still have the problem.
Plus we are now overriding the paste event, even if it is targeting only the input, it could bring unexpected side effects that we will have to support.
The problem comes probably from this file, I suggest we either open a issue, or propose a fix on their side:
https://github.com/TypeCellOS/BlockNote/blob/main/packages/core/src/api/clipboard/toClipboard/copyExtension.ts#L176-L199
We could eventually merge this PR in waiting for the fix on the BN side, but we should let the issue opened until Blocknote made the fix, and then remove the patch.
Wdyt ?
Yes, I agree, we need to handle the root case. I’m ok with merging this for now, and I’ll create a PR on the BlockNote side. EDI : pr on BN side |
Purpose
Fix broken links when pasting a URL into the BlockNote link toolbar input.
BlockNote copies links in Markdown autolink format (
<url>), and the anglebrackets are kept as-is when pasting, resulting of invalid hrefs.
lien.mp4
Proposal
onPasteCapturehandler that strips<>from pasted URLs ininput/textarea fields within the editor container