0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Koenig - Create blank paragraph when pressing Enter in title input

refs https://github.com/TryGhost/Ghost/issues/9311
- adds a solution to the problem of not being able to add text above a card if that card is the first section in the mobiledoc
This commit is contained in:
Kevin Ansfield 2018-03-14 13:07:50 +00:00
parent 13ccd50404
commit d7bae46f5c

View file

@ -72,6 +72,12 @@ export default Component.extend({
((event.key === 'ArrowDown' || event.key === 'ArrowRight') && (!value || selectionStart === value.length)) ((event.key === 'ArrowDown' || event.key === 'ArrowRight') && (!value || selectionStart === value.length))
) { ) {
event.preventDefault(); event.preventDefault();
// on Enter we also want to create a blank para if necessary
if (event.key === 'Enter') {
this._addParaAtTop();
}
this._editor.focus(); this._editor.focus();
} }
}, },
@ -104,5 +110,25 @@ export default Component.extend({
return true; return true;
} }
}); });
},
_addParaAtTop() {
if (!this._editor) {
return;
}
let editor = this._editor;
let section = editor.post.toRange().head.section;
// create a blank paragraph at the top of the editor unless it's already
// a blank paragraph
if (section.isListItem || !section.isBlank || section.text !== '') {
editor.run((postEditor) => {
let {builder} = postEditor;
let newPara = builder.createMarkupSection('p');
postEditor.insertSectionBefore(section.parent.sections, newPara, section);
});
}
} }
}); });