module("tinymce.EnterKey", { setupModule: function() { QUnit.stop(); tinymce.init({ selector: "textarea", add_unload_trigger: false, disable_nodechange: true, indent: false, skin: false, entities: 'raw', schema: 'html5', extended_valid_elements: 'div[id|style|contenteditable],span[id|style|contenteditable],#dt,#dd', valid_styles: { '*' : 'color,font-size,font-family,background-color,font-weight,font-style,text-decoration,float,margin,margin-top,margin-right,margin-bottom,margin-left,display,position,top,left' }, init_instance_callback: function(ed) { window.editor = ed; QUnit.start(); } }); }, teardown: function() { editor.settings.forced_root_block = 'p'; editor.settings.forced_root_block_attrs = null; editor.settings.end_container_on_empty_block = false; editor.settings.br_in_pre = true; editor.settings.keep_styles = true; delete editor.settings.force_p_newlines; } }); test('Enter at end of H1', function() { editor.setContent('

abc

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

abc

\u00a0

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

abcd

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

ab

cd

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

ab

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

a

b

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

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

\u00a0

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

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

\u00a0

\"\"

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

abc

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

abc

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

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

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

abc

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

abc

\u00a0

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

abc

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

abc

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

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

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

abc

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

abc

\u00a0

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

abc

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

abc

\u00a0

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

abc

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

abc

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

abcd

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

ab

cd

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

abc

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

abc

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

abc

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

abc

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

abcd

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

ab

cd

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

abc

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

abc

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

abc

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

\u00a0

abc

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

abcd

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

ab

cd

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

abcd

efgh

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

abgh

'); equal(editor.selection.getNode().nodeName, 'H1'); }); test('Enter at end of H1 in HGROUP', function() { editor.setContent('

abc

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

abc

\u00a0

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

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

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

ab

cd

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

\u00a0

abcd

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

abcd

\u00a0

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

\u00a0

\u00a0

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Enter inside empty li in beginning of ol', function() { editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
  1. a
' : '

  1. a
'; Utils.setSelection('li', 0); Utils.pressEnter(); equal(editor.getContent(), '

\u00a0

  1. a
'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Enter inside empty li at the end of ol', function() { editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
  1. a
' : '
  1. a

'; Utils.setSelection('li:last', 0); Utils.pressEnter(); equal(editor.getContent(), '
  1. a

\u00a0

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Shift+Enter inside empty li in the middle of ol', function() { editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
  1. a
  2. b
' : '
  1. a

  2. b
'; Utils.setSelection('li:nth-child(2)', 0); Utils.pressEnter({shiftKey: true}); equal(editor.getContent(), '
  1. a

\u00a0

  1. b
'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Shift+Enter inside empty li in beginning of ol', function() { editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
  1. a
' : '

  1. a
'; Utils.setSelection('li', 0); Utils.pressEnter({shiftKey: true}); equal(editor.getContent(), '

\u00a0

  1. a
'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Shift+Enter inside empty li at the end of ol', function() { editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
  1. a
' : '
  1. a

'; Utils.setSelection('li:last', 0); Utils.pressEnter({shiftKey: true}); equal(editor.getContent(), '
  1. a

\u00a0

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Enter inside empty li in the middle of ol with forced_root_block: false', function() { editor.settings.forced_root_block = false; editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
  1. a
  2. b
' : '
  1. a

  2. b
'; Utils.setSelection('li:nth-child(2)', 0); Utils.pressEnter(); equal(editor.getContent(), '
  1. a

  1. b
'); equal(editor.selection.getNode().nodeName, 'BODY'); }); test('Enter inside empty li in beginning of ol with forced_root_block: false', function() { editor.settings.forced_root_block = false; editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
  1. a
' : '

  1. a
'; Utils.setSelection('li', 0); Utils.pressEnter(); equal(editor.getContent(), '
  1. a
'); equal(editor.selection.getNode().nodeName, 'BODY'); }); test('Enter inside empty li at the end of ol with forced_root_block: false', function() { editor.settings.forced_root_block = false; editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
  1. a
' : '
  1. a

'; Utils.setSelection('li:last', 0); Utils.pressEnter(); equal(Utils.cleanHtml(editor.getBody().innerHTML), '
  1. a

'); equal(editor.selection.getNode().nodeName, 'BODY'); }); test('Enter inside empty li in the middle of ol', function() { editor.getBody().innerHTML = (tinymce.isIE && tinymce.Env.ie < 11) ? '
  1. a
  2. b
' : '
  1. a

  2. b
'; Utils.setSelection('li:nth-child(2)', 0); Utils.pressEnter(); equal(editor.getContent(), '
  1. a

\u00a0

  1. b
'); equal(editor.selection.getNode().nodeName, 'P'); }); // Nested lists in LI elements test('Enter inside empty LI in beginning of OL in LI', function() { editor.getBody().innerHTML = Utils.trimBrsOnIE( '
    ' + '
  1. a' + '
      ' + '

    1. ' + '
    2. a
    3. ' + '
    ' + '
  2. ' + '
' ); Utils.setSelection('li li', 0); editor.focus(); Utils.pressEnter(); equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
  3. ' + '
      ' + '
    1. a
    2. ' + '
    ' + '
  4. ' + '
' ); equal(editor.selection.getNode().nodeName, 'LI'); }); test('Enter inside empty LI in middle of OL in LI', function() { editor.getBody().innerHTML = Utils.trimBrsOnIE( '
    ' + '
  1. a' + '
      ' + '
    1. a
    2. ' + '

    3. ' + '
    4. b
    5. ' + '
    ' + '
  2. ' + '
' ); Utils.setSelection('li li:nth-child(2)', 0); editor.focus(); Utils.pressEnter(); equal(editor.getContent(), '
    ' + '
  1. a' + '
      ' + '
    1. a
    2. ' + '
    ' + '
  2. ' + '
  3. \u00a0' + '
      ' + '
    1. b
    2. ' + '
    ' + '
  4. ' + '
' ); // Ignore on IE 7, 8 this is a known bug not worth fixing if (!tinymce.Env.ie || tinymce.Env.ie > 8) { equal(editor.selection.getNode().nodeName, 'LI'); } }); test('Enter inside empty LI in end of OL in LI', function() { editor.getBody().innerHTML = Utils.trimBrsOnIE( '
    ' + '
  1. a' + '
      ' + '
    1. a
    2. ' + '

    3. ' + '
    ' + '
  2. ' + '
' ); Utils.setSelection('li li:last', 0); editor.focus(); Utils.pressEnter(); equal(editor.getContent(), '
    ' + '
  1. a' + '
      ' + '
    1. a
    2. ' + '
    ' + '
  2. ' + '
  3. ' + '
' ); equal(editor.selection.getNode().nodeName, 'LI'); }); // Nested lists in OL elements // Ignore on IE 7, 8 this is a known bug not worth fixing if (!tinymce.Env.ie || tinymce.Env.ie > 8) { test('Enter before nested list', function() { editor.getBody().innerHTML = Utils.trimBrsOnIE( '
    ' + '
  1. a' + '
      ' + '
    • b
    • ' + '
    • c
    • ' + '
    ' + '
  2. ' + '
' ); Utils.setSelection('ol > li', 1); editor.focus(); Utils.pressEnter(); equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
  3. \u00a0' + '
      ' + '
    • b
    • ' + '
    • c
    • ' + '
    ' + '
  4. ' + '
' ); equal(editor.selection.getNode().nodeName, 'LI'); }); } test('Enter inside empty LI in beginning of OL in OL', function() { editor.getBody().innerHTML = Utils.trimBrsOnIE( '
    ' + '
  1. a
  2. ' + '
      ' + '

    1. ' + '
    2. a
    3. ' + '
    ' + '
' ); Utils.setSelection('ol ol li', 0); editor.focus(); Utils.pressEnter(); equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
  3. ' + '
      ' + '
    1. a
    2. ' + '
    ' + '
' ); equal(editor.selection.getNode().nodeName, 'LI'); }); test('Enter inside empty LI in middle of OL in OL', function() { editor.getBody().innerHTML = Utils.trimBrsOnIE( '
    ' + '
  1. a
  2. ' + '
      ' + '
    1. a
    2. ' + '

    3. ' + '
    4. b
    5. ' + '
    ' + '
' ); Utils.setSelection('ol ol li:nth-child(2)', 0); editor.focus(); Utils.pressEnter(); equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
      ' + '
    1. a
    2. ' + '
    ' + '
  3. ' + '
      ' + '
    1. b
    2. ' + '
    ' + '
' ); equal(editor.selection.getNode().nodeName, 'LI'); }); test('Enter inside empty LI in end of OL in OL', function() { editor.getBody().innerHTML = Utils.trimBrsOnIE( '
    ' + '
  1. a
  2. ' + '
      ' + '
    1. a
    2. ' + '

    3. ' + '
    ' + '
' ); Utils.setSelection('ol ol li:last', 0); editor.focus(); Utils.pressEnter(); equal(editor.getContent(), '
    ' + '
  1. a
  2. ' + '
      ' + '
    1. a
    2. ' + '
    ' + '
  3. ' + '
' ); equal(editor.selection.getNode().nodeName, 'LI'); }); test('Enter at beginning of first DT inside DL', function() { editor.getBody().innerHTML = '
a
'; Utils.setSelection('dt', 0); Utils.pressEnter(); equal(editor.getContent(), '
\u00a0
a
'); equal(editor.selection.getNode().nodeName, 'DT'); }); test('Enter at beginning of first DD inside DL', function() { editor.getBody().innerHTML = '
a
'; Utils.setSelection('dd', 0); Utils.pressEnter(); equal(editor.getContent(), '
\u00a0
a
'); equal(editor.selection.getNode().nodeName, 'DD'); }); test('Enter at beginning of middle DT inside DL', function() { editor.getBody().innerHTML = '
a
b
c
'; Utils.setSelection('dt:nth-child(2)', 0); Utils.pressEnter(); equal(editor.getContent(), '
a
\u00a0
b
c
'); equal(editor.selection.getNode().nodeName, 'DT'); }); test('Enter at beginning of middle DD inside DL', function() { editor.getBody().innerHTML = '
a
b
c
'; Utils.setSelection('dd:nth-child(2)', 0); Utils.pressEnter(); equal(editor.getContent(), '
a
\u00a0
b
c
'); equal(editor.selection.getNode().nodeName, 'DD'); }); test('Enter at end of last DT inside DL', function() { editor.getBody().innerHTML = '
a
'; Utils.setSelection('dt', 1); Utils.pressEnter(); equal(editor.getContent(), '
a
\u00a0
'); equal(editor.selection.getNode().nodeName, 'DT'); }); test('Enter at end of last DD inside DL', function() { editor.getBody().innerHTML = '
a
'; Utils.setSelection('dd', 1); Utils.pressEnter(); equal(editor.getContent(), '
a
\u00a0
'); equal(editor.selection.getNode().nodeName, 'DD'); }); test('Enter at end of last empty DT inside DL', function() { editor.getBody().innerHTML = '
a
'; Utils.setSelection('dt:nth-child(2)', 0); Utils.pressEnter(); equal(editor.getContent(), '
a

\u00a0

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Enter at end of last empty DD inside DL', function() { editor.getBody().innerHTML = '
a
'; Utils.setSelection('dd:nth-child(2)', 0); Utils.pressEnter(); equal(editor.getContent(), '
a

\u00a0

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Enter at beginning of P inside LI', function() { editor.getBody().innerHTML = '
  1. abcd

'; Utils.setSelection('p', 0); Utils.pressEnter(); equal(editor.getContent(), '
  1. abcd

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Enter inside middle of P inside LI', function() { editor.getBody().innerHTML = '
  1. abcd

'; Utils.setSelection('p', 2); Utils.pressEnter(); equal(editor.getContent(), '
  1. ab

  2. cd

'); // Ignore on IE 7, 8 this is a known bug not worth fixing if (!tinymce.Env.ie || tinymce.Env.ie > 8) { equal(editor.selection.getNode().nodeName, 'P'); } }); test('Enter at end of P inside LI', function() { editor.getBody().innerHTML = '
  1. abcd

'; Utils.setSelection('p', 4); Utils.pressEnter(); equal(editor.getContent(), '
  1. abcd

'); equal(editor.selection.getNode().nodeName, 'LI'); }); test('Shift+Enter at beginning of P inside LI', function() { editor.getBody().innerHTML = '
  1. abcd

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

  1. abcd

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Shift+Enter inside middle of P inside LI', function() { editor.getBody().innerHTML = '
  1. abcd

'; Utils.setSelection('p', 2); Utils.pressEnter({shiftKey: true}); equal(editor.getContent(), '
  1. ab
    cd

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Shift+Enter at end of P inside LI', function() { editor.getBody().innerHTML = '
  1. abcd

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

' : '
  1. abcd

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Ctrl+Enter at beginning of P inside LI', function() { editor.getBody().innerHTML = '
  1. abcd

'; Utils.setSelection('p', 0); Utils.pressEnter({ctrlKey: true}); equal(editor.getContent(), '
  1. \u00a0

    abcd

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Ctrl+Enter inside middle of P inside LI', function() { editor.getBody().innerHTML = '
  1. abcd

'; Utils.setSelection('p', 2); Utils.pressEnter({ctrlKey: true}); equal(editor.getContent(), '
  1. ab

    cd

'); equal(editor.selection.getNode().nodeName, 'P'); }); test('Ctrl+Enter at end of P inside LI', function() { editor.getBody().innerHTML = '
  1. abcd

'; Utils.setSelection('p', 4); Utils.pressEnter({ctrlKey: true}); equal(editor.getContent(), '
  1. abcd

    \u00a0

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

abc

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

ab
c

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

abc

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

abc

' : '

abc

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

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

abc

' : '

abc


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

abc

\u00a0

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

abc

' : '


abc

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

\u00a0

abc

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

abc

123

' : '

abc


123

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

abc

\u00a0

123

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

X

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

\u00a0

\u00a0

\u00a0

X

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

a

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

a

\u00a0

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

abc

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


abc

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

abcd

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

ab
cd

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

abcd

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

abcd

' : '

abcd

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

abcd

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

ab
cd

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

abcd

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

abcd

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

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

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

\u00a0

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

\u00a0

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

abc

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

\u00a0

abc

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

abcd

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

ab

cd

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

abc

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

abc

\u00a0

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

ab

cd

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

abcd

\u00a0

'); }); test('Enter in div inside contentEditable:false div', function() { editor.getBody().innerHTML = '
abcd
'; Utils.setSelection('div div', 2); Utils.pressEnter(); equal(Utils.cleanHtml(editor.getBody().innerHTML), '
abcd
'); }); test('Enter in div with contentEditable:true inside contentEditable:false div', function() { editor.getBody().innerHTML = '
abcd
'; Utils.setSelection('div div', 2); Utils.pressEnter(); equal(Utils.cleanHtml(editor.getBody().innerHTML), '

ab

cd

'); }); test('Enter in span with contentEditable:true inside contentEditable:false div', function() { editor.getBody().innerHTML = '
abcd
'; Utils.setSelection('span', 2); Utils.pressEnter(); equal(Utils.cleanHtml(editor.getBody().innerHTML), '
abcd
'); }); test('Shift+Enter in span with contentEditable:true inside contentEditable:false div', function() { editor.getBody().innerHTML = '
abcd
'; Utils.setSelection('span', 2); Utils.pressEnter({shiftKey: true}); equal(Utils.cleanHtml(editor.getBody().innerHTML), '
ab
cd
'); }); test('Enter in span with contentEditable:true inside contentEditable:false div and forced_root_block: false', function() { editor.settings.forced_root_block = false; editor.getBody().innerHTML = '
abcd
'; Utils.setSelection('span', 2); Utils.pressEnter(); equal(Utils.cleanHtml(editor.getBody().innerHTML), '
ab
cd
'); }); test('Enter in em within contentEditable:true div inside contentEditable:false div', function() { editor.getBody().innerHTML = '
abcd
'; Utils.setSelection('em', 2); Utils.pressEnter(); equal(Utils.cleanHtml(editor.getBody().innerHTML), '

ab

cd

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

X

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

X

\u00a0

'); }); test('Shift+enter in LI when forced_root_block: false', function() { editor.settings.forced_root_block = false; editor.getBody().innerHTML = '
  • text
'; Utils.setSelection('li', 2); Utils.pressEnter({shiftKey: true}); equal(editor.getContent(), '
  • te
    xt
'); }); test('Enter when forced_root_block: false and force_p_newlines: true', function() { editor.settings.forced_root_block = false; editor.settings.force_p_newlines = true; editor.getBody().innerHTML = 'text'; Utils.setSelection('body', 2); Utils.pressEnter(); equal(editor.getContent(), '

te

xt

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

a
b

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

a


b

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

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

\u00a0

\u00a0

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

\u00a0

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

\u00a0

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

x

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

\u00a0

x

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

x

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

x

\u00a0

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

\u00a0

\u00a0

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

abc

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

abc

\u00a0

'); var rng = editor.selection.getRng(true); equal(rng.startContainer.nodeName, 'B'); notEqual(rng.startContainer.data, ' '); }); }