Ticket #4673: 4673.patch

File 4673.patch, 2.7 KB (added by Garry Yao, 14 years ago)
  • _source/plugins/undo/plugin.js

     
    179179                this.reset();
    180180        }
    181181
     182
     183        var editingKeyCodes = { /*Backspace*/ 8:1, /*Delete*/ 46:1, /*Space*/ 32:1 , /*Tab*/ 9:1 },
     184                modifierKeyCodes = { /*Shift*/ 16:1, /*Ctrl*/ 17:1, /*Alt*/ 18:1 },
     185                navigationKeyCodes = { 37:1, 38:1, 39:1, 40:1 };  // Arrows: L, T, R, B
     186
    182187        UndoManager.prototype =
    183188        {
    184189                /**
     
    187192                 */
    188193                type : function( event )
    189194                {
    190                         var keystroke = event && event.data.getKeystroke(),
    191 
    192                                 // Backspace, Delete
    193                                 modifierCodes = { 8:1, 46:1 },
    194                                 // Keystrokes which will modify the contents.
    195                                 isModifier = keystroke in modifierCodes,
    196                                 wasModifier = this.lastKeystroke in modifierCodes,
    197                                 lastWasSameModifier = isModifier && keystroke == this.lastKeystroke,
    198 
    199                                 // Arrows: L, T, R, B
    200                                 resetTypingCodes = { 37:1, 38:1, 39:1, 40:1 },
     195                        var keystroke = event && event.data.getKey(),
     196                                isModifierKey = keystroke in modifierKeyCodes,
     197                                isEditingKey = keystroke in editingKeyCodes,
     198                                wasEditingKey = this.lastKeystroke in editingKeyCodes,
     199                                sameAsLastEditingKey = isEditingKey && keystroke == this.lastKeystroke,
    201200                                // Keystrokes which navigation through contents.
    202                                 isReset = keystroke in resetTypingCodes,
    203                                 wasReset = this.lastKeystroke in resetTypingCodes,
     201                                isReset = keystroke in navigationKeyCodes,
     202                                wasReset = this.lastKeystroke in navigationKeyCodes,
    204203
    205204                                // Keystrokes which just introduce new contents.
    206                                 isContent = ( !isModifier && !isReset ),
     205                                isContent = ( !isEditingKey && !isReset ),
    207206
    208207                                // Create undo snap for every different modifier key.
    209                                 modifierSnapshot = ( isModifier && !lastWasSameModifier ),
     208                                modifierSnapshot = ( isEditingKey && !sameAsLastEditingKey ),
    210209                                // Create undo snap on the following cases:
    211                                 // 1. Just start to type.
     210                                // 1. Just start to type .
    212211                                // 2. Typing some content after a modifier.
    213212                                // 3. Typing some content after make a visible selection.
    214                                 startedTyping = !this.typing
    215                                         || ( isContent && ( wasModifier || wasReset ) );
     213                                startedTyping = !( isModifierKey || this.typing )
     214                                        || ( isContent && ( wasEditingKey || wasReset ) );
    216215
    217216                        if ( startedTyping || modifierSnapshot )
    218217                        {
     
    250249                        }
    251250
    252251                        this.lastKeystroke = keystroke;
     252
     253                        // Ignore modifier keys. (#4673)
     254                        if( isModifierKey )
     255                                return;
    253256                        // Create undo snap after typed too much (over 25 times).
    254                         if ( isModifier )
     257                        if ( isEditingKey )
    255258                        {
    256259                                this.typesCount = 0;
    257260                                this.modifiersCount++;
© 2003 – 2022, CKSource sp. z o.o. sp.k. All rights reserved. | Terms of use | Privacy policy