From 326e1a455bb510d795f357123f617618267848cc Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Mon, 26 Dec 2022 16:22:26 +0530 Subject: [PATCH] feat: Clicking the link option in Super notes will automatically add the selected text as the link --- .../Plugins/FloatingTextFormatToolbarPlugin/index.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/blocks-editor/src/Lexical/Plugins/FloatingTextFormatToolbarPlugin/index.tsx b/packages/blocks-editor/src/Lexical/Plugins/FloatingTextFormatToolbarPlugin/index.tsx index 3fc4fd9ab..be19dcc28 100644 --- a/packages/blocks-editor/src/Lexical/Plugins/FloatingTextFormatToolbarPlugin/index.tsx +++ b/packages/blocks-editor/src/Lexical/Plugins/FloatingTextFormatToolbarPlugin/index.tsx @@ -54,6 +54,7 @@ import { ListNumbered, } from '@standardnotes/icons'; import {IconComponent} from '../../Theme/IconComponent'; +import {sanitizeUrl} from '../../Utils/sanitizeUrl'; const blockTypeToBlockName = { bullet: 'Bulleted List', @@ -103,7 +104,15 @@ function TextFormatFloatingToolbar({ const insertLink = useCallback(() => { if (!isLink) { - editor.dispatchCommand(TOGGLE_LINK_COMMAND, 'https://'); + editor.update(() => { + const selection = $getSelection(); + const textContent = selection?.getTextContent(); + if (!textContent) { + editor.dispatchCommand(TOGGLE_LINK_COMMAND, 'https://'); + return; + } + editor.dispatchCommand(TOGGLE_LINK_COMMAND, sanitizeUrl(textContent)); + }); } else { editor.dispatchCommand(TOGGLE_LINK_COMMAND, null); }