Ticket #6735: 6735_4.patch

File 6735_4.patch, 8.4 KB (added by Garry Yao, 13 years ago)
  • _source/plugins/clipboard/plugin.js

     
    406406                                // For improved performance, we're checking the readOnly state on selectionChange instead of hooking a key event for that.
    407407                                editor.on( 'selectionChange', function( evt )
    408408                                {
    409                                         inReadOnly = evt.data.selection.getCommonAncestor().isReadOnly();
     409                                        inReadOnly = evt.data.selection.getRanges()[ 0 ].checkReadOnly();
    410410                                });
    411411
    412412                                // If the "contextmenu" plugin is loaded, register the listeners.
     
    414414                                {
    415415                                        editor.contextMenu.addListener( function( element, selection )
    416416                                                {
    417                                                         var readOnly = selection.getCommonAncestor().isReadOnly();
     417                                                        var readOnly = selection.getRanges()[ 0 ].checkReadOnly();
    418418                                                        return {
    419419                                                                cut : !readOnly && stateFromNamedCommand( 'Cut', editor ),
    420420                                                                copy : stateFromNamedCommand( 'Copy', editor ),
  • _source/plugins/wysiwygarea/plugin.js

     
    2525                                || element.isBlockBoundary() && CKEDITOR.dtd.$empty[ element.getName() ];
    2626        }
    2727
    28         function checkReadOnly( selection )
    29         {
    30                 if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT )
    31                         return selection.getSelectedElement().isReadOnly();
    32                 else
    33                         return selection.getCommonAncestor().isReadOnly();
    34         }
    3528
    36 
    3729        function onInsert( insertFunc )
    3830        {
    3931                return function( evt )
     
    4234                        {
    4335                                this.focus();
    4436
    45                                 var selection = this.getSelection();
    46                                 if ( checkReadOnly( selection ) )
    47                                         return;
    48 
    4937                                this.fire( 'saveSnapshot' );
    5038
    5139                                insertFunc.call( this, evt.data );
     
    6755                if ( this.dataProcessor )
    6856                        data = this.dataProcessor.toHtml( data );
    6957
    70                 var selection = this.getSelection();
     58                // HTML insertion only considers the first range.
     59                var selection = this.getSelection(),
     60                        range = selection.getRanges()[ 0 ];
     61
     62                if ( range.checkReadOnly() )
     63                        return;
     64
    7165                if ( CKEDITOR.env.ie )
    7266                {
    7367                        var selIsLocked = selection.isLocked;
     
    8680                                // (#6005), we need to make some checks and eventually
    8781                                // delete the selection first.
    8882
    89                                 var range = selection.getRanges()[0],
     83                                        range = selection.getRanges()[0],
    9084                                                endContainer = range && range.endContainer;
    9185
    9286                                if ( endContainer &&
     
    209203                {
    210204                        range = ranges[ i ];
    211205
    212                         // Remove the original contents.
    213                         range.deleteContents();
     206                                if ( !range.checkReadOnly() )
     207                                {
     208                                        // Remove the original contents.
     209                                        range.deleteContents();
    214210
    215                         clone = !i && element || element.clone( 1 );
     211                                        clone = !i && element || element.clone( 1 );
    216212
    217                         // If we're inserting a block at dtd-violated position, split
    218                         // the parent blocks until we reach blockLimit.
    219                         var current, dtd;
    220                         if ( isBlock )
    221                         {
    222                                 while ( ( current = range.getCommonAncestor( 0, 1 ) )
    223                                                 && ( dtd = CKEDITOR.dtd[ current.getName() ] )
    224                                                 && !( dtd && dtd [ elementName ] ) )
    225                                 {
    226                                         // Split up inline elements.
    227                                         if ( current.getName() in CKEDITOR.dtd.span )
    228                                                 range.splitElement( current );
    229                                         // If we're in an empty block which indicate a new paragraph,
    230                                         // simply replace it with the inserting block.(#3664)
    231                                         else if ( range.checkStartOfBlock()
    232                                                         && range.checkEndOfBlock() )
    233                                         {
    234                                                 range.setStartBefore( current );
    235                                                 range.collapse( true );
    236                                                 current.remove();
    237                                         }
    238                                         else
    239                                                 range.splitBlock();
    240                                 }
    241                         }
     213                                        // If we're inserting a block at dtd-violated position, split
     214                                        // the parent blocks until we reach blockLimit.
     215                                        var current, dtd;
     216                                        if ( isBlock )
     217                                        {
     218                                                while ( ( current = range.getCommonAncestor( 0, 1 ) )
     219                                                                && ( dtd = CKEDITOR.dtd[ current.getName() ] )
     220                                                                && !( dtd && dtd [ elementName ] ) )
     221                                                {
     222                                                        // Split up inline elements.
     223                                                        if ( current.getName() in CKEDITOR.dtd.span )
     224                                                                range.splitElement( current );
     225                                                        // If we're in an empty block which indicate a new paragraph,
     226                                                        // simply replace it with the inserting block.(#3664)
     227                                                        else if ( range.checkStartOfBlock()
     228                                                                        && range.checkEndOfBlock() )
     229                                                        {
     230                                                                range.setStartBefore( current );
     231                                                                range.collapse( true );
     232                                                                current.remove();
     233                                                        }
     234                                                        else
     235                                                                range.splitBlock();
     236                                                }
     237                                        }
    242238
    243                         // Insert the new node.
    244                         range.insertNode( clone );
     239                                        // Insert the new node.
     240                                        range.insertNode( clone );
    245241
    246                         // Save the last element reference so we can make the
    247                         // selection later.
    248                         if ( !lastElement )
    249                                 lastElement = clone;
    250                 }
     242                                        // Save the last element reference so we can make the
     243                                        // selection later.
     244                                        if ( !lastElement )
     245                                                lastElement = clone;
     246                                }
     247                        }
    251248
    252                 range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
     249                        if ( lastElement )
     250                        {
     251                                range.moveToPosition( lastElement, CKEDITOR.POSITION_AFTER_END );
    253252
    254                 // If we're inserting a block element immediatelly followed by
    255                 // another block element, the selection must move there. (#3100,#5436)
    256                 if ( isBlock )
    257                 {
    258                         var next = lastElement.getNext( notWhitespaceEval ),
    259                                         nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();
     253                                // If we're inserting a block element immediatelly followed by
     254                                // another block element, the selection must move there. (#3100,#5436)
     255                                if ( isBlock )
     256                                {
     257                                        var next = lastElement.getNext( notWhitespaceEval ),
     258                                                nextName = next && next.type == CKEDITOR.NODE_ELEMENT && next.getName();
    260259
    261                         // Check if it's a block element that accepts text.
    262                         if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )
    263                                 range.moveToElementEditStart( next );
    264                 }
     260                                        // Check if it's a block element that accepts text.
     261                                        if ( nextName && CKEDITOR.dtd.$block[ nextName ] && CKEDITOR.dtd[ nextName ]['#'] )
     262                                                range.moveToElementEditStart( next );
     263                                }
     264                        }
    265265
    266                 selection.selectRanges( [ range ] );
     266                        selection.selectRanges( [ range ] );
    267267
    268268                if ( selIsLocked )
    269269                        this.getSelection().lock();
  • _source/core/dom/range.js

     
    17551755                },
    17561756
    17571757                /**
     1758                 * Check if elements at which the range boundaries anchor are read-only,
     1759                 * with respect to "contenteditable" attribute.
     1760                 */
     1761                checkReadOnly : ( function()
     1762                {
     1763                        function checkNodesEditable( node, anotherEnd )
     1764                        {
     1765                                while( node )
     1766                                {
     1767                                        if ( node.type == CKEDITOR.NODE_ELEMENT )
     1768                                        {
     1769                                                if ( node.getAttribute( 'contentEditable' ) == 'false'
     1770                                                        && !node.data( 'cke-editable' ) )
     1771                                                {
     1772                                                        return 0;
     1773                                                }
     1774                                                // Range enclosed entirely in an editable element.
     1775                                                else if ( node.is( 'body' )
     1776                                                        || node.getAttribute( 'contentEditable' ) == 'true'
     1777                                                        && ( node.contains( anotherEnd ) || node.equals( anotherEnd ) ) )
     1778                                                {
     1779                                                        break;
     1780                                                }
     1781                                        }
     1782                                        node = node.getParent();
     1783                                }
     1784
     1785                                return 1;
     1786                        }
     1787
     1788                        return function()
     1789                        {
     1790                                var startNode = this.startContainer,
     1791                                        endNode = this.endContainer;
     1792
     1793                                // Check if elements path at both boundaries are editable.
     1794                                return !( checkNodesEditable( startNode, endNode ) && checkNodesEditable( endNode, startNode ) )
     1795                        };
     1796                })(),
     1797
     1798                /**
    17581799                 * Moves the range boundaries to the first/end editing point inside an
    17591800                 * element. For example, in an element tree like
    17601801                 * "<p><b><i></i></b> Text</p>", the start editing point is
  • _source/plugins/scayt/plugin.js

     
    626626                                editor.contextMenu.addListener( function( element, selection )
    627627                                        {
    628628                                                if ( !plugin.isScaytEnabled( editor )
    629                                                                 || selection.getCommonAncestor().isReadOnly() )
     629                                                                || selection.getRanges()[ 0 ].checkReadOnly() )
    630630                                                        return null;
    631631
    632632                                                var scayt_control = plugin.getScayt( editor ),
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy