import { Pipeline } from '@ephox/agar'; import { LegacyUnit, TinyLoader } from '@ephox/mcagar'; import Env from 'tinymce/core/api/Env'; import HtmlUtils from '../../module/test/HtmlUtils'; import Tools from 'tinymce/core/api/util/Tools'; import Theme from 'tinymce/themes/modern/Theme'; import { UnitTest } from '@ephox/bedrock'; UnitTest.asynctest('browser.tinymce.core.keyboard.EnterKey', function () { const success = arguments[arguments.length - 2]; const failure = arguments[arguments.length - 1]; const suite = LegacyUnit.createSuite(); Theme(); const pressEnter = function (editor, evt?) { const dom = editor.dom, target = editor.selection.getNode(); evt = Tools.extend({ keyCode: 13, shiftKey: false }, evt); dom.fire(target, 'keydown', evt); dom.fire(target, 'keypress', evt); dom.fire(target, 'keyup', evt); }; suite.test('Enter at end of H1', function (editor) { editor.setContent('

abc

'); LegacyUnit.setSelection(editor, 'h1', 3); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

\u00a0

'); LegacyUnit.equal(editor.selection.getRng(true).startContainer.nodeName, 'P'); }); suite.test('Enter in midde of H1', function (editor) { editor.setContent('

abcd

'); LegacyUnit.setSelection(editor, 'h1', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

ab

cd

'); LegacyUnit.equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'H1'); }); suite.test('Enter before text after EM', function (editor) { editor.setContent('

ab

'); editor.selection.setCursorLocation(editor.getBody().firstChild, 1); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

a

b

'); const rng = editor.selection.getRng(true); LegacyUnit.equal(rng.startContainer.nodeValue, 'b'); }); suite.test('Enter before first IMG in P', function (editor) { editor.setContent('

'); editor.selection.setCursorLocation(editor.getBody().firstChild, 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

\u00a0

'); }); suite.test('Enter before first wrapped IMG in P', function (editor) { editor.setContent('

'); editor.selection.setCursorLocation(editor.getBody().firstChild.firstChild, 0); pressEnter(editor); LegacyUnit.equal(editor.getBody().firstChild.innerHTML, (Env.ie && Env.ie < 11) ? '' : '
'); LegacyUnit.equal(editor.getContent(), '

\u00a0

'); }); suite.test('Enter before last IMG in P with text', function (editor) { editor.setContent('

abc

'); editor.selection.setCursorLocation(editor.getBody().firstChild, 1); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

'); const rng = editor.selection.getRng(true); LegacyUnit.equal(rng.startContainer.nodeName, 'P'); LegacyUnit.equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'IMG'); }); suite.test('Enter before last IMG in P with IMG sibling', function (editor) { editor.setContent('

'); editor.selection.setCursorLocation(editor.getBody().firstChild, 1); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

'); const rng = editor.selection.getRng(true); LegacyUnit.equal(rng.startContainer.nodeName, 'P'); LegacyUnit.equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'IMG'); }); suite.test('Enter after last IMG in P', function (editor) { editor.setContent('

abc

'); editor.selection.setCursorLocation(editor.getBody().firstChild, 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

\u00a0

'); }); suite.test('Enter before last INPUT in P with text', function (editor) { editor.setContent('

abc

'); editor.selection.setCursorLocation(editor.getBody().firstChild, 1); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

'); const rng = editor.selection.getRng(true); LegacyUnit.equal(rng.startContainer.nodeName, 'P'); LegacyUnit.equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'INPUT'); }); suite.test('Enter before last INPUT in P with IMG sibling', function (editor) { editor.setContent('

'); editor.selection.setCursorLocation(editor.getBody().firstChild, 1); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

'); const rng = editor.selection.getRng(true); LegacyUnit.equal(rng.startContainer.nodeName, 'P'); LegacyUnit.equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'INPUT'); }); suite.test('Enter after last INPUT in P', function (editor) { editor.setContent('

abc

'); editor.selection.setCursorLocation(editor.getBody().firstChild, 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

\u00a0

'); }); suite.test('Enter at end of P', function (editor) { editor.setContent('

abc

'); LegacyUnit.setSelection(editor, 'p', 3); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

\u00a0

'); LegacyUnit.equal(editor.selection.getRng(true).startContainer.nodeName, 'P'); }); suite.test('Enter at end of EM inside P', function (editor) { editor.setContent('

abc

'); LegacyUnit.setSelection(editor, 'em', 3); pressEnter(editor); LegacyUnit.equal( HtmlUtils.cleanHtml(editor.getBody().innerHTML).replace(/]+|)>| /g, ''), '

abc

' ); LegacyUnit.equal(editor.selection.getRng(true).startContainer.nodeName, 'EM'); }); suite.test('Enter at middle of EM inside P', function (editor) { editor.setContent('

abcd

'); LegacyUnit.setSelection(editor, 'em', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

ab

cd

'); LegacyUnit.equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'EM'); }); suite.test('Enter at beginning EM inside P', function (editor) { editor.setContent('

abc

'); LegacyUnit.setSelection(editor, 'em', 0); pressEnter(editor); LegacyUnit.equal( HtmlUtils.cleanHtml(editor.getBody().innerHTML).replace(/]+|)>| /g, ''), '

abc

' ); LegacyUnit.equal(editor.selection.getRng(true).startContainer.nodeValue, 'abc'); }); suite.test('Enter at end of STRONG in EM inside P', function (editor) { editor.setContent('

abc

'); LegacyUnit.setSelection(editor, 'strong', 3); pressEnter(editor); LegacyUnit.equal( HtmlUtils.cleanHtml(editor.getBody().innerHTML).replace(/]+|)>| /g, ''), '

abc

' ); LegacyUnit.equal(editor.selection.getRng(true).startContainer.nodeName, 'STRONG'); }); suite.test('Enter at middle of STRONG in EM inside P', function (editor) { editor.setContent('

abcd

'); LegacyUnit.setSelection(editor, 'strong', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

ab

cd

'); LegacyUnit.equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'STRONG'); }); suite.test('Enter at beginning STRONG in EM inside P', function (editor) { editor.setContent('

abc

'); LegacyUnit.setSelection(editor, 'strong', 0); pressEnter(editor); LegacyUnit.equal( HtmlUtils.cleanHtml(editor.getBody().innerHTML).replace(/]+|)>| /g, ''), '

abc

' ); LegacyUnit.equal(editor.selection.getRng(true).startContainer.nodeValue, 'abc'); }); suite.test('Enter at beginning of P', function (editor) { editor.setContent('

abc

'); LegacyUnit.setSelection(editor, 'p', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

\u00a0

abc

'); LegacyUnit.equal(editor.selection.getRng(true).startContainer.nodeValue, 'abc'); }); suite.test('Enter at middle of P with style, id and class attributes', function (editor) { editor.setContent('

abcd

'); LegacyUnit.setSelection(editor, 'p', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

ab

cd

'); LegacyUnit.equal(editor.selection.getRng(true).startContainer.parentNode.nodeName, 'P'); }); suite.test('Enter at a range between H1 and P', function (editor) { editor.setContent('

abcd

efgh

'); LegacyUnit.setSelection(editor, 'h1', 2, 'p', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

ab

gh

'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'H1'); }); suite.test('Enter at a range between LI elements', function (editor) { editor.setContent('
  • abcd
  • efgh
'); LegacyUnit.setSelection(editor, 'li:nth-child(1)', 2, 'li:nth-child(2)', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '
  • ab
  • gh
'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'LI'); }); suite.test('Enter at end of H1 in HGROUP', function (editor) { editor.setContent('

abc

'); LegacyUnit.setSelection(editor, 'h1', 3); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

\u00a0

'); LegacyUnit.equal(editor.selection.getRng(true).startContainer.nodeName, 'H1'); }); suite.test('Enter inside empty TD', function (editor) { editor.getBody().innerHTML = '
'; LegacyUnit.setSelection(editor, 'td', 0); pressEnter(editor); LegacyUnit.equal( HtmlUtils.cleanHtml(editor.getBody().innerHTML).replace(/]+|)>| /g, ''), '

' ); LegacyUnit.equal(editor.selection.getNode().nodeName, 'P'); }); suite.test('Shift+Enter inside STRONG inside TD with BR', function (editor) { editor.getBody().innerHTML = '
d e
'; LegacyUnit.setSelection(editor, 'strong', 1); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal( HtmlUtils.cleanHtml(editor.getBody().innerHTML), '
d e

' ); LegacyUnit.equal(editor.selection.getNode().nodeName, 'STRONG'); }); suite.test('Enter inside middle of text node in body', function (editor) { editor.getBody().innerHTML = 'abcd'; LegacyUnit.setSelection(editor, 'body', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

ab

cd

'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'P'); }); suite.test('Enter inside at beginning of text node in body', function (editor) { editor.getBody().innerHTML = 'abcd'; LegacyUnit.setSelection(editor, 'body', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

\u00a0

abcd

'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'P'); }); suite.test('Enter inside at end of text node in body', function (editor) { editor.getBody().innerHTML = 'abcd'; LegacyUnit.setSelection(editor, 'body', 4); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abcd

\u00a0

'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'P'); }); suite.test('Enter inside empty body', function (editor) { editor.getBody().innerHTML = ''; LegacyUnit.setSelection(editor, 'body', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

\u00a0

\u00a0

'); LegacyUnit.equal(editor.selection.getNode().nodeName, 'P'); }); suite.test('Enter in the middle of text in P with forced_root_block set to false', function (editor) { editor.settings.forced_root_block = false; editor.getBody().innerHTML = '

abc

'; LegacyUnit.setSelection(editor, 'p', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

ab
c

'); }); suite.test('Enter at the end of text in P with forced_root_block set to false', function (editor) { editor.settings.forced_root_block = false; editor.getBody().innerHTML = '

abc

'; LegacyUnit.setSelection(editor, 'p', 3); pressEnter(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), (Env.ie && Env.ie < 11) ? '

abc

' : '

abc

'); editor.settings.forced_root_block = 'p'; }); suite.test('Enter at the middle of text in BODY with forced_root_block set to false', function (editor) { editor.settings.forced_root_block = false; editor.getBody().innerHTML = 'abcd'; LegacyUnit.setSelection(editor, 'body', 2); editor.focus(); pressEnter(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), 'ab
cd'); editor.settings.forced_root_block = 'p'; }); suite.test('Enter at the beginning of text in BODY with forced_root_block set to false', function (editor) { editor.settings.forced_root_block = false; editor.getBody().innerHTML = 'abcd'; LegacyUnit.setSelection(editor, 'body', 0); editor.focus(); pressEnter(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), '
abcd'); editor.settings.forced_root_block = 'p'; }); suite.test('Enter at the end of text in BODY with forced_root_block set to false', function (editor) { editor.settings.forced_root_block = false; editor.getBody().innerHTML = 'abcd'; LegacyUnit.setSelection(editor, 'body', 4); editor.focus(); pressEnter(editor); LegacyUnit.equal(HtmlUtils.cleanHtml(editor.getBody().innerHTML), (Env.ie && Env.ie < 11) ? 'abcd
' : 'abcd

'); editor.settings.forced_root_block = 'p'; }); suite.test('Enter in empty P at the end of a blockquote and end_container_on_empty_block: true', function (editor) { editor.settings.end_container_on_empty_block = true; editor.getBody().innerHTML = (Env.ie && Env.ie < 11) ? '

abc

' : '

abc


'; LegacyUnit.setSelection(editor, 'p:last', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

\u00a0

'); editor.settings.forced_root_block = 'p'; }); suite.test('Enter in empty P at the beginning of a blockquote and end_container_on_empty_block: true', function (editor) { editor.settings.end_container_on_empty_block = true; editor.getBody().innerHTML = (Env.ie && Env.ie < 11) ? '

abc

' : '


abc

'; LegacyUnit.setSelection(editor, 'p', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

\u00a0

abc

'); editor.settings.forced_root_block = 'p'; }); suite.test('Enter in empty P at in the middle of a blockquote and end_container_on_empty_block: true', function (editor) { editor.settings.end_container_on_empty_block = true; editor.getBody().innerHTML = (Env.ie && Env.ie < 11) ? '

abc

123

' : '

abc


123

'; LegacyUnit.setSelection(editor, 'p:nth-child(2)', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

\u00a0

123

'); editor.settings.forced_root_block = 'p'; }); suite.test('Enter in empty P at in the middle of a blockquote and end_container_on_empty_block: true', function (editor) { editor.settings.end_container_on_empty_block = true; editor.getBody().innerHTML = '

abc

\u00a0


123

'; LegacyUnit.setSelection(editor, 'p:nth-child(3)', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

\u00a0

\u00a0

123

'); editor.settings.forced_root_block = 'p'; }); suite.test('Enter inside empty P with empty P siblings', function (editor) { // Tests that a workaround for an IE bug is working correctly editor.getBody().innerHTML = '

X

'; LegacyUnit.setSelection(editor, 'p', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

\u00a0

\u00a0

\u00a0

X

'); }); suite.test('Enter at end of H1 with forced_root_block_attrs', function (editor) { editor.settings.forced_root_block_attrs = { class: 'class1' }; editor.getBody().innerHTML = '

a

'; LegacyUnit.setSelection(editor, 'h1', 1); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

a

\u00a0

'); delete editor.settings.forced_root_block_attrs; }); suite.test('Shift+Enter at beginning of P', function (editor) { editor.getBody().innerHTML = '

abc

'; LegacyUnit.setSelection(editor, 'p', 0); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '


abc

'); }); suite.test('Shift+Enter in the middle of P', function (editor) { editor.getBody().innerHTML = '

abcd

'; LegacyUnit.setSelection(editor, 'p', 2); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '

ab
cd

'); }); suite.test('Shift+Enter at the end of P', function (editor) { editor.getBody().innerHTML = '

abcd

'; LegacyUnit.setSelection(editor, 'p', 4); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), (Env.ie && Env.ie < 11) ? '

abcd

' : '

abcd

'); }); suite.test('Shift+Enter in the middle of B with a BR after it', function (editor) { editor.getBody().innerHTML = '

abcd

'; LegacyUnit.setSelection(editor, 'b', 2); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '

ab
cd

'); }); suite.test('Shift+Enter at the end of B with a BR after it', function (editor) { editor.getBody().innerHTML = '

abcd

'; LegacyUnit.setSelection(editor, 'b', 4); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '

abcd

'); }); suite.test('Enter in beginning of PRE', function (editor) { editor.getBody().innerHTML = '
abc
'; LegacyUnit.setSelection(editor, 'pre', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc
'); }); suite.test('Enter in the middle of PRE', function (editor) { editor.getBody().innerHTML = '
abcd
'; LegacyUnit.setSelection(editor, 'pre', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '
ab
cd
'); }); suite.test('Enter at the end of PRE', function (editor) { editor.getBody().innerHTML = '
abcd
'; LegacyUnit.setSelection(editor, 'pre', 4); pressEnter(editor); LegacyUnit.equal(editor.getContent(), (Env.ie && Env.ie < 11) ? '
abcd
' : '
abcd

'); }); suite.test('Enter in beginning of PRE and br_in_pre: false', function (editor) { editor.settings.br_in_pre = false; editor.getBody().innerHTML = '
abc
'; LegacyUnit.setSelection(editor, 'pre', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '
\u00a0
abc
'); delete editor.settings.br_in_pre; }); suite.test('Enter in the middle of PRE and br_in_pre: false', function (editor) { editor.settings.br_in_pre = false; editor.getBody().innerHTML = '
abcd
'; LegacyUnit.setSelection(editor, 'pre', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '
ab
cd
'); delete editor.settings.br_in_pre; }); suite.test('Enter at the end of PRE and br_in_pre: false', function (editor) { editor.settings.br_in_pre = false; editor.getBody().innerHTML = '
abcd
'; LegacyUnit.setSelection(editor, 'pre', 4); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '
abcd

\u00a0

'); delete editor.settings.br_in_pre; }); suite.test('Shift+Enter in beginning of PRE', function (editor) { editor.getBody().innerHTML = '
abc
'; LegacyUnit.setSelection(editor, 'pre', 0); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '
\u00a0
abc
'); }); suite.test('Shift+Enter in the middle of PRE', function (editor) { editor.getBody().innerHTML = '
abcd
'; LegacyUnit.setSelection(editor, 'pre', 2); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '
ab
cd
'); }); suite.test('Shift+Enter at the end of PRE', function (editor) { editor.getBody().innerHTML = '
abcd
'; LegacyUnit.setSelection(editor, 'pre', 4); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '
abcd

\u00a0

'); }); suite.test('Shift+Enter in beginning of P with forced_root_block set to false', function (editor) { editor.settings.forced_root_block = false; editor.getBody().innerHTML = '

abc

'; LegacyUnit.setSelection(editor, 'p', 0); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '

\u00a0

abc

'); editor.settings.forced_root_block = 'p'; }); suite.test('Shift+Enter in middle of P with forced_root_block set to false', function (editor) { editor.settings.forced_root_block = false; editor.getBody().innerHTML = '

abcd

'; LegacyUnit.setSelection(editor, 'p', 2); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '

ab

cd

'); editor.settings.forced_root_block = 'p'; }); suite.test('Shift+Enter at the end of P with forced_root_block set to false', function (editor) { editor.settings.forced_root_block = false; editor.getBody().innerHTML = '

abc

'; LegacyUnit.setSelection(editor, 'p', 3); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '

abc

\u00a0

'); editor.settings.forced_root_block = 'p'; }); suite.test('Shift+Enter in body with forced_root_block set to false', function (editor) { editor.settings.forced_root_block = false; editor.getBody().innerHTML = 'abcd'; const rng = editor.dom.createRng(); rng.setStart(editor.getBody().firstChild, 2); rng.setEnd(editor.getBody().firstChild, 2); editor.selection.setRng(rng); pressEnter(editor, { shiftKey: true }); LegacyUnit.equal(editor.getContent(), '

ab

cd

'); editor.settings.forced_root_block = 'p'; }); suite.test('Enter at the end of DIV layer', function (editor) { editor.settings.br_in_pre = false; editor.setContent('
abcd
'); LegacyUnit.setSelection(editor, 'div', 4); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abcd

\u00a0

'); delete editor.settings.br_in_pre; }); suite.test('Enter at end of text in a span inside a P and keep_styles: false', function (editor) { editor.settings.keep_styles = false; editor.getBody().innerHTML = '

X

'; LegacyUnit.setSelection(editor, 'span', 1); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

X

\u00a0

'); delete editor.settings.keep_styles; }); suite.test( 'keep_styles=false: P should not pass its styles and classes to the new P that is cloned from it when enter is pressed', function (editor) { editor.settings.keep_styles = false; editor.getBody().innerHTML = '

X

'; LegacyUnit.setSelection(editor, 'span', 1); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

X

\u00a0

'); delete editor.settings.keep_styles; }); suite.test('Enter when forced_root_block: false and force_p_newlines: true', function (editor) { editor.settings.forced_root_block = false; editor.settings.force_p_newlines = true; editor.getBody().innerHTML = 'text'; LegacyUnit.setSelection(editor, 'body', 2); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

te

xt

'); editor.settings.forced_root_block = 'p'; delete editor.settings.force_p_newlines; }); suite.test('Enter at end of br line', function (editor) { editor.settings.forced_root_block = false; editor.settings.force_p_newlines = true; editor.getBody().innerHTML = '

a
b

'; LegacyUnit.setSelection(editor, 'p', 1); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

a


b

'); const rng = editor.selection.getRng(true); LegacyUnit.equal(rng.startContainer.nodeName, 'P'); LegacyUnit.equal(rng.startContainer.childNodes[rng.startOffset].nodeName, 'BR'); editor.settings.forced_root_block = 'p'; delete editor.settings.force_p_newlines; }); // Ignore on IE 7, 8 this is a known bug not worth fixing if (!Env.ie || Env.ie > 8) { suite.test('Enter before BR between DIVs', function (editor) { editor.getBody().innerHTML = '
abc

d
'; const rng = editor.dom.createRng(); rng.setStartBefore(editor.dom.select('br')[0]); rng.setEndBefore(editor.dom.select('br')[0]); editor.selection.setRng(rng); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '
abc

\u00a0

\u00a0

d
'); }); } // Only test these on modern browsers suite.test('Enter behind table element', function (editor) { const rng = editor.dom.createRng(); editor.getBody().innerHTML = '
x
'; rng.setStartAfter(editor.getBody().lastChild); rng.setEndAfter(editor.getBody().lastChild); editor.selection.setRng(rng); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '
x

\u00a0

'); }); suite.test('Enter before table element', function (editor) { const rng = editor.dom.createRng(); editor.getBody().innerHTML = '
x
'; rng.setStartBefore(editor.getBody().lastChild); rng.setEndBefore(editor.getBody().lastChild); editor.selection.setRng(rng); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

\u00a0

x
'); }); suite.test('Enter behind table followed by a p', function (editor) { const rng = editor.dom.createRng(); editor.getBody().innerHTML = '
x

x

'; rng.setStartAfter(editor.getBody().firstChild); rng.setEndAfter(editor.getBody().firstChild); editor.selection.setRng(rng); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '
x

\u00a0

x

'); }); suite.test('Enter before table element preceded by a p', function (editor) { const rng = editor.dom.createRng(); editor.getBody().innerHTML = '

x

x
'; rng.setStartBefore(editor.getBody().lastChild); rng.setStartBefore(editor.getBody().lastChild); editor.selection.setRng(rng); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

x

\u00a0

x
'); }); suite.test('Enter twice before table element', function (editor) { const rng = editor.dom.createRng(); editor.getBody().innerHTML = '
x
'; rng.setStartBefore(editor.getBody().lastChild); rng.setEndBefore(editor.getBody().lastChild); editor.selection.setRng(rng); pressEnter(editor); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

\u00a0

\u00a0

x
'); }); suite.test('Enter after span with space', function (editor) { editor.setContent('

abc

'); LegacyUnit.setSelection(editor, 'b', 3); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

abc

\u00a0

'); const rng = editor.selection.getRng(true); LegacyUnit.equal(rng.startContainer.nodeName, 'B'); LegacyUnit.equal(rng.startContainer.data !== ' ', true); }); suite.test('Enter inside first li with block inside', function (editor) { editor.getBody().innerHTML = '

  • b

  • c
'; LegacyUnit.setSelection(editor, 'p', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '

\u00a0

  • b

  • c
'); }); suite.test('Enter inside middle li with block inside', function (editor) { editor.getBody().innerHTML = '
  • a

  • c
'; LegacyUnit.setSelection(editor, 'p', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '
  • a

\u00a0

  • c
'); }); suite.test('Enter inside last li with block inside', function (editor) { editor.getBody().innerHTML = '
  • a
  • b

'; LegacyUnit.setSelection(editor, 'p', 0); pressEnter(editor); LegacyUnit.equal(editor.getContent(), '
  • a
  • b

\u00a0

'); }); TinyLoader.setup(function (editor, onSuccess, onFailure) { Pipeline.async({}, suite.toSteps(editor), onSuccess, onFailure); }, { add_unload_trigger: false, disable_nodechange: true, schema: 'html5', extended_valid_elements: 'div[id|style|contenteditable],span[id|style|contenteditable],#dt,#dd', entities: 'raw', indent: false, skin_url: '/project/js/tinymce/skins/lightgray' }, success, failure); });