mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-13 16:22:59 +10:00
Move core logic of setLink to outer scope
Will allow code changes in a subsequent commit to access the function and utilize the same core logic
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 (
|
||||
|
||||
Reference in New Issue
Block a user