Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #694: Alignment of a section is removed when pressing "Enter" #695

Merged
merged 1 commit into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
});