Skip to content
This repository has been archived by the owner on Nov 28, 2022. It is now read-only.

Commit

Permalink
If this card is the last element in the document create an empty para…
Browse files Browse the repository at this point in the history
…graph afterwards.
  • Loading branch information
disordinary authored and kevinansfield committed Apr 6, 2017
1 parent 4c8e558 commit d65d0eb
Showing 1 changed file with 33 additions and 14 deletions.
47 changes: 33 additions & 14 deletions lib/gh-koenig/addon/options/default-tools.js
Expand Up @@ -199,14 +199,18 @@ export default function (editor, toolbar) {
cardMenu: true,
onClick: (editor) => {
editor.run((postEditor, section) => {
let thisSection = section || editor.range.headSection;
let card = postEditor.builder.createCardSection('card-image', {pos: 'top'});
console.log(editor.range.headSection.text.length);
if (section || editor.range.headSection.text.length) {
if (thisSection.text.length) {
postEditor.insertSection(card);
} else {
postEditor.replaceSection(section || editor.range.headSection, card);
postEditor.replaceSection(thisSection, card);
}
// insert empty paragraph after card if it's the last element.
if(!thisSection.next) {
let newSection = editor.builder.createMarkupSection('p');
postEditor.insertSectionAtEnd(newSection);
}

});
},
checkElements(elements) {
Expand All @@ -224,15 +228,18 @@ export default function (editor, toolbar) {
cardMenu: true,
onClick: (editor, section) => {
editor.run((postEditor) => {
let card = postEditor.builder.createCardSection('card-html', {pos: 'top', html: editor.range.headSection.text});
let thisSection = section || editor.range.headSection;
let card = postEditor.builder.createCardSection('card-html', {pos: 'top', html: thisSection.text});
// we can't replace a list item so we insert a card after it and then delete it.
if (editor.range.headSection.isListItem) {
// postEditor.toggleSection('p');
// postEditor.insertSection(card);
// postEditor.removeSection(editor.range.head.section);
if (thisSection.isListItem) {
editor.insertCard('card-html');
} else {
postEditor.replaceSection(section || editor.range.headSection, card);
postEditor.replaceSection(thisSection, card);
}

if(!thisSection.next) {
let newSection = editor.builder.createMarkupSection('p');
postEditor.insertSectionAtEnd(newSection);
}
});
},
Expand All @@ -249,10 +256,16 @@ export default function (editor, toolbar) {
visibility: 'primary',
order: 4,
cardMenu: true,
onClick: (editor) => {
onClick: (editor, section) => {
editor.run((postEditor) => {
let thisSection = section || editor.range.headSection;
let card = postEditor.builder.createCardSection('card-hr', {pos: 'top'});
postEditor.insertSection(card);

if(!thisSection.next) {
let newSection = editor.builder.createMarkupSection('p');
postEditor.insertSectionAtEnd(newSection);
}
});
},
checkElements() {
Expand All @@ -269,12 +282,18 @@ export default function (editor, toolbar) {
cardMenu: true,
onClick: (editor, section) => {
editor.run((postEditor) => {
let card = postEditor.builder.createCardSection('card-markdown', {pos: 'top', markdown: editor.range.headSection.text, newlyCreated: true});
let thisSection = section || editor.range.headSection;
let card = postEditor.builder.createCardSection('card-markdown', {pos: 'top', markdown: thisSection.text, newlyCreated: true});
// we can't replace a list item so we insert a card after it and then delete it.
if (editor.range.headSection.isListItem) {
if (thisSection.isListItem) {
editor.insertCard('card-markdown');
} else {
postEditor.replaceSection(section || editor.range.headSection, card);
postEditor.replaceSection(thisSection, card);
}
// if this is the last element then insert a paragraph after the card
if(!thisSection.next) {
let newSection = editor.builder.createMarkupSection('p');
postEditor.insertSectionAtEnd(newSection);
}
});
},
Expand Down

0 comments on commit d65d0eb

Please sign in to comment.