Koenig - Handle deletion of last card with no other sections

refs https://github.com/TryGhost/Ghost/issues/9505
- if there is only a single card in a document and no other text then deleting it would throw an error because we assumed there's another section to move the cursor to
- handle the situation of not having a position to move to by creating a new blank paragraph and placing the cursor inside
This commit is contained in:
Kevin Ansfield 2018-05-08 18:17:30 +01:00
parent b4b85fba99
commit e8fdc4ca6f

View File

@ -900,15 +900,24 @@ export default Component.extend({
let nextPosition;
if (cursorDirection === CURSOR_BEFORE) {
nextPosition = section.prev.tailPosition();
nextPosition = section.prev && section.prev.tailPosition();
} else {
nextPosition = section.next.headPosition();
nextPosition = section.next && section.next.headPosition();
}
postEditor.removeSection(section);
// if there's no prev or next section then the doc is empty, we want
// to add a blank paragraph and place the cursor in it
if (cursorDirection !== NO_CURSOR_MOVEMENT && !nextPosition) {
let {builder} = postEditor;
let newPara = builder.createMarkupSection('p');
postEditor.insertSectionAtEnd(newPara);
return postEditor.setRange(newPara.tailPosition());
}
if (cursorDirection !== NO_CURSOR_MOVEMENT) {
postEditor.setRange(nextPosition);
return postEditor.setRange(nextPosition);
}
});
},