Skip to content

Commit

Permalink
Create default markup section when hitting enter
Browse files Browse the repository at this point in the history
  • Loading branch information
bantic committed Sep 3, 2015
1 parent f5871fc commit d348d06
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/js/models/markup-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ const MarkupSection = class MarkupSection extends Markerable {
splitAtMarker(marker, offset=0) {
let [beforeSection, afterSection] = [
this.builder.createMarkupSection(this.tagName, []),
// FIXME we probably want to make it so that we create a new default markup
// section instead of copying the same tagname to the section below
this.builder.createMarkupSection(this.tagName, [])
this.builder.createMarkupSection()
];

return this._redistributeMarkers(beforeSection, afterSection, marker, offset);
Expand Down
19 changes: 19 additions & 0 deletions tests/acceptance/editor-sections-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,25 @@ test('hitting enter at end of a section creates new empty section', (assert) =>
assert.hasElement('#editor p:eq(1):contains(X)', 'text is inserted in the new section');
});

test('hitting enter in a section creates a new basic section', (assert) => {
const mobiledoc = Helpers.mobiledoc.build(({post, markupSection, marker}) =>
post([
markupSection('h2', [marker('abc')])
])
);
editor = new Editor({mobiledoc});
editor.render(editorElement);
assert.hasElement('#editor h2:contains(abc)', 'precond - h2 is there');
assert.hasNoElement('#editor p', 'precond - no p tag');

Helpers.dom.moveCursorTo($('#editor h2')[0].childNodes[0], 'abc'.length);
Helpers.dom.triggerEnter(editor);
Helpers.dom.insertText('X');

assert.hasElement('#editor h2:contains(abc)', 'h2 still there');
assert.hasElement('#editor p:contains(X)', 'p tag instead of h2 generated');
});

// Phantom does not recognize toggling contenteditable off
Helpers.skipInPhantom('deleting across 2 sections does nothing if editing is disabled', (assert) => {
editor = new Editor({mobiledoc: mobileDocWith2Sections});
Expand Down

0 comments on commit d348d06

Please sign in to comment.