Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions apps/web/src/components/editor/use-block-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,43 @@ type UseBlockEditorOptions = {
initialBlocks?: [PartialBlock, ...PartialBlock[]] | undefined;
};

function getAnchorFromTarget(target: EventTarget | null) {
if (!(target instanceof Element)) return null;
const anchor = target.closest("a[href]");
return anchor instanceof HTMLAnchorElement ? anchor : null;
}

export function useBlockEditor({ initialBlocks }: UseBlockEditorOptions) {
const editor = useCreateBlockNote({
_tiptapOptions: {
editorProps: {
handleClick: (_view, _pos, event) => {
const anchor = getAnchorFromTarget(event.target);

if (!anchor) return false;

event.preventDefault();

// Block single-click navigation for links in the editor.
return true;
Comment on lines +34 to +37
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Let ProseMirror handle link single-click selection

This handler consumes every anchor click by returning true, which in ProseMirror means the click is fully handled and downstream/default editor click logic will not run. That blocks normal caret/selection updates when users single-click linked text, so they can no longer reliably place the cursor in a link to edit it (a regression in editing behavior even though navigation is blocked).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually to make sure the Link menu opens on click:
image

Otherwise the whole formatting toolbar would open.

},
handleDoubleClick: (_view, _pos, event) => {
const anchor = getAnchorFromTarget(event.target);

if (!anchor) return false;

event.preventDefault();

window.open(
anchor.href,
anchor.target || "_blank",
"noopener,noreferrer",
);

return true;
},
},
},
animations: false,
dictionary: {
...en,
Expand Down
Loading