Skip to content

Commit

Permalink
ensure starting with an empty editor generates a block tag
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoitch committed Jan 29, 2015
1 parent a7e39be commit 5e834d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/js/content-kit-editor/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@ function bindContentEditableTypingListeners(editor) {
if (!selectionTag || selectionTag === Type.QUOTE.tag) {
document.execCommand('formatBlock', false, Type.PARAGRAPH.tag);
}
} else if (e.which === Keycodes.BKSP) {
if (!editor.element.innerHTML) {
// On backspace of the last letter, make sure to generate a 'p' tag
document.execCommand('formatBlock', false, Type.PARAGRAPH.tag);
} //else {
// TODO: need to rerender when backspacing 2 blocks together
//}
}// else if (e.which === Keycodes.BKSP) {
// TODO: need to rerender when backspacing 2 blocks together
//}

// Assure there is always a supported block tag, and not empty text nodes or divs.
if (!getSelectionBlockElement()) {
document.execCommand('formatBlock', false, Type.PARAGRAPH.tag);
}
});

Expand Down
4 changes: 3 additions & 1 deletion src/js/content-kit-editor/utils/selection-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ function getSelectionBlockElement(selection) {
var element = getSelectionElement();
var tag = element && element.tagName.toLowerCase();
while (tag && RootTags.indexOf(tag) === -1) {
if (element.contentEditable === 'true') { return; } // Stop traversing up dom when hitting an editor element
if (element.contentEditable === 'true') {
return null; // Stop traversing up dom when hitting an editor element
}
element = element.parentNode;
tag = element.tagName && element.tagName.toLowerCase();
}
Expand Down

0 comments on commit 5e834d5

Please sign in to comment.