From 865530709be88a85744a85b01c9d4bddcf2e9642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Thu, 17 Mar 2016 06:08:38 +0800 Subject: [PATCH] Proper REDO / UNDO function ( without cursor pos ) --- botanjs/src/Components/Vim/Actions/INSERT.js | 19 ++++++++++--------- botanjs/src/Components/Vim/Controls.js | 2 +- botanjs/src/Components/Vim/State/Recorder.js | 13 ++++--------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/botanjs/src/Components/Vim/Actions/INSERT.js b/botanjs/src/Components/Vim/Actions/INSERT.js index 367e6b0..708dd44 100644 --- a/botanjs/src/Components/Vim/Actions/INSERT.js +++ b/botanjs/src/Components/Vim/Actions/INSERT.js @@ -57,6 +57,7 @@ INSERT.prototype.dispose = function() { + this.__cursor.moveX( -1 ); this.__rec( "", true ); }; @@ -68,12 +69,6 @@ var contentUndo = this.__contentUndo; var startPos = this.__startPosition; - if( insertLength < 0 ) - { - startPos += insertLength; - insertLength = 0; - } - return function() { var contentRedo = feeder.content.substr( startPos, insertLength ); feeder.content = @@ -128,8 +123,15 @@ var f = ContentPosition( feeder ); - this.__contentUndo = feeder.content.substr( f, 1 ) + this.__contentUndo; - this.__insertLength --; + if( this.__insertLength <= 0 ) + { + this.__contentUndo = feeder.content.substr( f, 1 ) + this.__contentUndo; + this.__startPosition --; + } + else + { + this.__insertLength --; + } feeder.content = feeder.content.substring( 0, f ) @@ -140,7 +142,6 @@ var f = ContentPosition( feeder ); this.__contentUndo += feeder.content.substr( f, 1 ); - this.__insertLength ++; feeder.content = feeder.content.substring( 0, f ) diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js index eacb150..794202c 100644 --- a/botanjs/src/Components/Vim/Controls.js +++ b/botanjs/src/Components/Vim/Controls.js @@ -45,7 +45,7 @@ e.preventDefault(); var kCode = e.keyCode - + ( e.shiftKey ? SHIFT : 0 ) + + ( e.shiftKey || e.getModifierState( "CapsLock" ) ? SHIFT : 0 ) + ( e.ctrlKey ? CTRL : 0 ); var cfeeder = sender.contentFeeder; diff --git a/botanjs/src/Components/Vim/State/Recorder.js b/botanjs/src/Components/Vim/State/Recorder.js index 2fe9081..1ba8a59 100644 --- a/botanjs/src/Components/Vim/State/Recorder.js +++ b/botanjs/src/Components/Vim/State/Recorder.js @@ -13,19 +13,16 @@ if( i == -1 || !this.__steps.length ) return null; - this.__i -= 2; - return this.__steps[ i ]; + return this.__steps[ this.__i = i ]; }; Recorder.prototype.redo = function() { - var i = this.__i + 1; - if( i == -1 || !this.__steps.length ) return null; + var State = this.__steps[ this.__i ]; - var State = this.__steps[ i ]; if( State ) { - this.__i += 2; + this.__i ++; return State; } @@ -35,9 +32,7 @@ Recorder.prototype.record = function( StateObj ) { this.__steps[ this.__i ] = StateObj; - StateObj.id = this.__i; - - delete this.__steps[ ++ this.__i ]; + StateObj.id = this.__i ++; }; ns[ NS_EXPORT ]( EX_CLASS, "Recorder", Recorder );