]> BookStack Code Mirror - bookstack/blobdiff - resources/js/wysiwyg/ui/defaults/forms/objects.ts
Search: Added exact/filter/tag term negation support
[bookstack] / resources / js / wysiwyg / ui / defaults / forms / objects.ts
index 714d5f64b916cd32301239c4304428f098735444..228566d442e5ce8c609dc4d363b3b29550f26bf3 100644 (file)
@@ -100,13 +100,12 @@ export const image: EditorFormDefinition = {
 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(() => {
@@ -114,9 +113,16 @@ export function $showLinkForm(link: LinkNode|null, context: EditorUiContext) {
             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 = {
@@ -197,7 +203,7 @@ export const media: EditorFormDefinition = {
                 if (selectedNode && node) {
                     selectedNode.replace(node)
                 } else if (node) {
-                    $insertNodeToNearestRoot(node);
+                    $insertNodes([node]);
                 }
             });
 
@@ -213,7 +219,7 @@ export const media: EditorFormDefinition = {
             updateNode.setSrc(src);
             updateNode.setWidthAndHeight(width, height);
             if (!selectedNode) {
-                $insertNodeToNearestRoot(updateNode);
+                $insertNodes([updateNode]);
             }
         });