diff --git a/libs/ui/src/components/rich-input.tsx b/libs/ui/src/components/rich-input.tsx index 790cbba10..22824f101 100644 --- a/libs/ui/src/components/rich-input.tsx +++ b/libs/ui/src/components/rich-input.tsx @@ -113,25 +113,29 @@ const InsertImageForm = ({ onInsert }: InsertImageProps) => { ); }; +const setLinkGlobal = (editor: Editor) => { + const previousUrl = editor.getAttributes("link").href; + const url = window.prompt("URL", previousUrl); + + // cancelled + if (url === null) { + return; + } + + // empty + if (url === "") { + editor.chain().focus().extendMarkRange("link").unsetLink().run(); + + return; + } + + // update link + editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run(); +}; + const Toolbar = ({ editor }: { editor: Editor }) => { const setLink = useCallback(() => { - const previousUrl = editor.getAttributes("link").href; - const url = window.prompt("URL", previousUrl); - - // cancelled - if (url === null) { - return; - } - - // empty - if (url === "") { - editor.chain().focus().extendMarkRange("link").unsetLink().run(); - - return; - } - - // update link - editor.chain().focus().extendMarkRange("link").setLink({ href: url }).run(); + setLinkGlobal(editor); }, [editor]); return ( @@ -440,7 +444,17 @@ export const RichInput = forwardRef( Image, Underline, Highlight, - Link.extend({ inclusive: false }).configure({ openOnClick: false }), + Link.extend({ + inclusive: false, + addKeyboardShortcuts() { + return { + "Mod-k": () => { + setLinkGlobal(this.editor as Editor); + return true; + }, + }; + }, + }).configure({ openOnClick: false }), TextAlign.configure({ types: ["heading", "paragraph"] }), ], editorProps: {