Ticket #3949: 3949.patch

File 3949.patch, 6.0 KB (added by Garry Yao, 15 years ago)
  • _source/tests/plugins/enterkey/enterkey.html

     
     1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     2<html xmlns="http://www.w3.org/1999/xhtml">
     3<head>
     4        <title>Plugin: Enterkey</title>
     5        <link rel="stylesheet" type="text/css" href="../../test.css" />
     6        <script type="text/javascript" src="../../../../ckeditor_source.js"></script>
     7        <script type="text/javascript" src="../../test.js"></script>
     8        <script type="text/javascript">
     9        //<![CDATA[
     10/**
     11 * Load the editor and wait for fully interactable.
     12 * @param {Object} elementId
     13 * @parma {Object} mode
     14 * @param {Object} config
     15 * @param {Object} callback Continuation with {@param editor}.
     16 * @param {Object} context
     17 */
     18function prepareEditor( elementId, mode, config, callback, context )
     19{
     20        CKEDITOR.on( 'instanceReady',
     21                function( evt )
     22                {
     23                        var isMe = mode == CKEDITOR.ELEMENT_MODE_REPLACE ?
     24                                evt.editor.name == elementId
     25                                : evt.editor.element.$ ==
     26                                        document.getElementById( elementId );
     27                        if ( isMe )
     28                        {
     29                                var editor = evt.editor;
     30                                // Force result data unformatted.
     31                                editor.dataProcessor.writer._.rules = {};
     32                                // Force remove tail br.
     33                                editor.dataProcessor.htmlFilter.addRules( {
     34                                        elements : {
     35                                                'br' : function( br ){
     36                                                        var parent = br.parent,
     37                                                                length = parent.children.length,
     38                                                                lastChild = parent.children[ length - 1 ];
     39                                                        if( lastChild == br )
     40                                                                return false;
     41                                                }
     42                                        }
     43                                } );
     44                                callback.call( context, editor );
     45                        }
     46                }, this );
     47
     48        mode = mode || CKEDITOR.ELEMENT_MODE_REPLACE;
     49        switch( mode )
     50        {
     51                case CKEDITOR.ELEMENT_MODE_REPLACE :
     52                        CKEDITOR.replace( elementId, config );
     53                        break;
     54                case CKEDITOR.ELEMENT_MODE_APPENDTO :
     55                        CKEDITOR.appendTo( elementId, config );
     56                        break;
     57        }
     58}
     59
     60function getTextAreaValue( id )
     61{
     62        return CKEDITOR.document.getById( id ).getValue();
     63}
     64
     65CKEDITOR.test.addTestCase( ( function()
     66        {
     67
     68                // Local references.
     69                var assert = CKEDITOR.test.assert,
     70                        doc = CKEDITOR.document,
     71                        action = YAHOO.util.UserAction,
     72                        selector = YAHOO.util.Selector;
     73
     74                /**
     75                 * Set the range with the start/end position specified by the locator, which in form of bookmark2.
     76                 * @param {Object} range
     77                 * @param {Array} startPosition range start path including offset
     78                 * @param {Array|Boolean} endPositoin range end path including offset or is collapsed
     79                 */
     80                function setRange( range, startPosition, endPositoin )
     81                {
     82                        var bm = {
     83                                end : null,
     84                                start : null,
     85                                is2: true,
     86                                startOffset : 0,
     87                                endoffset : 0
     88                        };
     89                        bm.start = startPosition.slice( 0, startPosition.length - 1 );
     90                        bm.startOffset = startPosition[ startPosition.length -1];
     91                        if( endPositoin === true )
     92                        {
     93                                bm.end = bm.start.slice();
     94                                bm.endOffset = bm.startOffset;
     95                        }
     96                        else
     97                        {
     98                                bm.end = endPositoin.slice( 0, endPositoin.length - 1 );
     99                                bm.endOffset = endPositoin[ endPositoin.length -1 ];
     100                        }
     101                        range.moveToBookmark( bm );
     102                }
     103
     104                return  {
     105
     106                        /**
     107                         *  Test press enter key right after existing line break inside <pre>.
     108                         */
     109                        test_ticket_3949 : function()
     110                        {
     111                                prepareEditor( 'test_ticket_3949_editor', null,
     112                                        { enterMode : CKEDITOR.ENTER_BR },
     113                                        function( editor )
     114                                        {
     115                                                this.resume( function()
     116                                                {
     117                                                        editor.focus();
     118
     119                                                        var doc = editor.document,
     120                                                                range = new CKEDITOR.dom.range( doc );
     121
     122                                                        // <pre>line1^\nline2</pre>
     123                                                        setRange( range, [ 1, 0, 0, 5 ], true );
     124                                                        var sel = editor.getSelection();
     125                                                        sel.selectRanges( [ range ] );
     126                                                        // 'Enter key' triggering.
     127                                                        editor.specialKeys[ 13 ]( editor );
     128                                                        this.wait( function(){
     129                                                                assert.areSame(
     130                                                                 getTextAreaValue( 'test_ticket_3949_result' ),
     131                                                                 editor.getData(),
     132                                                                 'Enter key result not correct.' );
     133                                                        }, 1000 );
     134
     135                                                } );
     136                                        }, this );
     137                                        this.wait();
     138                        },
     139
     140                        name :document.title
     141                };
     142        } )() );
     143        //]]>
     144        </script>
     145</head>
     146<body>
     147<textarea id="test_ticket_3949_editor"><pre>line1
     148line2</pre></textarea>
     149<textarea id="test_ticket_3949_result"><pre>line1
     150
     151line2</pre></textarea>
     152</body>
     153</html>
  • _source/plugins/selection/plugin.js

     
    491491                                                }
    492492
    493493                                                testRange.setEndPoint( 'StartToStart', range );
    494                                                 var distance = testRange.text.length;
     494                                                // IE report line break as CRLF with range.text but
     495                                                // only LF with textnode.nodeValue, normalize them to avoid
     496                                                // breaking character counting logic below. (#3949)
     497                                                var distance = testRange.text.replace( /(\r\n|\r)/g, '\n' ).length;
    495498
    496499                                                while ( distance > 0 )
    497500                                                        distance -= siblings[ --i ].nodeValue.length;
  • CHANGES.html

     
    130130                <li><a href="http://dev.fckeditor.net/ticket/3742">#3742</a> : Fixed wrong dialog layout for dialogs without tab bar in IE RTL mode .</li>
    131131                <li><a href="http://dev.fckeditor.net/ticket/3671">#3671</a> : Fixed body fixing should be applied to the real type under fake elements.</li>
    132132                <li><a href="http://dev.fckeditor.net/ticket/3836">#3836</a> : Fixed remove list in enterMode=BR will merge sibling text to one line.</li>
     133                <li><a href="http://dev.fckeditor.net/ticket/3949">#3949</a> : Fixed enterKey within pre-formatted text introduce wrong line-break.</li>
    133134        </ul>
    134135        <h3>
    135136                CKEditor 3.0 RC</h3>
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy