mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
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:
parent
55645e9dd5
commit
f2736be430
2 changed files with 8 additions and 16 deletions
|
@ -243,7 +243,7 @@ export default Component.extend({
|
||||||
// TODO: this will override any passed in options, we should allow the
|
// TODO: this will override any passed in options, we should allow the
|
||||||
// default behaviour to be overridden by addon consumers
|
// default behaviour to be overridden by addon consumers
|
||||||
registerKeyCommands(editor);
|
registerKeyCommands(editor);
|
||||||
registerTextExpansions(editor);
|
registerTextExpansions(editor, this);
|
||||||
|
|
||||||
editor.registerKeyCommand({
|
editor.registerKeyCommand({
|
||||||
str: 'ENTER',
|
str: 'ENTER',
|
||||||
|
@ -381,14 +381,18 @@ export default Component.extend({
|
||||||
editor.run((postEditor) => {
|
editor.run((postEditor) => {
|
||||||
let {builder} = postEditor;
|
let {builder} = postEditor;
|
||||||
let card = builder.createCardSection(cardName);
|
let card = builder.createCardSection(cardName);
|
||||||
let needsTrailingParagraph = !section.next;
|
let nextSection = section.next;
|
||||||
|
let needsTrailingParagraph = !nextSection;
|
||||||
|
|
||||||
postEditor.replaceSection(section, card);
|
postEditor.replaceSection(section, card);
|
||||||
|
|
||||||
|
// add an empty paragraph after if necessary so writing can continue
|
||||||
if (needsTrailingParagraph) {
|
if (needsTrailingParagraph) {
|
||||||
let newSection = postEditor.builder.createMarkupSection('p');
|
let newSection = postEditor.builder.createMarkupSection('p');
|
||||||
postEditor.insertSectionAtEnd(newSection);
|
postEditor.insertSectionAtEnd(newSection);
|
||||||
postEditor.setRange(newSection.tailPosition());
|
postEditor.setRange(newSection.tailPosition());
|
||||||
|
} else {
|
||||||
|
postEditor.setRange(nextSection.headPosition());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import {run} from '@ember/runloop';
|
||||||
// TODO: this was copied from our old Koenig editor, it could do with some
|
// TODO: this was copied from our old Koenig editor, it could do with some
|
||||||
// comments, cleanup, and refactoring
|
// 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,
|
// 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
|
// 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
|
// rule, and only then run the rules. Right now we only want to match
|
||||||
|
@ -82,19 +82,7 @@ export default function (editor) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
editor.run((postEditor) => {
|
koenig.send('replaceWithCardSection', 'hr', section.toRange());
|
||||||
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());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue