From df82f2444fa421b3d24957aa3ef289b80c6d66e7 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Sun, 15 Nov 2020 21:00:29 -0600 Subject: [PATCH] Fixes #37 --- src/app/components/wysiwyg/wysiwyg.component.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/app/components/wysiwyg/wysiwyg.component.ts b/src/app/components/wysiwyg/wysiwyg.component.ts index 2fddde6..f6dcc1f 100644 --- a/src/app/components/wysiwyg/wysiwyg.component.ts +++ b/src/app/components/wysiwyg/wysiwyg.component.ts @@ -9,8 +9,14 @@ export class WysiwygComponent implements OnInit { @ViewChild('editable') editable; @Input() readonly = false; @Input() set contents(val: string) { - if ( this.currentContents !== val ) { - this.currentContents = val; + if ( this.isFocused ) { + if ( this.editingContents !== val ) { + this.editingContents = val; + } + } else { + if ( this.currentContents !== val ) { + this.currentContents = val; + } } } @@ -21,6 +27,7 @@ export class WysiwygComponent implements OnInit { @Output() contentsChanged: EventEmitter = new EventEmitter(); public currentContents = ''; + protected editingContents = ''; public isFocused = false; protected hadOneFocusOut = false; @@ -52,6 +59,7 @@ export class WysiwygComponent implements OnInit { onFocusIn(event: MouseEvent) { console.log('on focus in', event); this.isFocused = !this.readonly; + this.editingContents = this.currentContents; } @HostListener('document:keyup.escape', ['$event']) @@ -68,6 +76,7 @@ export class WysiwygComponent implements OnInit { } else { this.isFocused = false; this.hadOneFocusOut = false; + this.currentContents = this.editingContents; } }