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:
parent
13ccd50404
commit
d7bae46f5c
1 changed files with 26 additions and 0 deletions
|
@ -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);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue