From 620c8fcd0461ba2ece7cd4955c109b6d997b8215 Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Thu, 21 Jun 2018 17:57:45 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Koenig=20-=20Fix=20Firefox=20add?= =?UTF-8?q?ing=20"ArrowUp"=20or=20similar=20to=20caption=20fields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refs https://github.com/TryGhost/Ghost/issues/9623 - Firefox unlike other browsers triggers `keypress` events for non-printable characters - use mobiledoc-kit's `Key` class to guard against adding non-printable key values to captions --- lib/koenig-editor/addon/components/koenig-caption-input.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/koenig-editor/addon/components/koenig-caption-input.js b/lib/koenig-editor/addon/components/koenig-caption-input.js index 3a440a00ad..8cb22649aa 100644 --- a/lib/koenig-editor/addon/components/koenig-caption-input.js +++ b/lib/koenig-editor/addon/components/koenig-caption-input.js @@ -1,4 +1,5 @@ import Component from '@ember/component'; +import Key from 'mobiledoc-kit/utils/key'; import layout from '../templates/components/koenig-caption-input'; import {computed} from '@ember/object'; import {kgStyle} from 'ember-cli-ghost-spirit/helpers/kg-style'; @@ -64,8 +65,9 @@ export default Component.extend({ // that it's possible to start typing without explicitly focusing the input _handleKeypress(event) { let captionInput = this.element.querySelector('[name="caption"]'); + let key = new Key(event); - if (captionInput && captionInput !== document.activeElement) { + if (captionInput && captionInput !== document.activeElement && key.isPrintableKey()) { captionInput.value = `${captionInput.value}${event.key}`; captionInput.focus(); event.preventDefault();