Ticket #3372: 3372_5.patch

File 3372_5.patch, 2.7 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.
     
    167167        function UndoManager( editor )
    168168        {
    169169                this.typesCount = 0;
     170                this.modifiersCount = 0;
    170171
    171172                this.editor = editor;
    172173
     
    182183                this.index = -1;
    183184
    184185                this.limit = editor.config.undoStackSize;
     186
     187                /**
     188                 * Remember last pressed key.
     189                 */
     190                this.lastKeystroke = 0;
    185191        }
    186192
    187193        UndoManager.prototype =
    188194        {
    189                 type : function()
     195                /**
     196                 *
     197                 * @param {CKEDITOR.dom.event} event
     198                 */
     199                type : function( event )
    190200                {
    191                         if ( !this.typing )
     201                        var keystroke = event && event.data.getKeystroke(),
     202                                isSelected = !this.editor.getSelection().getRanges()[0].collapsed,
     203
     204                                // Backspace, Delete
     205                                modifierCodes = { 8:1, 46:1 },
     206                                isModifier = keystroke in modifierCodes,
     207                                wasModifier = this.lastKeystroke in modifierCodes,
     208                                lastWasSameModifier = isModifier && keystroke == this.lastKeystroke,
     209
     210                                // Arrows: L, T, R, B
     211                                resetTypingCodes = { 37:1, 38:1, 39:1, 40:1 },
     212                                isReset = keystroke in resetTypingCodes,
     213                                wasReset = this.lastKeystroke in resetTypingCodes,
     214
     215                                isTyping = !isModifier && !isReset,
     216
     217                                modifierSnapshot = ( isModifier && !lastWasSameModifier ) || ( isTyping && isSelected ),
     218                                startedTyping = isTyping && ( wasModifier || wasReset );
     219
     220                        if ( startedTyping || modifierSnapshot )
    192221                        {
    193222                                var beforeTypeImage = new Image( this.editor );
    194223
     
    214243                                                        this.hasRedo = false;
    215244
    216245                                                        this.typesCount = 1;
    217                                                         this.typing = true;
     246                                                        this.modifiersCount = 1;
    218247
    219248                                                        this.onChange();
    220249                                                }
    221250                                        },
    222                                         0, this );
    223 
    224                                 return;
     251                                        0, this
     252                                );
    225253                        }
     254                        this.lastKeystroke = keystroke;
    226255
    227                         this.typesCount++;
     256                        if ( isModifier )
     257                        {
     258                                this.typesCount = 0;
     259                                this.modifiersCount++;
     260
     261                                if ( this.modifiersCount > 25 )
     262                                {
     263                                        this.save();
     264                                        this.modifiersCount = 1;
     265                                }
     266                        }
     267                        else if ( !isReset )
     268                        {
     269                                this.modifiersCount = 0;
     270                                this.typesCount++;
    228271
    229                         if ( this.typesCount > 25 )
    230                         {
    231                                 this.save();
    232                                 this.typesCount = 1;
    233                         }
    234 
    235                         this.typing = true;
     272                                if ( this.typesCount > 25 )
     273                                {
     274                                        this.save();
     275                                        this.typesCount = 1;
     276                                }
     277                        }
    236278                },
    237279
    238280                fireChange : function()
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy