@@ -146,6 +146,34 @@ export function selectedFragmentToHTML<
146
146
return { clipboardHTML, externalHTML, markdown } ;
147
147
}
148
148
149
+ const checkIfSelectionInNonEditableBlock = ( ) => {
150
+ // Let browser handle event if selection is empty (nothing
151
+ // happens).
152
+ const selection = window . getSelection ( ) ;
153
+ if ( ! selection || selection . isCollapsed ) {
154
+ return true ;
155
+ }
156
+
157
+ // Let browser handle event if it's within a non-editable
158
+ // "island". This means it's in selectable content within a
159
+ // non-editable block. We only need to check one node as it's
160
+ // not possible for the browser selection to start in an
161
+ // editable block and end in a non-editable one.
162
+ let node = selection . focusNode ;
163
+ while ( node ) {
164
+ if (
165
+ node instanceof HTMLElement &&
166
+ node . getAttribute ( "contenteditable" ) === "false"
167
+ ) {
168
+ return true ;
169
+ }
170
+
171
+ node = node . parentElement ;
172
+ }
173
+
174
+ return false ;
175
+ } ;
176
+
149
177
const copyToClipboard = <
150
178
BSchema extends BlockSchema ,
151
179
I extends InlineContentSchema ,
@@ -186,11 +214,19 @@ export const createCopyToClipboardExtension = <
186
214
props : {
187
215
handleDOMEvents : {
188
216
copy ( view , event ) {
217
+ if ( checkIfSelectionInNonEditableBlock ( ) ) {
218
+ return true ;
219
+ }
220
+
189
221
copyToClipboard ( editor , view , event ) ;
190
222
// Prevent default PM handler to be called
191
223
return true ;
192
224
} ,
193
225
cut ( view , event ) {
226
+ if ( checkIfSelectionInNonEditableBlock ( ) ) {
227
+ return true ;
228
+ }
229
+
194
230
copyToClipboard ( editor , view , event ) ;
195
231
if ( view . editable ) {
196
232
view . dispatch ( view . state . tr . deleteSelection ( ) ) ;
0 commit comments