Koenig - Prevent "Enter" being inserted into captions

refs https://github.com/TryGhost/Ghost/issues/9724
- mobiledoc-kit's `key.isPrintable()` returns true for <kbd>Enter</kbd> but in this instance we don't want to capture newlines as printable chars
- swapped insertion of `event.key` for `key.toString()` for better handling of named keys that output characters (eg. when `event.key` === `Enter` which prints `\n`)
This commit is contained in:
Kevin Ansfield 2018-08-11 18:26:30 +01:00
parent fcc943fc26
commit 482188b263
1 changed files with 2 additions and 2 deletions

View File

@ -90,10 +90,10 @@ export default Component.extend({
let key = new Key(event);
let {editor} = this;
if (event.target.matches('[data-kg="editor"]') && editor && !editor._hasFocus() && key.isPrintableKey()) {
if (event.target.matches('[data-kg="editor"]') && editor && !editor._hasFocus() && key.isPrintableKey() && !key.isEnter()) {
editor.focus();
editor.run((postEditor) => {
postEditor.insertText(editor.post.tailPosition(), event.key);
postEditor.insertText(editor.post.tailPosition(), key.toString());
});
event.preventDefault();