diff --git a/src/app/ngx-editor/ngx-editor.component.html b/src/app/ngx-editor/ngx-editor.component.html index 2ea99f04..31dc9587 100644 --- a/src/app/ngx-editor/ngx-editor.component.html +++ b/src/app/ngx-editor/ngx-editor.component.html @@ -94,7 +94,7 @@
diff --git a/src/app/ngx-editor/ngx-editor.component.ts b/src/app/ngx-editor/ngx-editor.component.ts index 8e6c4cd2..63e53d69 100644 --- a/src/app/ngx-editor/ngx-editor.component.ts +++ b/src/app/ngx-editor/ngx-editor.component.ts @@ -106,15 +106,21 @@ export class NgxEditorComponent implements OnInit { createLink() { const selection = document.getSelection(); - if (selection['type'] === 'None') { - this.createMessage('No selection made'); - } else { - const linkURL = prompt('Enter URL', 'http://'); + if (selection.anchorNode.parentElement.tagName === 'A') { + const linkURL = prompt('Enter URL', selection.anchorNode.parentElement.getAttribute('href')) if (linkURL) { document.execCommand('createLink', false, linkURL); } + } else { + if (selection['type'] === 'None') { + this.createMessage('No selection made'); + } else { + const linkURL = prompt('Enter URL', 'http://'); + if (linkURL) { + document.execCommand('createLink', false, linkURL); + } + } } - } /*