Ticket #1272: 1272_4.patch

File 1272_4.patch, 6.5 KB (added by Frederico Caldeira Knabben, 13 years ago)
  • _source/core/dom/text.js

     
    6767                        return this.$.nodeValue;
    6868                },
    6969
     70                setText : function( text )
     71                {
     72                        this.$.nodeValue = text;
     73                },
     74
    7075                /**
    7176                 * Breaks this text node into two nodes at the specified offset,
    7277                 * keeping both in the tree as siblings. This node then only contains
  • _source/plugins/editingblock/plugin.js

     
    153153         */
    154154        CKEDITOR.editor.prototype.setMode = function( mode )
    155155        {
     156                this.fire( 'beforeSetMode', { newMode : mode } );
     157
    156158                var data,
    157159                        holderElement = this.getThemeSpace( 'contents' ),
    158160                        isDirty = this.checkDirty();
  • _source/plugins/selection/plugin.js

     
    9999                canUndo : false
    100100        };
    101101
     102        var fillingChar,
     103                fillingCharReady;
     104
     105        // Checks if a filling char has been used, eventualy removing it (#1272).
     106        function checkFillingChar()
     107        {
     108                if ( fillingChar )
     109                {
     110                        fillingCharReady && removeFillingChar();
     111
     112                        // Use this flag to avoid removing the filling char right after
     113                        // creating it.
     114                        fillingCharReady = !fillingCharReady;
     115                }
     116        }
     117
     118        function removeFillingChar()
     119        {
     120                if ( fillingChar )
     121                {
     122                        // We can't simply remove the filling node because the user
     123                        // will actually enlarge it when typing, so we just remove the
     124                        // invisible char from it.
     125                        fillingChar.setText( fillingChar.getText().replace( /\u200B/g, '' ) );
     126                        fillingChar = 0;
     127                }
     128        }
     129
    102130        CKEDITOR.plugins.add( 'selection',
    103131        {
    104132                init : function( editor )
    105133                {
     134                        // On WebKit only, we need a special "filling" char on some situations
     135                        // (#1272). Here we set the events that should invalidate that char.
     136                        if ( CKEDITOR.env.webkit )
     137                        {
     138                                editor.on( 'selectionChange', checkFillingChar );
     139                                editor.on( 'beforeSetMode', checkFillingChar );
     140                                editor.on( 'key', function( e )
     141                                        {
     142                                                // Remove the filling char before the left-key is
     143                                                // executed, so it'll not get blocked by it.
     144                                                switch ( e.data.keyCode )
     145                                                {
     146                                                        case 37 :       // LEFT-ARROW
     147                                                        case 8 :        // BACKSPACE
     148                                                                checkFillingChar();
     149                                                }
     150                                        });
     151
     152                                var fillingCharBeforeUndo;
     153                                editor.on( 'beforeUndoImage', function()
     154                                        {
     155                                                fillingCharBeforeUndo = fillingChar && fillingChar.getText();
     156                                                fillingCharBeforeUndo && fillingChar.setText( fillingCharBeforeUndo.replace( /\u200B/g, '' ) );
     157                                        });
     158                                editor.on( 'afterUndoImage', function()
     159                                        {
     160                                                fillingChar && fillingChar.setText( fillingCharBeforeUndo );
     161                                        });
     162                        }
     163
    106164                        editor.on( 'contentDom', function()
    107165                                {
    108166                                        var doc = editor.document,
     
    11381196                                var sel = this.getNative();
    11391197
    11401198                                if ( ranges.length )
     1199                                {
    11411200                                        sel.removeAllRanges();
     1201                                        // Remove any existing filling char first.
     1202                                        CKEDITOR.env.webkit && checkFillingChar();
     1203                                }
    11421204
    11431205                                for ( var i = 0 ; i < ranges.length ; i++ )
    11441206                                {
     
    11881250                                                startContainer.appendText( '' );
    11891251                                        }
    11901252
    1191                                         nativeRange.setStart( startContainer.$, range.startOffset );
     1253                                        if ( range.collapsed && CKEDITOR.env.webkit )
     1254                                        {
     1255                                                // Append a zero-width space so WebKit will not try to
     1256                                                // move the selection by itself (#1272).
     1257                                                fillingChar = this.document.createText( '\u200B' );
     1258                                                range.insertNode( fillingChar ) ;
     1259
     1260                                                var next = fillingChar.getNext();
     1261
     1262                                                // If the filling char is followed by a <br>, it'll not
     1263                                                // blink. Let's remove it in this case.
     1264                                                if ( next && next.type == CKEDITOR.NODE_ELEMENT && next.getName() == 'br' )
     1265                                                {
     1266                                                        removeFillingChar();
     1267                                                        range.moveToPosition( next, CKEDITOR.POSITION_BEFORE_START );
     1268                                                }
     1269                                                else
     1270                                                        range.moveToPosition( fillingChar, CKEDITOR.POSITION_AFTER_END );
     1271                                        }
     1272
     1273                                        nativeRange.setStart( range.startContainer.$, range.startOffset );
    11921274                                        nativeRange.setEnd( range.endContainer.$, range.endOffset );
    11931275
    11941276                                        // Select the range.
     
    13761458                :
    13771459                        function()
    13781460                        {
    1379                                 var startContainer = this.startContainer;
    1380 
    1381                                 // If we have a collapsed range, inside an empty element, we must add
    1382                                 // something to it, otherwise the caret will not be visible.
    1383                                 if ( this.collapsed && startContainer.type == CKEDITOR.NODE_ELEMENT && !startContainer.getChildCount() )
    1384                                         startContainer.append( new CKEDITOR.dom.text( '' ) );
    1385 
    1386                                 var nativeRange = this.document.$.createRange();
    1387                                 nativeRange.setStart( startContainer.$, this.startOffset );
    1388 
    1389                                 try
    1390                                 {
    1391                                         nativeRange.setEnd( this.endContainer.$, this.endOffset );
    1392                                 }
    1393                                 catch ( e )
    1394                                 {
    1395                                         // There is a bug in Firefox implementation (it would be too easy
    1396                                         // otherwise). The new start can't be after the end (W3C says it can).
    1397                                         // So, let's create a new range and collapse it to the desired point.
    1398                                         if ( e.toString().indexOf( 'NS_ERROR_ILLEGAL_VALUE' ) >= 0 )
    1399                                         {
    1400                                                 this.collapse( true );
    1401                                                 nativeRange.setEnd( this.endContainer.$, this.endOffset );
    1402                                         }
    1403                                         else
    1404                                                 throw( e );
    1405                                 }
    1406 
    1407                                 var selection = this.document.getSelection().getNative();
    1408                                 // getSelection() returns null in case when iframe is "display:none" in FF. (#6577)
    1409                                 if ( selection )
    1410                                 {
    1411                                         selection.removeAllRanges();
    1412                                         selection.addRange( nativeRange );
    1413                                 }
     1461                                this.document.getSelection().selectRanges( [ this ] );
    14141462                        };
    14151463} )();
  • _source/plugins/undo/plugin.js

     
    148148        var Image = CKEDITOR.plugins.undo.Image = function( editor )
    149149        {
    150150                this.editor = editor;
     151
     152                editor.fire( 'beforeUndoImage' );
     153
    151154                var contents = editor.getSnapshot(),
    152155                        selection       = contents && editor.getSelection();
    153156
     
    156159
    157160                this.contents   = contents;
    158161                this.bookmarks  = selection && selection.createBookmarks2( true );
     162
     163                editor.fire( 'afterUndoImage' );
    159164        };
    160165
    161166        // Attributes that browser may changing them when setting via innerHTML.
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy