From 4cf0292204a29098e6449ab70deb4fe8d719c320 Mon Sep 17 00:00:00 2001 From: richard-loafle <44828666+richard-loafle@users.noreply.github.com> Date: Tue, 4 Feb 2020 17:59:27 +0900 Subject: [PATCH] bug fixed --- .../messenger/components/messages.component.html | 2 +- .../messenger/components/messages.component.ts | 15 +++++++++++++-- .../dialogs/chat/clipboard.dialog.component.html | 12 +++++------- .../dialogs/chat/clipboard.dialog.component.ts | 4 ++++ .../src/lib/components/form.component.ts | 4 ++-- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.html index fa08118b..0d3b73fa 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.html @@ -327,7 +327,7 @@ (clearView)="clearView()" (toggleStickerSelector)="onShowToggleStickerSelector($event)" (toggleTranslation)="onShowToggleTranslation($event)" - (clipboardPaste)="onClipboardPaste()" + (clipboardPaste)="onClipboardPaste($event)" > diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts index 1c92a9b5..cdaa60f0 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/components/messages.component.ts @@ -1965,7 +1965,7 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit { this.translationPreviewInfo = null; } - onClipboardPaste() { + onClipboardPaste(event: ClipboardEvent) { this.nativeService.readFromClipboard().then(async data => { if (!!data.image && !!data.text) { const result = await this.dialogService.open< @@ -2003,7 +2003,18 @@ export class MessagesComponent implements OnInit, OnDestroy, AfterViewInit { this.onFileSelected(fileUploadItems); } else { - this.chatForm.replyInput.nativeElement.value = `${this.chatForm.replyInput.nativeElement.value}${data.text}`; + const v = this.chatForm.replyInput.nativeElement.value; + const selectionStart = this.chatForm.replyInput.nativeElement + .selectionStart; + const selectionEnd = this.chatForm.replyInput.nativeElement + .selectionEnd; + + const start = v.substr(0, selectionStart); + const end = v.substr(selectionEnd); + + this.chatForm.replyInput.nativeElement.value = `${start}${data.text}${end}`; + + event.preventDefault(); } }); } diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/clipboard.dialog.component.html b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/clipboard.dialog.component.html index 59713d3e..bd42e33c 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/clipboard.dialog.component.html +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/clipboard.dialog.component.html @@ -32,19 +32,17 @@ --> diff --git a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/clipboard.dialog.component.ts b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/clipboard.dialog.component.ts index cc55f218..953adfbd 100644 --- a/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/clipboard.dialog.component.ts +++ b/projects/ucap-webmessenger-app/src/app/layouts/messenger/dialogs/chat/clipboard.dialog.component.ts @@ -35,6 +35,9 @@ export class ClipboardDialogComponent implements OnInit, AfterViewInit { @ViewChild('chkText', { static: false }) chkText: MatCheckbox; + @ViewChild('chkHtml', { static: false }) + chkHtml: MatCheckbox; + @ViewChild('chkImage', { static: false }) chkImage: MatCheckbox; @@ -58,6 +61,7 @@ export class ClipboardDialogComponent implements OnInit, AfterViewInit { if (choice) { selected = { text: !!this.chkText && this.chkText.checked, + html: !!this.chkHtml && this.chkHtml.checked, image: !!this.chkImage && this.chkImage.checked }; } else { diff --git a/projects/ucap-webmessenger-ui-chat/src/lib/components/form.component.ts b/projects/ucap-webmessenger-ui-chat/src/lib/components/form.component.ts index e3fd2f79..56914f19 100644 --- a/projects/ucap-webmessenger-ui-chat/src/lib/components/form.component.ts +++ b/projects/ucap-webmessenger-ui-chat/src/lib/components/form.component.ts @@ -35,7 +35,7 @@ export class FormComponent implements OnInit { clearView = new EventEmitter(); @Output() - clipboardPaste = new EventEmitter(); + clipboardPaste = new EventEmitter(); @ViewChild('replyForm', { static: false }) replyForm: NgForm; @@ -91,6 +91,6 @@ export class FormComponent implements OnInit { onPasteReply(event: ClipboardEvent) { event.preventDefault(); - this.clipboardPaste.emit(); + this.clipboardPaste.emit(event); } }