Ticket #1630: 1630_2_ref.patch

File 1630_2_ref.patch, 10.0 KB (added by Tobiasz Cudnik, 15 years ago)
  • _source/plugins/undo/plugin.js

     
    2222                                {
    2323                                        exec : function()
    2424                                        {
     25                                                console.log('UNDO request')
    2526                                                if ( undoManager.undo() )
    2627                                                {
    2728                                                        editor.selectionChange();
     
    2930                                                }
    3031                                        },
    3132                                        state : CKEDITOR.TRISTATE_DISABLED,
    32                                         canUndo : false
     33                                        canUndo : false,
     34                                        modes : { wysiwyg : 1, source : 1 }
    3335                                });
    3436
    3537                        var redoCommand = editor.addCommand( 'redo',
    3638                                {
    3739                                        exec : function()
    3840                                        {
     41                                                console.log('REDO request')
    3942                                                if ( undoManager.redo() )
    4043                                                {
    4144                                                        editor.selectionChange();
     
    4346                                                }
    4447                                        },
    4548                                        state : CKEDITOR.TRISTATE_DISABLED,
    46                                         canUndo : false
     49                                        canUndo : false,
     50                                        modes : { wysiwyg : 1, source : 1 }
    4751                                });
    4852
    4953                        undoManager.onChange = function()
     
    8084                                                });
    8185                                });
    8286
     87                        // Registering keydown on every source area recreation.
     88                        editor.on( 'contentSource', function( e )
     89                                {
     90                                        e.data.on( 'keydown', function( event )
     91                                                {
     92                                                        // Do not capture CTRL hotkeys.
     93                                                        if ( !event.data.$.ctrlKey && !event.data.$.metaKey )
     94                                                                undoManager.type( event );
     95                                                });
     96                                });
     97
    8398                        // Always save an undo snapshot - the previous mode might have
    8499                        // changed editor contents.
    85100                        editor.on( 'beforeModeUnload', function()
     
    87102                                        editor.mode == 'wysiwyg' && undoManager.save( true );
    88103                                });
    89104
    90                         // Make the undo manager available only in wysiwyg mode.
    91                         editor.on( 'mode', function()
    92                                 {
    93                                         undoManager.enabled = editor.mode == 'wysiwyg';
    94                                         undoManager.onChange();
    95                                 });
    96 
    97105                        editor.ui.addButton( 'Undo',
    98106                                {
    99107                                        label : editor.lang.undo,
     
    122130        {
    123131                var selection = editor.getSelection();
    124132
    125                 this.contents   = editor.getSnapshot();
     133                this.mode = {};
     134                this.mode[ editor.mode ] = { contents : editor.getSnapshot() };
     135                // TODO normalize bookmarks per mode ?
    126136                this.bookmarks  = selection && selection.createBookmarks2( true );
    127137
    128138                // In IE, we need to remove the expando attributes.
    129139                if ( CKEDITOR.env.ie )
    130                         this.contents = this.contents.replace( /\s+_cke_expando=".*?"/g, '' );
     140                        this.mode[ editor.mode ].contents = this.contents.replace( /\s+_cke_expando=".*?"/g, '' );
    131141        }
    132142
    133143        Image.prototype =
    134144        {
    135                 equals : function( otherImage, contentOnly )
     145                equals : function( otherImage, contentOnly, editor )
    136146                {
    137                         if ( this.contents != otherImage.contents )
     147                        if ( this.getContents( editor ) != otherImage.getContents( editor ) )
    138148                                return false;
    139149
    140150                        if ( contentOnly )
    141151                                return true;
    142152
     153                        // TODO normalize bookmarks per mode ?
    143154                        var bookmarksA = this.bookmarks,
    144155                                bookmarksB = otherImage.bookmarks;
    145156
     
    165176                        }
    166177
    167178                        return true;
     179                },
     180
     181                getContents : function( editor )
     182                {
     183                        // Initialize actual editor's mode for this image if missing.
     184                        if ( !this.mode[ editor.mode ] )
     185                        {
     186                                this.mode[ editor.mode ] = {};
     187                               
     188                                // Normalize data from first available mode.
     189                                for ( var i in this.mode )
     190                                        return this.mode[ editor.mode ].contents = editor.normalizeSnapshotData( this.mode[ i ].contents );
     191                        }
     192                        return this.mode[ editor.mode ].contents;
    168193                }
    169194        };
    170195
     
    174199        function UndoManager( editor )
    175200        {
    176201                this.editor = editor;
     202                this.enabled = true;
    177203
    178204                // Reset the undo stack.
    179205                this.reset();
     
    318344                },
    319345                fireChange : function()
    320346                {
     347                        console.log( 'fireChange()')
    321348                        this.hasUndo = !!this.getNextImage( true );
    322349                        this.hasRedo = !!this.getNextImage( false );
    323350                        // Reset typing
     
    337364                                image = new Image( this.editor );
    338365
    339366                        // Check if this is a duplicate. In such case, do nothing.
    340                         if ( this.currentImage && image.equals( this.currentImage, onContentOnly ) )
     367                        if ( this.currentImage && image.equals( this.currentImage, onContentOnly, this.editor ) )
    341368                                return false;
    342369
    343370                        // Drop future snapshots.
     
    359386
    360387                restoreImage : function( image )
    361388                {
    362                         this.editor.loadSnapshot( image.contents );
     389                        this.editor.loadSnapshot( image.getContents( this.editor ) );
    363390
    364                         if ( image.bookmarks )
    365                                 this.editor.getSelection().selectBookmarks( image.bookmarks );
     391                        var selection = image.bookmarks && this.editor.getSelection();
     392                        if ( selection )
     393                                selection.selectBookmarks( image.bookmarks );
     394                        // TODO range
    366395                        else if ( CKEDITOR.env.ie )
    367396                        {
    368397                                // IE BUG: If I don't set the selection to *somewhere* after setting
     
    374403                        }
    375404
    376405                        this.index = image.index;
    377 
     406console.log('UPDATE currentImage')
    378407                        this.currentImage = image;
    379408
    380409                        this.fireChange();
     
    387416                                currentImage = this.currentImage,
    388417                                image, i;
    389418
     419                        console.log( 'getNextImage()' );
     420
    390421                        if ( currentImage )
    391422                        {
     423                                console.log( 'currentImage.contents:\n', currentImage.getContents( this.editor ) )
    392424                                if ( isUndo )
    393425                                {
    394426                                        for ( i = this.index - 1 ; i >= 0 ; i-- )
    395427                                        {
    396428                                                image = snapshots[ i ];
    397                                                 if ( !currentImage.equals( image, true ) )
     429                                                if ( !currentImage.equals( image, true, this.editor ) )
    398430                                                {
     431                                                        console.log( 'RETURN image.contents:\n', image.getContents( this.editor ) )
    399432                                                        image.index = i;
    400433                                                        return image;
    401434                                                }
     435                                                else console.log( 'image.contents:\n', image.getContents( this.editor ) )
    402436                                        }
    403437                                }
    404438                                else
     
    406440                                        for ( i = this.index + 1 ; i < snapshots.length ; i++ )
    407441                                        {
    408442                                                image = snapshots[ i ];
    409                                                 if ( !currentImage.equals( image, true ) )
     443                                                if ( !currentImage.equals( image, true, this.editor ) )
    410444                                                {
    411445                                                        image.index = i;
    412446                                                        return image;
  • _source/plugins/sourcearea/plugin.js

     
    1515        init : function( editor )
    1616        {
    1717                var sourcearea = CKEDITOR.plugins.sourcearea;
     18               
     19                var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )
     20                        ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;
    1821
    1922                editor.on( 'editingBlockReady', function()
    2023                        {
     
    100103                                                        {
    101104                                                                editor.mode = 'source';
    102105                                                                editor.fire( 'mode' );
     106                                                                editor.fire( 'contentSource', textarea );
    103107                                                        },
    104108                                                        ( CKEDITOR.env.gecko || CKEDITOR.env.webkit ) ? 100 : 0 );
    105109                                                },
     
    116120
    117121                                                getSnapshotData : function()
    118122                                                {
     123                                                        var fixForBody = ( editor.config.enterMode != CKEDITOR.ENTER_BR )
     124                                                                ? editor.config.enterMode == CKEDITOR.ENTER_DIV ? 'div' : 'p' : false;
     125                                                        console.log('REQUESTED undo snashot')
     126
     127//                                                      if ( editor.dataProcessor )
     128//                                                      {
     129//                                                              var rules = editor.dataProcessor.writer._.rules;
     130//                                                              // Reset rules to get non-formatted output.
     131//                                                              editor.dataProcessor.writer._.rules = [];
     132//                                                              var data = editor.dataProcessor.toDataFormat( textarea.getValue(), fixForBody );
     133//                                                              editor.dataProcessor.writer._.rules = rules;
     134//                                                              return data;
     135//                                                      }
     136
    119137                                                        return textarea.getValue();
    120138                                                },
    121139
     140                                                loadSnapshotData : function( data )
     141                                                {
     142                                                        textarea.setValue( data );
     143
     144                                                        console.log('LOADED undo snashot')
     145                                                },
     146
     147                                                normalizeSnapshotData : function( data )
     148                                                {
     149                                                        if ( editor.dataProcessor )
     150                                                                data = editor.dataProcessor.toDataFormat( data, fixForBody );
     151
     152                                                        // TODO ? Strip the last blank paragraph within document.
     153//                                                      if ( editor.config.ignoreEmptyParagraph )
     154//                                                              data = data.replace( emptyParagraphRegexp, '' );
     155
     156                                                        return data;
     157                                                },
     158
    122159                                                unload : function( holderElement )
    123160                                                {
    124161                                                        editor.textarea = textarea = null;
  • _source/plugins/editingblock/plugin.js

     
    8282                                                event.data = getMode( editor ).getSnapshotData();
    8383                                });
    8484
     85                        editor.on( 'normalizeSnapshotData', function( event )
     86                                {
     87                                        if ( editor.mode )
     88                                                event.data = getMode( editor ).normalizeSnapshotData( event.data );
     89                                });
     90
    8591                        editor.on( 'loadSnapshot', function( event )
    8692                                {
    8793                                        if ( editor.mode )
  • _source/plugins/wysiwygarea/plugin.js

     
    552552
    553553                                                        getSnapshotData : function()
    554554                                                        {
     555                                                                console.log('REQUESTED undo snashot')
    555556                                                                return iframe.getFrameDocument().getBody().getHtml();
    556557                                                        },
    557558
     
    560561                                                                iframe.getFrameDocument().getBody().setHtml( data );
    561562                                                        },
    562563
     564                                                        normalizeSnapshotData : function( data )
     565                                                        {
     566                                                                return editor.dataProcessor
     567                                                                        ? data = editor.dataProcessor.toHtml( data, fixForBody )
     568                                                                        : data;
     569                                                        },
     570
    563571                                                        unload : function( holderElement )
    564572                                                        {
    565573                                                                editor.window = editor.document = iframe = mainElement = isPendingFocus = null;
  • _source/core/editor.js

     
    474474                execCommand : function( commandName, data )
    475475                {
    476476                        var command = this.getCommand( commandName );
     477                        console.log('command.state: ' + command.state, command )
    477478
    478479                        var eventData =
    479480                        {
     
    559560                        return data;
    560561                },
    561562
     563                normalizeSnapshotData : function( data )
     564                {
     565                        return this.fire( 'normalizeSnapshotData', data );
     566                },
     567
    562568                loadSnapshot : function( snapshot )
    563569                {
    564570                        this.fire( 'loadSnapshot', snapshot );
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy