Skip to content

Commit 4fadc60

Browse files
YoranBrondsemaZeeJab
authored andcommitted
Fix #694: Alignment of a section is removed when pressing "Enter"
1 parent 2adb542 commit 4fadc60

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

src/js/editor/post.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ class PostEditor {
941941
*/
942942
_splitListAtItem(list, item) {
943943
let next = list;
944-
let prev = this.builder.createListSection(next.tagName);
944+
let prev = this.builder.createListSection(next.tagName, [], next.attributes);
945945
let mid = this.builder.createListSection(next.tagName);
946946

947947
let addToPrev = true;

src/js/models/markup-section.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const MarkupSection = class MarkupSection extends Markerable {
5151

5252
splitAtMarker(marker, offset=0) {
5353
let [beforeSection, afterSection] = [
54-
this.builder.createMarkupSection(this.tagName, []),
54+
this.builder.createMarkupSection(this.tagName, [], false, this.attributes),
5555
this.builder.createMarkupSection()
5656
];
5757

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import Helpers from '../test-helpers';
2+
3+
const { module, test } = Helpers;
4+
5+
let editor, editorElement;
6+
7+
function renderEditor(...args) {
8+
editor = Helpers.mobiledoc.renderInto(editorElement, ...args);
9+
editor.selectRange(editor.post.tailPosition());
10+
return editor;
11+
}
12+
13+
module('Acceptance: Editor: Attributes', {
14+
beforeEach() {
15+
editorElement = $('#editor')[0];
16+
},
17+
afterEach() {
18+
if (editor) { editor.destroy(); }
19+
}
20+
});
21+
22+
test('pressing ENTER at the end of an aligned paragraph maintains the alignment (bug #694)', (assert) => {
23+
renderEditor(({post, markupSection, marker}) => {
24+
return post([
25+
markupSection(
26+
'p',
27+
[marker('abc')],
28+
false,
29+
{ 'data-md-text-align': 'center' }
30+
)
31+
]);
32+
});
33+
34+
Helpers.dom.triggerEnter(editor);
35+
36+
const firstParagraph = document.querySelector('#editor p:first-of-type');
37+
assert.equal(firstParagraph.getAttribute('data-md-text-align'), 'center');
38+
});
39+
40+
test('toggling the section inside an aligned list maintains the alignment of the list (bug #694)', (assert) => {
41+
renderEditor(({post, listSection, listItem, marker}) => {
42+
return post([
43+
listSection(
44+
'ul',
45+
[
46+
listItem([marker('abc')]),
47+
listItem([marker('123')])
48+
],
49+
{ 'data-md-text-align': 'center' }
50+
)
51+
]);
52+
});
53+
54+
editor.run(postEditor => postEditor.toggleSection('h1'));
55+
56+
const ul = document.querySelector('#editor ul');
57+
assert.equal(ul.getAttribute('data-md-text-align'), 'center');
58+
});

0 commit comments

Comments
 (0)