Skip to content
Permalink
Browse files

Merge branch 't/11947'

  • Loading branch information...
Reinmar committed Jun 13, 2014
2 parents 850b2e4 + ae2c01f commit c6b36c2dc56ba2064f4ca9c8b19f5c6b143ca0fb
Showing with 207 additions and 127 deletions.
  1. +1 −0 CHANGES.md
  2. +5 −2 plugins/enterkey/plugin.js
  3. +178 −120 tests/plugins/enter/enterkey.js
  4. +23 −5 tests/utils/range/setgetwithhtml.js
@@ -23,6 +23,7 @@ Fixed Issues:
* [#12009](http://dev.ckeditor.com/ticket/12009): [Nested widgets] Integration with Magicline plugin.
* [#11387](http://dev.ckeditor.com/ticket/11387): Fixed: `role="radiogroup"` should be applied only to radio inputs' container.
* [#7975](http://dev.ckeditor.com/ticket/7975): [IE8] Fixed: Errors when trying to select empty table cell on IE8.
* [#11947](http://dev.ckeditor.com/ticket/11947): [FF+IE11] Fixed: Shift+Enter in lists produces two line breaks.

## CKEditor 4.4.1

@@ -453,8 +453,11 @@
doc.createText( '\ufeff' ).insertAfter( lineBreak );

// If we are at the end of a block, we must be sure the bogus node is available in that block.
if ( isEndOfBlock )
lineBreak.getParent().appendBogus();
if ( isEndOfBlock ) {
// In most situations we've got an elementPath.block (e.g. <p>), but in a
// blockless editor or when autoP is false that needs to be a block limit.
( startBlock || elementPath.blockLimit ).appendBogus();
}

// Now we can remove the text node contents, so the caret doesn't
// stop on it.
@@ -1,97 +1,147 @@
/* bender-tags: editor,unit */
/* bender-ckeditor-plugins: entities,enterkey */

bender.editor = {
config: {
enterMode: CKEDITOR.ENTER_P,
allowedContent: true
( function() {
'use strict';

var selectionTools = bender.tools.selection,
matchOpts = {
compareSelection: true,
normalizeSelection: true
};

function se( editorName, htmlWithSeleciton, expectedHtmlWithSelection ) {
return function() {
var editor = this.editors[ editorName ];

selectionTools.setWithHtml( editor, htmlWithSeleciton );
editor.execCommand( 'shiftEnter' );

var output = selectionTools.getWithHtml( editor );

assert.isInnerHtmlMatching( expectedHtmlWithSelection, output, matchOpts );
};
}
};

bender.test(
{
// #7912
'test enterkey after invisible element': function() {
// IE restrain making selection in invisible element.
if ( CKEDITOR.env.ie )
assert.ignore();

var bot = this.editorBot;
bot.setHtmlWithSelection( '<p>foo<span style="display:none;">bar^</span></p>' );
bot.execCommand( 'enter' );
this.editor.insertText( 'baz' );

var output = bender.tools.getHtmlWithSelection( bot.editor );
output = bot.editor.dataProcessor.toDataFormat( output );

var expected =
CKEDITOR.env.safari ?
'<p>foo</p><p>baz^<span style="display:none;">bar</span></p>' :
'<p>foo<span style="display:none;">bar</span></p><p>baz^</p>';

assert.areSame( expected, bender.tools.fixHtml( output ) );
},

// #8321
'test enter at the end of block with inline styles' : function() {
var bot = this.editorBot;
bot.setHtmlWithSelection( '<p><b><i>foo^</i></b></p>' );
bot.execCommand( 'enter' );
bot.editor.insertText( 'bar' );
assert.areSame( '<p><b><i>foo</i></b></p><p><b><i>bar</i></b></p>', bot.getData( false, true ) );
},

// #7946 TODO: Add editor doc quirks mode tests.
'test enter key scrolls document' : function() {
var bot = this.editorBot;

bot.editor.focus();
bot.setHtmlWithSelection( '^' );

// Press enough enter key in order overflow the content area.
var i = 0;
while ( i++ < 20 ) bot.execCommand( 'enter' );
var start = bot.editor.getSelection().getStartElement();
var rect = start.$.getBoundingClientRect();
var viewport = bot.editor.window.getViewPaneSize();

// Make sure the cursor is inside of viewport.
assert.isTrue( rect.top < viewport.height && rect.top > 0 );
},

// Start of #8812
'test Enter key at the end of contents with comment' : function() {
var bot = this.editorBot;
bot.setHtmlWithSelection( 'test ^<!-- --> ' );
bot.execCommand( 'enter' );
assert.areSame( '<p>test <!-- --></p><p>&nbsp;</p>', bot.getData( false, true ) );
},

'test Enter key in the middle of contents with comments' : function() {
var bot = this.editorBot;
bot.setHtmlWithSelection( '<!-- baz -->foo^bar<!-- baz -->' );
bot.execCommand( 'enter' );

// IE9+Compat looses the first comment, so we remove it from the assertion (not related to #8812).
assert.areSame( '<p>foo</p><p>bar</p>', bot.getData( false, true ).replace( /<![^>]+>/g, '' ) );
},

'test Enter key in the middle of contents with comments (2)' : function() {
var bot = this.editorBot;
bot.setHtmlWithSelection( '<b>foo</b>bar^baz<!-- --><b>qux</b>' );
bot.execCommand( 'enter' );

assert.areSame( '<p><b>foo</b>bar</p><p>baz<!-- --><b>qux</b></p>', bot.getData( false, true ) );
},
// End of #8812

'test Enter key uses editor.activeEnterMode': function() {
bender.editorBot.create( {
name: 'test_enter_editor_enter_mode',
config: {
autoParagraph: false

bender.test( {
_should: {
ignore: {
'test shift+enter key - end of block, inside inline element followed by bogus br': !CKEDITOR.env.needsBrFiller,
'test shift+enter key - end of list item, inside inline element followed by bogus br': !CKEDITOR.env.needsBrFiller,
}
}, function( bot ) {
},

'async:init': function() {
var that = this;

bender.tools.setUpEditors( {
editor: {
name: 'editor1',
config: {
enterMode: CKEDITOR.ENTER_P,
allowedContent: true
}
},

editorNoAutoParagraph: {
name: 'editor2',
config: {
autoParagraph: false
}
}
}, function( editors, bots ) {
that.editorBots = bots;
that.editors = editors;
that.callback();
} );
},

// #7912
'test enter key after invisible element': function() {
// IE restrain making selection in invisible element.
if ( CKEDITOR.env.ie )
assert.ignore();

var bot = this.editorBots.editor,
editor = bot.editor;

bot.setHtmlWithSelection( '<p>foo<span style="display:none;">bar^</span></p>' );
bot.execCommand( 'enter' );
editor.insertText( 'baz' );

var output = bender.tools.getHtmlWithSelection( editor );
output = editor.dataProcessor.toDataFormat( output );

var expected =
CKEDITOR.env.safari ?
'<p>foo</p><p>baz^<span style="display:none;">bar</span></p>' :
'<p>foo<span style="display:none;">bar</span></p><p>baz^</p>';

assert.areSame( expected, bender.tools.fixHtml( output ) );
},

// #8321
'test enter key at the end of block with inline styles' : function() {
var bot = this.editorBots.editor,
editor = bot.editor;

bot.setHtmlWithSelection( '<p><b><i>foo^</i></b></p>' );
bot.execCommand( 'enter' );
editor.insertText( 'bar' );
assert.areSame( '<p><b><i>foo</i></b></p><p><b><i>bar</i></b></p>', bot.getData( false, true ) );
},

// #7946 TODO: Add editor doc quirks mode tests.
'test enter key key scrolls document' : function() {
var bot = this.editorBots.editor,
editor = bot.editor;

editor.focus();
bot.setHtmlWithSelection( '^' );

// Press enough enter key in order overflow the content area.
var i = 0;
while ( i++ < 20 ) bot.execCommand( 'enter' );
var start = editor.getSelection().getStartElement();
var rect = start.$.getBoundingClientRect();
var viewport = bot.editor.window.getViewPaneSize();

// Make sure the cursor is inside of viewport.
assert.isTrue( rect.top < viewport.height && rect.top > 0 );
},

// Start of #8812
'test ener key at the end of contents with comment' : function() {
var bot = this.editorBots.editor;

bot.setHtmlWithSelection( 'test ^<!-- --> ' );
bot.execCommand( 'enter' );
assert.areSame( '<p>test <!-- --></p><p>&nbsp;</p>', bot.getData( false, true ) );
},

'test enter key in the middle of contents with comments' : function() {
var bot = this.editorBots.editor;

bot.setHtmlWithSelection( '<!-- baz -->foo^bar<!-- baz -->' );
bot.execCommand( 'enter' );

// IE9+Compat looses the first comment, so we remove it from the assertion (not related to #8812).
assert.areSame( '<p>foo</p><p>bar</p>', bot.getData( false, true ).replace( /<![^>]+>/g, '' ) );
},

'test enter key in the middle of contents with comments (2)' : function() {
var bot = this.editorBots.editor;

bot.setHtmlWithSelection( '<b>foo</b>bar^baz<!-- --><b>qux</b>' );
bot.execCommand( 'enter' );

assert.areSame( '<p><b>foo</b>bar</p><p>baz<!-- --><b>qux</b></p>', bot.getData( false, true ) );
},
// End of #8812

'test enter key uses editor.activeEnterMode': function() {
var bot = this.editorBots.editorNoAutoParagraph;

bot.editor.setActiveEnterMode( CKEDITOR.ENTER_BR, CKEDITOR.ENTER_DIV );

try {
@@ -112,16 +162,11 @@ bender.test(
bot.setHtmlWithSelection( 'foo^bar' );
bot.execCommand( 'enter' );
assert.areSame( '<p>foo</p><p>bar</p>', bot.getData(), 'main mode was used' );
} );
},

'test Enter key is influenced by the active filter': function() {
bender.editorBot.create( {
name: 'test_enter_active_filter',
config: {
autoParagraph: false
}
}, function( bot ) {
},

'test enter key is influenced by the active filter': function() {
var bot = this.editorBots.editorNoAutoParagraph;

bot.setHtmlWithSelection( 'foo^bar' );

var filter = new CKEDITOR.filter( 'div' );
@@ -140,27 +185,40 @@ bender.test(
bot.setHtmlWithSelection( 'foo^bar' );
bot.execCommand( 'enter' );
assert.areSame( '<p>foo</p><p>bar</p>', bot.getData(), 'main mode was used' );
} );
},
},

/*
// Commented out until we decide whether we want to block enter key completely and how.
'test Enter key is completely blocked if neither p nor br are allowed': function() {
var bot = this.editorBot;
bot.setHtmlWithSelection( '<p>foo^bar</p>' );
/*
// Commented out until we decide whether we want to block enter key completely and how.
'test enter key is completely blocked if neither p nor br are allowed': function() {
var bot = this.editorBot;
bot.setHtmlWithSelection( '<p>foo^bar</p>' );
var filter = new CKEDITOR.filter( 'x' );
this.editor.setActiveFilter( filter );
var filter = new CKEDITOR.filter( 'x' );
this.editor.setActiveFilter( filter );
try {
bot.execCommand( 'enter' );
assert.areSame( '<p>foobar</p>', bot.getData(), 'enter is blocked' );
} catch ( e ) {
throw e;
} finally {
// Always reset filter - even if previous test failed.
this.editor.setActiveFilter( null );
}
}
*/
} );
try {
bot.execCommand( 'enter' );
assert.areSame( '<p>foobar</p>', bot.getData(), 'enter is blocked' );
} catch ( e ) {
throw e;
} finally {
// Always reset filter - even if previous test failed.
this.editor.setActiveFilter( null );
}
},
*/

'test shift+enter key - middle of block': se( 'editor', '<p>foo{}bar</p>', '<p>foo<br />^bar@</p>' ),
'test shift+enter key - list item': se( 'editor', '<ul><li>foo{}bar</li></ul>', '<ul><li>foo<br />^bar@</li></ul>' ),
'test shift+enter key - start of block': se( 'editor', '<p>{}foobar</p>', '<p><br />^foobar@</p>' ),
'test shift+enter key - end of block': se( 'editor', '<p>foobar{}</p>', '<p>foobar<br />^@</p>' ),
'test shift+enter key - before br': se( 'editor', '<p>foo{}<br />bar</p>', '<p>foo<br />^<br />bar@</p>' ),
'test shift+enter key - after br': se( 'editor', '<p>foo<br />{}bar</p>', '<p>foo<br /><br />^bar@</p>' ),
// #11947
'test shift+enter key - end of block, inside inline element followed by bogus br':
se( 'editor', '<p><em>foo{}</em><br /></p>', '<p><em>foo<br />^</em><br /></p>' ),
'test shift+enter key - end of list item, inside inline element followed by bogus br':
se( 'editor', '<ul><li><em>foo{}</em><br /></li></ul>', '<ul><li><em>foo<br />^</em><br /></li></ul>' ),
} );

} )();

0 comments on commit c6b36c2

Please sign in to comment.
You can’t perform that action at this time.