From 5eb817373f9e05d16bfadc2ef214a089a5079e97 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 3 Sep 2021 08:59:59 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixed=20captions=20becoming=20un?= =?UTF-8?q?editable=20when=20they=20have=20a=20trailing=20space?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes https://github.com/TryGhost/Team/issues/1023 closes https://github.com/TryGhost/Ghost/issues/11424 - we were comparing the caption editor's contenteditable inner html vs the passed in html in order to reset the editor if the bound value changed upstream, this was causing problems because the editor and external html cleaning were treating trailing whitespace slightly differently which resulted in the editor being reset every time it gained focus when a trailing space was present - removed reliance on inspecting the editor's inner html and instead switched to comparing a changed `html` value to that which was passed in during initialisation or was last passed upstream from the editor so there's no chance of unexpected deviance --- .../addon/components/koenig-basic-html-input.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-basic-html-input.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-basic-html-input.js index 17cf9be1ff..d45d8ec6d3 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-basic-html-input.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-basic-html-input.js @@ -74,6 +74,7 @@ export default Component.extend({ init() { this._super(...arguments); this.SPECIAL_MARKUPS = []; + this._lastSetHtml = this.html; }, didReceiveAttrs() { @@ -81,8 +82,9 @@ export default Component.extend({ // reset local mobiledoc if html has been changed upstream so that // the html will be re-parsed by the mobiledoc-kit editor - if (this.cleanHTML !== this._getHTML()) { + if (this._lastSetHtml !== this.html) { this.set('mobiledoc', null); + this._lastSetHtml = this.html; } }, @@ -343,7 +345,9 @@ export default Component.extend({ postDidChange() { // trigger closure action - this.onChange(this._getHTML()); + const html = this._getHTML(); + this._lastSetHtml = html; + this.onChange(html); }, cursorDidChange(editor) {