diff --git a/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.ts b/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.ts index 917f93c8..16936a07 100644 --- a/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.ts +++ b/projects/ucap-webmessenger-ui-message/src/lib/components/write.component.ts @@ -185,10 +185,17 @@ export class WriteComponent implements OnInit, OnDestroy, AfterViewInit { img.setAttribute('style', 'max-height:250px; max-width:250px;'); img[ATTR_FILE] = file; self.insertNode(img); + + const empty = document.createElement('div'); + empty.innerHTML = ' 
'; + self.insertNode(empty, true); } self.fileInput.nativeElement.value = ''; - this.fileInput.nativeElement.onchange = undefined; + self.fileInput.nativeElement.onchange = undefined; + + self.checkContentLength(); + self.changeDetectorRef.detectChanges(); }; } @@ -564,23 +571,27 @@ export class WriteComponent implements OnInit, OnDestroy, AfterViewInit { private insertNode(node: Node, removeSelected: boolean = false) { const selection: Selection = document.getSelection(); - const range: Range = selection.getRangeAt(0); - let inEditor = false; - if (removeSelected) { - // onPaste - selection.empty(); - inEditor = true; - } else { - inEditor = this.inEditor(selection.anchorNode); - } + if (!!selection && !!selection.anchorNode) { + const range: Range = selection.getRangeAt(0); - if (inEditor) { - range.insertNode(node); + let inEditor = false; + if (removeSelected) { + // onPaste + selection.empty(); + inEditor = true; + } else { + inEditor = this.inEditor(selection.anchorNode); + } + + if (inEditor) { + range.insertNode(node); + } else { + this.editor.nativeElement.appendChild(node); + } } else { this.editor.nativeElement.appendChild(node); } - selection.empty(); } private inEditor(el) {