mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 20:34:02 +03:00
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:
parent
b4b85fba99
commit
e8fdc4ca6f
@ -900,15 +900,24 @@ export default Component.extend({
|
|||||||
let nextPosition;
|
let nextPosition;
|
||||||
|
|
||||||
if (cursorDirection === CURSOR_BEFORE) {
|
if (cursorDirection === CURSOR_BEFORE) {
|
||||||
nextPosition = section.prev.tailPosition();
|
nextPosition = section.prev && section.prev.tailPosition();
|
||||||
} else {
|
} else {
|
||||||
nextPosition = section.next.headPosition();
|
nextPosition = section.next && section.next.headPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
postEditor.removeSection(section);
|
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) {
|
if (cursorDirection !== NO_CURSOR_MOVEMENT) {
|
||||||
postEditor.setRange(nextPosition);
|
return postEditor.setRange(nextPosition);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user