Skip to content

Commit

Permalink
Merge pull request #695 from YoranBrondsema/fix-694
Browse files Browse the repository at this point in the history
Fix #694: Alignment of a section is removed when pressing "Enter"
  • Loading branch information
ZeeJab committed Sep 20, 2019
2 parents 2adb542 + 4fadc60 commit ac5a1bb
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/js/editor/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ class PostEditor {
*/
_splitListAtItem(list, item) {
let next = list;
let prev = this.builder.createListSection(next.tagName);
let prev = this.builder.createListSection(next.tagName, [], next.attributes);
let mid = this.builder.createListSection(next.tagName);

let addToPrev = true;
Expand Down
2 changes: 1 addition & 1 deletion src/js/models/markup-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const MarkupSection = class MarkupSection extends Markerable {

splitAtMarker(marker, offset=0) {
let [beforeSection, afterSection] = [
this.builder.createMarkupSection(this.tagName, []),
this.builder.createMarkupSection(this.tagName, [], false, this.attributes),
this.builder.createMarkupSection()
];

Expand Down
58 changes: 58 additions & 0 deletions tests/acceptance/editor-attributes-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import Helpers from '../test-helpers';

const { module, test } = Helpers;

let editor, editorElement;

function renderEditor(...args) {
editor = Helpers.mobiledoc.renderInto(editorElement, ...args);
editor.selectRange(editor.post.tailPosition());
return editor;
}

module('Acceptance: Editor: Attributes', {
beforeEach() {
editorElement = $('#editor')[0];
},
afterEach() {
if (editor) { editor.destroy(); }
}
});

test('pressing ENTER at the end of an aligned paragraph maintains the alignment (bug #694)', (assert) => {
renderEditor(({post, markupSection, marker}) => {
return post([
markupSection(
'p',
[marker('abc')],
false,
{ 'data-md-text-align': 'center' }
)
]);
});

Helpers.dom.triggerEnter(editor);

const firstParagraph = document.querySelector('#editor p:first-of-type');
assert.equal(firstParagraph.getAttribute('data-md-text-align'), 'center');
});

test('toggling the section inside an aligned list maintains the alignment of the list (bug #694)', (assert) => {
renderEditor(({post, listSection, listItem, marker}) => {
return post([
listSection(
'ul',
[
listItem([marker('abc')]),
listItem([marker('123')])
],
{ 'data-md-text-align': 'center' }
)
]);
});

editor.run(postEditor => postEditor.toggleSection('h1'));

const ul = document.querySelector('#editor ul');
assert.equal(ul.getAttribute('data-md-text-align'), 'center');
});

0 comments on commit ac5a1bb

Please sign in to comment.