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

when caret is at the end of blockquote and you press enter, create paragraph, not another blockquote #1162

Merged
merged 2 commits into from
Jul 30, 2016
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
29 changes: 29 additions & 0 deletions spec/content.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,35 @@ describe('Content TestCase', function () {
});
expect(document.execCommand).toHaveBeenCalledWith('unlink', false, null);
});

describe('within a blockquote element', function () {

it('at the end of the blockquote, p tag should be created next, not blockquote', function () {
this.el.innerHTML = '<blockquote>lorem ipsum</blockquote>';
var editor = this.newMediumEditor('.editor'),
target = editor.elements[0].querySelector('blockquote').firstChild;

placeCursorInsideElement(target, target.textContent.length);
fireEvent(target, 'keydown', {
keyCode: MediumEditor.util.keyCode.ENTER
});

expect(this.el.innerHTML).toBe('<blockquote>lorem ipsum</blockquote><p><br></p>');
});

it('NOT at the start of the blockqoute, no formatting should be changed', function () {
this.el.innerHTML = '<blockquote>lorem ipsum</blockquote>';
var editor = this.newMediumEditor('.editor'),
target = editor.elements[0].querySelector('blockquote').firstChild;

placeCursorInsideElement(target, 0);
fireEvent(target, 'keydown', {
keyCode: MediumEditor.util.keyCode.ENTER
});

expect(this.el.innerHTML).toBe('<blockquote>lorem ipsum</blockquote>');
});
});
});

describe('when the ctrl key and m key is pressed', function () {
Expand Down
14 changes: 14 additions & 0 deletions src/js/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,20 @@
// then pressing backspace key should change the <blockquote> to a <p> tag
event.preventDefault();
MediumEditor.util.execFormatBlock(this.options.ownerDocument, 'p');
} else if (MediumEditor.util.isKey(event, MediumEditor.util.keyCode.ENTER) &&
(MediumEditor.util.getClosestTag(node, 'blockquote') !== false) &&
MediumEditor.selection.getCaretOffsets(node).right === 0) {

// when cursor is at the end of <blockquote>,
// then pressing enter key should create <p> tag, not <blockquote>
p = this.options.ownerDocument.createElement('p');
p.innerHTML = '<br>';
node.parentElement.insertBefore(p, node.nextSibling);

// move the cursor into the new paragraph
MediumEditor.selection.moveCursor(this.options.ownerDocument, p);

event.preventDefault();
}
}

Expand Down