Koenig - Fix divider card insertion

refs https://github.com/TryGhost/Ghost/issues/9505
- ensure we select the next section when inserting a card
- remove duplicated card insertion logic by passing the Koenig instance to our text expansion helpers so that they can call actions
This commit is contained in:
Kevin Ansfield 2018-04-25 13:12:59 +01:00
parent 55645e9dd5
commit f2736be430
2 changed files with 8 additions and 16 deletions

View File

@ -243,7 +243,7 @@ export default Component.extend({
// TODO: this will override any passed in options, we should allow the
// default behaviour to be overridden by addon consumers
registerKeyCommands(editor);
registerTextExpansions(editor);
registerTextExpansions(editor, this);
editor.registerKeyCommand({
str: 'ENTER',
@ -381,14 +381,18 @@ export default Component.extend({
editor.run((postEditor) => {
let {builder} = postEditor;
let card = builder.createCardSection(cardName);
let needsTrailingParagraph = !section.next;
let nextSection = section.next;
let needsTrailingParagraph = !nextSection;
postEditor.replaceSection(section, card);
// add an empty paragraph after if necessary so writing can continue
if (needsTrailingParagraph) {
let newSection = postEditor.builder.createMarkupSection('p');
postEditor.insertSectionAtEnd(newSection);
postEditor.setRange(newSection.tailPosition());
} else {
postEditor.setRange(nextSection.headPosition());
}
});

View File

@ -11,7 +11,7 @@ import {run} from '@ember/runloop';
// TODO: this was copied from our old Koenig editor, it could do with some
// comments, cleanup, and refactoring
export default function (editor) {
export default function (editor, koenig) {
// We don't want to run all our content rules on every text entry event,
// instead we check to see if this text entry event could match a content
// rule, and only then run the rules. Right now we only want to match
@ -82,19 +82,7 @@ export default function (editor) {
return;
}
editor.run((postEditor) => {
let card = postEditor.builder.createCardSection('hr');
let needsTrailingParagraph = !section.next;
postEditor.replaceSection(section, card);
// add an empty paragraph after if necessary so writing can continue
if (needsTrailingParagraph) {
let newSection = postEditor.builder.createMarkupSection('p');
postEditor.insertSectionAtEnd(newSection);
postEditor.setRange(newSection.tailPosition());
}
});
koenig.send('replaceWithCardSection', 'hr', section.toRange());
}
});