Skip to content

Commit

Permalink
Made all events in non-selectable blocks get handled by browser (Type…
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlipski authored Sep 30, 2024
1 parent d0003b1 commit d198f89
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions packages/core/src/schema/blocks/createSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,20 @@ export type CustomBlockImplementation<
) => PartialBlockFromConfig<T, I, S>["props"] | undefined;
};

// Function that enables copying of selected content within non-selectable
// blocks.
// Function that causes events within non-selectable blocks to be handled by the
// browser instead of the editor.
export function applyNonSelectableBlockFix(nodeView: NodeView, editor: Editor) {
nodeView.stopEvent = (event) => {
// Ensures copy events are handled by the browser and not by ProseMirror.
if (
event.type === "copy" ||
event.type === "cut" ||
event.type === "paste"
) {
return true;
}
// Blurs the editor on mouse down as the block is non-selectable. This is
// mainly done to prevent UI elements like the formatting toolbar from being
// visible while content within a non-selectable block is selected.
if (event.type === "mousedown") {
setTimeout(() => {
editor.view.dom.blur();
}, 10);
return true;
}
return false;

return true;
};
}

Expand Down

0 comments on commit d198f89

Please sign in to comment.