mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-25 09:03:12 +03: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
@ -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());
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user