| 101 | var fillingChar, |
| 102 | fillingCharReady; |
| 103 | |
| 104 | // Checks if a filling char has been used, eventualy removing it (#1272). |
| 105 | function checkFillingChar() |
| 106 | { |
| 107 | if ( fillingChar ) |
| 108 | { |
| 109 | if ( fillingCharReady ) |
| 110 | { |
| 111 | // We can't simply remove the filling node because the user |
| 112 | // will actually enlarge it when typing, so we just remove the |
| 113 | // invisible char from it. |
| 114 | fillingChar.setText( fillingChar.getText().replace( /\u200B/g, '' ) ); |
| 115 | fillingChar = 0; |
| 116 | } |
| 117 | |
| 118 | // Use this flag to avoid removing the filling char right after |
| 119 | // creating it. |
| 120 | fillingCharReady = !fillingCharReady; |
| 121 | } |
| 122 | } |
| 123 | |
| 128 | // On WebKit only, we need a special "filling" char on some situations |
| 129 | // (#1272). Here we set the events that should invalidate that char. |
| 130 | if ( CKEDITOR.env.webkit ) |
| 131 | { |
| 132 | editor.on( 'selectionChange', checkFillingChar ); |
| 133 | editor.on( 'beforeSetMode', checkFillingChar ); |
| 134 | editor.on( 'key', function( e ) |
| 135 | { |
| 136 | // Remove the filling char before the left-key is |
| 137 | // executed, so it'll not get blocked by it. |
| 138 | if ( e.data.keyCode == 37 ) |
| 139 | checkFillingChar(); |
| 140 | }); |
| 141 | } |
| 142 | |
1378 | | var startContainer = this.startContainer; |
1379 | | |
1380 | | // If we have a collapsed range, inside an empty element, we must add |
1381 | | // something to it, otherwise the caret will not be visible. |
1382 | | if ( this.collapsed && startContainer.type == CKEDITOR.NODE_ELEMENT && !startContainer.getChildCount() ) |
1383 | | startContainer.append( new CKEDITOR.dom.text( '' ) ); |
1384 | | |
1385 | | var nativeRange = this.document.$.createRange(); |
1386 | | nativeRange.setStart( startContainer.$, this.startOffset ); |
1387 | | |
1388 | | try |
1389 | | { |
1390 | | nativeRange.setEnd( this.endContainer.$, this.endOffset ); |
1391 | | } |
1392 | | catch ( e ) |
1393 | | { |
1394 | | // There is a bug in Firefox implementation (it would be too easy |
1395 | | // otherwise). The new start can't be after the end (W3C says it can). |
1396 | | // So, let's create a new range and collapse it to the desired point. |
1397 | | if ( e.toString().indexOf( 'NS_ERROR_ILLEGAL_VALUE' ) >= 0 ) |
1398 | | { |
1399 | | this.collapse( true ); |
1400 | | nativeRange.setEnd( this.endContainer.$, this.endOffset ); |
1401 | | } |
1402 | | else |
1403 | | throw( e ); |
1404 | | } |
1405 | | |
1406 | | var selection = this.document.getSelection().getNative(); |
1407 | | // getSelection() returns null in case when iframe is "display:none" in FF. (#6577) |
1408 | | if ( selection ) |
1409 | | { |
1410 | | selection.removeAllRanges(); |
1411 | | selection.addRange( nativeRange ); |
1412 | | } |
| 1429 | this.document.getSelection().selectRanges( [ this ] ); |