export function $showLinkForm(link: LinkNode|null, context: EditorUiContext) {
const linkModal = context.manager.createModal('link');
- let formDefaults = {};
if (link) {
- formDefaults = {
+ const formDefaults: Record<string, string> = {
url: link.getURL(),
text: link.getTextContent(),
- title: link.getTitle(),
- target: link.getTarget(),
+ title: link.getTitle() || '',
+ target: link.getTarget() || '',
}
context.editor.update(() => {
selection.add(link.getKey());
$setSelection(selection);
});
- }
- linkModal.show(formDefaults);
+ linkModal.show(formDefaults);
+ } else {
+ context.editor.getEditorState().read(() => {
+ const selection = $getSelection();
+ const text = selection?.getTextContent() || '';
+ const formDefaults = {text};
+ linkModal.show(formDefaults);
+ });
+ }
}
export const link: EditorFormDefinition = {