diff --git a/dist/content-kit-editor.js b/dist/content-kit-editor.js index d10f97ef0..c8484ff96 100644 --- a/dist/content-kit-editor.js +++ b/dist/content-kit-editor.js @@ -1,6 +1,6 @@ /** * @overview content-kit-editor: A modern, minimalist WYSIWYG editor. - * @version 0.1.1 + * @version 0.1.2 * @author Garth Poitras (http://garthpoitras.com/) * @license MIT * Last modified: Feb 26, 2015 @@ -2257,18 +2257,23 @@ }) }; - function $$editor$$isNaughtyKeystroke(e) { - return (!e.shiftKey && e.which === $$$utils$keycodes$$default.ENTER) || - (e.ctrlKey && e.which === $$$utils$keycodes$$default.M) || - (e.which === $$$utils$keycodes$$default.BKSP); - } - function $$editor$$bindContentEditableTypingListeners(editor) { - editor.element.addEventListener('keydown', function(e) { - if ($$editor$$isNaughtyKeystroke(e)) { - e.preventDefault(); - } + + editor.element.addEventListener('keyup', function(e) { + // Assure there is always a supported block tag, and not empty text nodes or divs. + // On a carrage return, make sure to always generate a 'p' tag + if (!$$$utils$selection$utils$$getSelectionBlockElement() || + !editor.element.textContent || + (!e.shiftKey && e.which === $$$utils$keycodes$$default.ENTER) || (e.ctrlKey && e.which === $$$utils$keycodes$$default.M)) { + document.execCommand('formatBlock', false, node_modules$content$kit$compiler$src$types$type$$default.PARAGRAPH.tag); + } //else if (e.which === Keycodes.BKSP) { + // TODO: Need to rerender when backspacing 2 blocks together + //var cursorIndex = editor.getCursorIndexInCurrentBlock(); + //var currentBlockElement = getSelectionBlockElement(); + //editor.renderBlockAt(editor.getCurrentBlockIndex(), true); + //setCursorIndexInElement(currentBlockElement, cursorIndex); + //} }); // On 'PASTE' sanitize and insert diff --git a/package.json b/package.json index 8723f699d..95e892548 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "content-kit-editor", - "version": "0.1.2", + "version": "0.1.3", "description": "A modern, minimalist WYSIWYG editor.", "repository": "https://github.com/bustlelabs/content-kit-editor", "main": "dist/content-kit-editor.js", diff --git a/src/js/editor/editor.js b/src/js/editor/editor.js index 1b8ff4254..1e43bfb28 100644 --- a/src/js/editor/editor.js +++ b/src/js/editor/editor.js @@ -49,18 +49,23 @@ var defaults = { }) }; -function isNaughtyKeystroke(e) { - return (!e.shiftKey && e.which === Keycodes.ENTER) || - (e.ctrlKey && e.which === Keycodes.M) || - (e.which === Keycodes.BKSP); -} - function bindContentEditableTypingListeners(editor) { - editor.element.addEventListener('keydown', function(e) { - if (isNaughtyKeystroke(e)) { - e.preventDefault(); - } + + editor.element.addEventListener('keyup', function(e) { + // Assure there is always a supported block tag, and not empty text nodes or divs. + // On a carrage return, make sure to always generate a 'p' tag + if (!getSelectionBlockElement() || + !editor.element.textContent || + (!e.shiftKey && e.which === Keycodes.ENTER) || (e.ctrlKey && e.which === Keycodes.M)) { + document.execCommand('formatBlock', false, Type.PARAGRAPH.tag); + } //else if (e.which === Keycodes.BKSP) { + // TODO: Need to rerender when backspacing 2 blocks together + //var cursorIndex = editor.getCursorIndexInCurrentBlock(); + //var currentBlockElement = getSelectionBlockElement(); + //editor.renderBlockAt(editor.getCurrentBlockIndex(), true); + //setCursorIndexInElement(currentBlockElement, cursorIndex); + //} }); // On 'PASTE' sanitize and insert