Skip to content

Commit 9641ac4

Browse files
committed
Merge branch 't/12423'
2 parents 4f0ee0c + 7abbf4d commit 9641ac4

File tree

6 files changed

+97
-10
lines changed

6 files changed

+97
-10
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ New Features:
99

1010
Fixed Issues:
1111

12+
* [#12423](http://dev.ckeditor.com/ticket/12423): Fixed: Enter key moved cursor to strange position on Safari 8.0.
1213
* [#12381](http://dev.ckeditor.com/ticket/12381): Fixed: Selection trouble in iOS. Thanks to [Remiremi](https://github.com/Remiremi)!
1314
* [#10804](http://dev.ckeditor.com/ticket/10804): Fixed: `CKEDITOR_GETURL` isn't used with some plugins it should be used. Thanks to [Thomas Andraschko](https://github.com/tandraschko)!
1415
* [#9137](http://dev.ckeditor.com/ticket/9137): Fixed: `base` tag is not created when `head` has an attribute. Thanks to [naoki.fujikawa](https://github.com/naoki-fujikawa)!

core/dom/walker.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,14 +398,17 @@
398398
};
399399

400400
/**
401-
* Returns a function which checks whether the node is invisible in wysiwyg mode.
401+
* Returns a function which checks whether the node is invisible in the WYSIWYG mode.
402402
*
403403
* @static
404404
* @param {Boolean} [isReject=false]
405405
* @returns {Function}
406406
*/
407407
CKEDITOR.dom.walker.invisible = function( isReject ) {
408-
var whitespace = CKEDITOR.dom.walker.whitespaces();
408+
var whitespace = CKEDITOR.dom.walker.whitespaces(),
409+
// #12221 (Chrome) plus #11111 (Safari).
410+
offsetWidth0 = CKEDITOR.env.webkit ? 1 : 0;
411+
409412
return function( node ) {
410413
var invisible;
411414

@@ -416,12 +419,11 @@
416419
if ( node.type == CKEDITOR.NODE_TEXT )
417420
node = node.getParent();
418421

419-
// Nodes that take no spaces in wysiwyg:
420-
// 1. White-spaces but not including NBSP;
421-
// 2. Empty inline elements, e.g. <b></b> we're checking here
422-
// 'offsetHeight' instead of 'offsetWidth' for properly excluding
423-
// all sorts of empty paragraph, e.g. <br />.
424-
invisible = !node.$.offsetHeight;
422+
// Nodes that take no spaces in wysiwyg:
423+
// 1. White-spaces but not including NBSP.
424+
// 2. Empty inline elements, e.g. <b></b>.
425+
// 3. <br> elements (bogus, surrounded by text) (#12423).
426+
invisible = node.$.offsetWidth <= offsetWidth0;
425427
}
426428

427429
return !!( isReject ^ invisible );

tests/core/dom/walker.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<div id="playground"></div>
22
<span id="nbsp">&nbsp;</span>
3+
<p>foo<br id="brInText">bar<br id="bogusBr"></p>
4+
<p>foo<b id="emptyInline"></b>,<b id="wsInline"> </b>, <b id="wsInline2"> </b> ,<b id="nonEmptyInline">x</b>bar</p>
5+
<p id="filledBlock"><br></p>
36

47
<!-- isBlockBoundary section -->
58
<span id="bbf1" style="display:block; float: right">x</span>

tests/core/dom/walker.js

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,48 @@
346346

347347
},
348348

349-
test_nbsp_is_visible: function() {
350-
assert.isTrue( !!CKEDITOR.dom.walker.invisible( true )( doc.getById( 'nbsp' ).getFirst() ) );
349+
'test walker.invisible() - br surrounded by text': function() {
350+
assert.isTrue( CKEDITOR.dom.walker.invisible()( doc.getById( 'brInText' ) ) );
351+
},
352+
353+
'test walker.invisible() - bogus br': function() {
354+
assert.isTrue( CKEDITOR.dom.walker.invisible()( doc.getById( 'bogusBr' ) ) );
355+
},
356+
357+
'test walker.invisible() - nbsp': function() {
358+
assert.isFalse( CKEDITOR.dom.walker.invisible()( doc.getById( 'nbsp' ).getFirst() ) );
359+
},
360+
361+
'test walker.invisible() - whitespaces in empty inline element surrounded by text': function() {
362+
assert.isTrue( CKEDITOR.dom.walker.invisible()( doc.getById( 'wsInline' ).getFirst() ) );
363+
},
364+
365+
'test walker.invisible() - whitespaces in empty inline element surrounded by whitespaces': function() {
366+
// IE8 loses empty text nodes when parsing HTML.
367+
if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 )
368+
assert.ignore();
369+
370+
assert.isTrue( CKEDITOR.dom.walker.invisible()( doc.getById( 'wsInline2' ).getFirst() ) );
371+
},
372+
373+
'test walker.invisible() - empty inline element': function() {
374+
assert.isTrue( CKEDITOR.dom.walker.invisible()( doc.getById( 'emptyInline' ) ) );
375+
},
376+
377+
'test walker.invisible() - inline element containing whitespaces, surrounded by text': function() {
378+
assert.isFalse( CKEDITOR.dom.walker.invisible()( doc.getById( 'wsInline' ) ) );
379+
},
380+
381+
'test walker.invisible() - inline element containing whitespaces, surrounded by whitespaces': function() {
382+
assert.isTrue( CKEDITOR.dom.walker.invisible()( doc.getById( 'wsInline2' ) ) );
383+
},
384+
385+
'test walker.invisible() - non empty inline element': function() {
386+
assert.isFalse( CKEDITOR.dom.walker.invisible()( doc.getById( 'nonEmptyInline' ).getFirst() ) );
387+
},
388+
389+
'test walker.invisible() - block with a bogus br only': function() {
390+
assert.isFalse( CKEDITOR.dom.walker.invisible()( doc.getById( 'filledBlock' ) ) );
351391
},
352392

353393
'test walker.temp': function() {

tests/core/selection/selection.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,30 @@ bender.test(
132132
} );
133133
},
134134

135+
'test selectRanges - in empty block': function() {
136+
if ( !CKEDITOR.env.needsBrFiller )
137+
assert.ignore();
138+
139+
var editor = this.editor,
140+
range = editor.createRange();
141+
142+
editor.editable().setHtml( '<p>foo</p><p id="target"><br /></p><p>bar</p>' );
143+
144+
var p = editor.document.getById( 'target' );
145+
range.moveToPosition( p, CKEDITOR.POSITION_AFTER_START );
146+
147+
editor.getSelection().selectRanges( [ range ] );
148+
149+
assert.isInnerHtmlMatching(
150+
'<p>foo</p><p id="target">^<br /></p><p>bar</p>',
151+
bender.tools.selection.getWithHtml( editor ),
152+
{
153+
compareSelection: true,
154+
normalizeSelection: true
155+
},
156+
'selection was placed in the empty paragraph' );
157+
},
158+
135159
test_getSelectedElement : function() {
136160
testSelectedElement( '[<img />]', 'img' );
137161
testSelectedElement( '[<hr />]', 'hr' );

tests/plugins/enter/enterkey.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@
2323
};
2424
}
2525

26+
function e( editorName, htmlWithSeleciton, expectedHtmlWithSelection ) {
27+
return function() {
28+
var editor = this.editors[ editorName ];
29+
30+
selectionTools.setWithHtml( editor, htmlWithSeleciton );
31+
editor.execCommand( 'enter' );
32+
33+
var output = selectionTools.getWithHtml( editor );
34+
35+
assert.isInnerHtmlMatching( expectedHtmlWithSelection, output, matchOpts );
36+
};
37+
}
38+
2639
bender.test( {
2740
_should: {
2841
ignore: {
@@ -233,6 +246,10 @@
233246
},
234247
*/
235248

249+
'test enter key - start of block': e( 'editor', '<p>{}foo</p>', '<p>@</p><p>^foo@</p>' ),
250+
'test enter key - middle of block': e( 'editor', '<p>foo{}bar</p>', '<p>foo@</p><p>^bar@</p>' ),
251+
'test enter key - end of block': e( 'editor', '<p>foo{}</p>', '<p>foo@</p><p>^@</p>' ),
252+
236253
'test shift+enter key - middle of block': se( 'editor', '<p>foo{}bar</p>', '<p>foo<br />^bar@</p>' ),
237254
'test shift+enter key - list item': se( 'editor', '<ul><li>foo{}bar</li></ul>', '<ul><li>foo<br />^bar@</li></ul>' ),
238255
'test shift+enter key - start of block': se( 'editor', '<p>{}foobar</p>', '<p><br />^foobar@</p>' ),

0 commit comments

Comments
 (0)