feat: Clicking the link option in Super notes will automatically add the selected text as the link
This commit is contained in:
@@ -54,6 +54,7 @@ import {
|
|||||||
ListNumbered,
|
ListNumbered,
|
||||||
} from '@standardnotes/icons';
|
} from '@standardnotes/icons';
|
||||||
import {IconComponent} from '../../Theme/IconComponent';
|
import {IconComponent} from '../../Theme/IconComponent';
|
||||||
|
import {sanitizeUrl} from '../../Utils/sanitizeUrl';
|
||||||
|
|
||||||
const blockTypeToBlockName = {
|
const blockTypeToBlockName = {
|
||||||
bullet: 'Bulleted List',
|
bullet: 'Bulleted List',
|
||||||
@@ -103,7 +104,15 @@ function TextFormatFloatingToolbar({
|
|||||||
|
|
||||||
const insertLink = useCallback(() => {
|
const insertLink = useCallback(() => {
|
||||||
if (!isLink) {
|
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 {
|
} else {
|
||||||
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
editor.dispatchCommand(TOGGLE_LINK_COMMAND, null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user