Conversation
…ibility
OpenProject embeds BlockNote inside a Shadow DOM (attachShadow({ mode: 'open' }))
to isolate it from the host Angular application. In this setup,
window.getSelection() returns null or a collapsed selection even when text is
selected (Firefox all versions, Safari ≤16.3, Chromium edge cases), causing
checkIfSelectionInNonEditableBlock to always return true and skip the
clipboard write entirely. The browser's default copy then fires, which uses
ProseMirror's DOMSerializer without semantic wrappers — so list formatting,
headings, and bold/italic are lost on paste into external apps.
Fix: use view.state.selection.empty as the primary empty-selection guard.
ProseMirror's internal state is always accurate regardless of DOM mode. The
DOM-level non-editable-island check is kept as a secondary guard, but only
when window.getSelection() actually returns a non-collapsed selection.
Fixes copy/cut for editors mounted inside attachShadow({ mode: 'open' }).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
BlockNote embeds ProseMirror inside editors that may be mounted in a Shadow DOM (e.g. OpenProject uses
attachShadow({ mode: 'open' })to isolate the editor from its Angular host). In this setup,window.getSelection()returnsnullor a collapsed selection even when text is visually selected — this affects Firefox (all versions), Safari ≤16.3, and Chromium edge cases.checkIfSelectionInNonEditableBlockusedwindow.getSelection()as its primary empty-selection guard. BecausegetSelection()misfires in Shadow DOM, the guard always returnedtrue, causing both thecopyandcuthandlers to bail out early without writing to the clipboard. The browser's default copy then ran, which uses ProseMirror'sDOMSerializerwithout BlockNote's semantic wrappers — losing list formatting, headings, and bold/italic on paste into external apps.Fix
Use
view.state.selection.emptyas the primary guard. ProseMirror's internal selection state is updated via its own reconciliation loop and is always accurate regardless of DOM mode.The non-editable-block DOM walk (which does need
window.getSelection()) is kept as a secondary guard, but only runs whengetSelection()actually returns a non-collapsed selection — so it's a no-op in Shadow DOM environments wheregetSelection()is unreliable.Test
Verified in OpenProject (Shadow DOM setup) with a bullet list: the clipboard now contains all three expected types —
blocknote/html,text/html(with<ul>/<li>), andtext/plain(markdown* item).