Ticket #3730: 3730_2.patch

File 3730_2.patch, 8.2 KB (added by Garry Yao, 15 years ago)
  • _source/tests/plugins/indent/indent.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: indent</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                                callback.call( context, editor );
     33                        }
     34                }, this );
     35
     36        mode = mode || CKEDITOR.ELEMENT_MODE_REPLACE;
     37        switch( mode )
     38        {
     39                case CKEDITOR.ELEMENT_MODE_REPLACE :
     40                        CKEDITOR.replace( elementId, config );
     41                        break;
     42                case CKEDITOR.ELEMENT_MODE_APPENDTO :
     43                        CKEDITOR.appendTo( elementId, config );
     44                        break;
     45        }
     46}
     47
     48/**
     49 * IE always returning CRLF for line-feed, so remove it when retrieving
     50 * pre-formated text from text area.
     51 */
     52function getTextAreaValue( id )
     53{
     54        return CKEDITOR.document.getById( id ).getValue().replace( /\r/gi, '' );
     55}
     56
     57CKEDITOR.test.addTestCase( ( function()
     58        {
     59
     60                // Local references.
     61                var assert = CKEDITOR.test.assert,
     62                        doc = CKEDITOR.document,
     63                        action = YAHOO.util.UserAction,
     64                        selector = YAHOO.util.Selector;
     65
     66                /**
     67                 * Set the range with the start/end position specified by the locator, which in form of bookmark2.
     68                 * @param {Object} range
     69                 * @param {Array} startPosition range start path including offset
     70                 * @param {Array|Boolean} endPositoin range end path including offset or is collapsed
     71                 */
     72                function setRange( range, startPosition, endPositoin )
     73                {
     74                        var bm = {
     75                                end : null,
     76                                start : null,
     77                                is2: true,
     78                                startOffset : 0,
     79                                endoffset : 0
     80                        };
     81                        bm.start = startPosition.slice( 0, startPosition.length - 1 );
     82                        bm.startOffset = startPosition[ startPosition.length -1];
     83                        if( endPositoin === true )
     84                        {
     85                                bm.end = bm.start.slice();
     86                                bm.endOffset = bm.startOffset;
     87                        }
     88                        else
     89                        {
     90                                bm.end = endPositoin.slice( 0, endPositoin.length - 1 );
     91                                bm.endOffset = endPositoin[ endPositoin.length -1 ];
     92                        }
     93                        range.moveToBookmark( bm );
     94                }
     95
     96                return  {
     97
     98                        /**
     99                         *  Test indent multiple lines with 'enterMode = BR' inside <div>
     100                         */
     101                        test_ticket_3730 : function()
     102                        {
     103                                prepareEditor( 'test_ticket_3730_editor', null,
     104                                        { enterMode : CKEDITOR.ENTER_BR },
     105                                        function( editor )
     106                                        {
     107                                                this.resume( function()
     108                                                {
     109                                                        editor.focus();
     110
     111                                                        var doc = editor.document,
     112                                                                range = new CKEDITOR.dom.range( doc );
     113
     114                                                        setRange( range, [ 1, 0, 2, 2 ], [ 1, 0, 4, 2 ] );
     115                                                        var sel = editor.getSelection();
     116                                                        sel.selectRanges( [ range ] );
     117                                                        // Waiting for 'comand state' effected.
     118                                                        this.wait( function(){
     119                                                                // Remove list.
     120                                                                editor.execCommand( 'indent' );
     121                                                                assert.areSame( getTextAreaValue( 'test_ticket_3730_result' ),
     122                                                                        editor.getData(),
     123                                                                        'Indent result not correct.' );
     124                                                        }, 1000 );
     125
     126                                                } );
     127                                        }, this );
     128                                        this.wait();
     129                        },
     130
     131                        /**
     132                         *  Test indent multiple lines with 'enterMode = BR' inside <p>.
     133                         */
     134                        test_ticket_3730_2 : function()
     135                        {
     136                                prepareEditor( 'test_ticket_3730_2_editor', null,
     137                                        { enterMode : CKEDITOR.ENTER_BR },
     138                                        function( editor )
     139                                        {
     140                                                this.resume( function()
     141                                                {
     142                                                        editor.focus();
     143
     144                                                        var doc = editor.document,
     145                                                                range = new CKEDITOR.dom.range( doc );
     146
     147                                                        setRange( range, [ 1, 0, 2, 2 ], [ 1, 0, 4, 2 ] );
     148                                                        var sel = editor.getSelection();
     149                                                        sel.selectRanges( [ range ] );
     150                                                        // Waiting for 'comand state' effected.
     151                                                        this.wait( function(){
     152                                                                // Remove list.
     153                                                                editor.execCommand( 'indent' );
     154                                                                assert.areSame( getTextAreaValue( 'test_ticket_3730_2_result' ),
     155                                                                        editor.getData(),
     156                                                                        'Indent result not correct.' );
     157                                                        }, 1000 );
     158
     159                                                } );
     160                                        }, this );
     161                                        this.wait();
     162                        },
     163
     164                        /**
     165                         *  Test indent multiple lines with 'enterMode = BR' inside <body>
     166                         */
     167                        test_ticket_3730_3 : function()
     168                        {
     169                                prepareEditor( 'test_ticket_3730_3_editor', null,
     170                                        { enterMode : CKEDITOR.ENTER_BR },
     171                                        function( editor )
     172                                        {
     173                                                this.resume( function()
     174                                                {
     175                                                        editor.focus();
     176
     177                                                        var doc = editor.document,
     178                                                                range = new CKEDITOR.dom.range( doc );
     179
     180                                                        setRange( range, [ 1, 2, 2 ], [ 1, 4, 2 ] );
     181                                                        var sel = editor.getSelection();
     182                                                        sel.selectRanges( [ range ] );
     183                                                        // Waiting for 'comand state' effected.
     184                                                        this.wait( function(){
     185                                                                // Remove list.
     186                                                                editor.execCommand( 'indent' );
     187                                                                assert.areSame( getTextAreaValue( 'test_ticket_3730_3_result' ),
     188                                                                        editor.getData(),
     189                                                                        'Indent result not correct.' );
     190                                                        }, 1000 );
     191
     192                                                } );
     193                                        }, this );
     194                                        this.wait();
     195                        },
     196                       
     197                        name :document.title
     198                };
     199        } )() );
     200        //]]>
     201        </script>
     202</head>
     203<body>
     204<textarea id="test_ticket_3730_editor"><div>test1<br/>test2<br/>test3<br/>test4<br/></div></textarea>
     205<textarea id="test_ticket_3730_result"><div>test1</div><div style="margin-left: 40px;">test2<br />test3</div><div>test4</div></textarea></body>
     206<textarea id="test_ticket_3730_2_editor"><p>test1<br/>test2<br/>test3<br/>test4<br/></p></textarea>
     207<textarea id="test_ticket_3730_2_result"><p>test1</p><p style="margin-left: 40px;">test2<br />test3</p><p>test4</p></textarea></body>
     208<textarea id="test_ticket_3730_3_editor">test1<br/>test2<br/>test3<br/>test4<br/></textarea>
     209<textarea id="test_ticket_3730_3_result">test1<p style="margin-left: 40px;">test2<br />test3</p>test4<br /></textarea></body>
     210</html>
  • _source/plugins/domiterator/plugin.js

     
    1919
    2020                this.range = range;
    2121                this.forceBrBreak = false;
     22
     23                // Whether include <br>s into the enlarged range.(#3730).
     24                this.enlargeBr = true;
    2225                this.enforceRealBlocks = false;
    2326
    2427                this._ || ( this._ = {} );
     
    4548                        if ( !this._.lastNode )
    4649                        {
    4750                                range = this.range.clone();
    48                                 range.enlarge( this.forceBrBreak ? CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS : CKEDITOR.ENLARGE_BLOCK_CONTENTS );
     51                                range.enlarge( this.forceBrBreak || !this.enlargeBr ?
     52                                                           CKEDITOR.ENLARGE_LIST_ITEM_CONTENTS : CKEDITOR.ENLARGE_BLOCK_CONTENTS );
    4953
    5054                                var walker = new CKEDITOR.dom.walker( range ),
    5155                                        ignoreBookmarkTextEvaluator = CKEDITOR.dom.walker.bookmark( true, true );
  • _source/plugins/indent/plugin.js

     
    153153
    154154        function indentBlock( editor, range )
    155155        {
    156                 var iterator = range.createIterator();
     156                var iterator = range.createIterator(),
     157                        enterMode = editor.config.enterMode;
    157158                iterator.enforceRealBlocks = true;
    158 
     159                iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR;
    159160                var block;
    160161                while ( ( block = iterator.getNextParagraph() ) )
    161162                {
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy