mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-12 14:05:08 +10:00
Merge pull request #1729 from CorreyL/feature/ctrl-k-for-hyperlink
[Feature] Keyboard Shortcut for Hyperlink
This commit is contained in:
@@ -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<Editor, RichInputProps>(
|
||||
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: {
|
||||
|
||||
Reference in New Issue
Block a user