Ticket #3372: 3372_4.patch

File 3372_4.patch, 2.0 KB (added by Tobiasz Cudnik, 15 years ago)
  • _source/plugins/undo/plugin.js

     
    8282                                                                {
    8383                                                                        // Do not capture CTRL hotkeys.
    8484                                                                        if ( !event.data.$.ctrlKey && !event.data.$.metaKey )
    85                                                                                 undoManager.type();
     85                                                                                undoManager.type( event );
    8686                                                                });
    8787
    8888                                                        // Being this the first call, let's get an undo snapshot.
     
    182182                this.index = -1;
    183183
    184184                this.limit = editor.config.undoStackSize;
     185
     186                /**
     187                 * Remember last pressed key.
     188                 */
     189                this.lastKeystroke = 0;
    185190        }
    186191
    187192        UndoManager.prototype =
    188193        {
    189                 type : function()
     194                /**
     195                 *
     196                 * @param {CKEDITOR.dom.event} [event]
     197                 */
     198                type : function( event )
    190199                {
    191                         if ( !this.typing )
     200                        var keystroke = event && event.data.getKeystroke(),
     201                                // Backspace, Delete
     202                                modifierCodes = { 8:1, 46:1 },
     203                                // Arrows: L, T, R, B
     204                                resetTypingCodes = { 37:1, 38:1, 39:1, 40:1 },
     205                                isModifier = keystroke in modifierCodes,
     206                                lastWasSameModifier = isModifier && keystroke == this.lastKeystroke,
     207                                modifierSnapshot = isModifier  && !lastWasSameModifier;
     208                       
     209                        if ( !this.typing || modifierSnapshot )
    192210                        {
    193211                                var beforeTypeImage = new Image( this.editor );
    194212
     
    219237                                                        this.onChange();
    220238                                                }
    221239                                        },
    222                                         0, this );
     240                                        0, this
     241                                );
    223242
    224                                 return;
     243                                if ( !modifierSnapshot )
     244                                        return;
    225245                        }
     246                        this.lastKeystroke = keystroke;
    226247
    227                         this.typesCount++;
     248                        if ( keystroke in resetTypingCodes )
     249                                this.typing = false;
     250                        else
     251                        {
     252                                this.typesCount++;
    228253
    229                         if ( this.typesCount > 25 )
    230                         {
    231                                 this.save();
    232                                 this.typesCount = 1;
    233                         }
     254                                if ( this.typesCount > 25 )
     255                                {
     256                                        this.save();
     257                                        this.typesCount = 1;
     258                                }
    234259
    235                         this.typing = true;
     260                                this.typing = true;
     261                        }
    236262                },
    237263
    238264                fireChange : function()
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy