From 11dbf01ddf741b87b30e6bdcb3c4846f37d4fd71 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: Tue, 5 Apr 2016 04:36:29 +0800 Subject: [PATCH] Stator bug fix for UNDO / REDO --- botanjs/src/Components/Vim/Actions/INSERT.js | 35 ++++++++++++++++---- botanjs/src/Components/Vim/Actions/VISUAL.js | 2 +- botanjs/src/Components/Vim/Cursor.js | 4 ++- botanjs/src/Components/Vim/State/Stator.js | 13 +++----- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/botanjs/src/Components/Vim/Actions/INSERT.js b/botanjs/src/Components/Vim/Actions/INSERT.js index 759aec6..b37562d 100644 --- a/botanjs/src/Components/Vim/Actions/INSERT.js +++ b/botanjs/src/Components/Vim/Actions/INSERT.js @@ -30,6 +30,8 @@ this.__cursor = Cursor; this.__stator = new Stator( Cursor ); + this.__minReach = 0; + this.__insertLen = 0; // Initialize this stack this.__rec( "", true ); @@ -57,18 +59,27 @@ if( this.__stack ) { // If nothings changed - if( this.__insertLength == 0 + if( this.__minReach == 0 + && this.__punch == 0 && this.__contentUndo === "" ) return; + if( this.__punch < this.__minReach ) + { + this.__minReach = this.__punch; + } + this.__stack.store( - this.__stator.save( this.__insertLength, this.__contentUndo ) + this.__stator.save( + this.__insertLen + , this.__contentUndo + , -this.__minReach ) ); this.__cursor.rec.record( this.__stack ); } - this.__insertLength = 0; + this.__punch = 0; this.__contentUndo = ""; this.__stack = new Stack(); } @@ -78,7 +89,14 @@ // todo } - this.__insertLength += c.length; + if( this.__punch < this.__minReach ) + { + this.__insertLen = 0; + this.__minReach = this.__punch; + } + + this.__punch += c.length; + this.__insertLen += c.length; }; INSERT.prototype.__specialKey = function( e, inputChar ) @@ -96,7 +114,7 @@ var f = cur.aPos; - if( this.__insertLength <= 0 ) + if( this.__punch <= this.__minReach ) { this.__contentUndo = feeder.content.substr( f, 1 ) + this.__contentUndo; } @@ -105,7 +123,8 @@ feeder.content.substring( 0, f ) + feeder.content.substring( f + 1 ); - this.__insertLength --; + if( 0 < this.__insertLen ) this.__insertLen --; + this.__punch --; } else if( e.kMap( "Del" ) ) { @@ -126,6 +145,9 @@ INSERT.prototype.handler = function( e ) { e.preventDefault(); + + if( e.ModKeys ) return; + var inputChar = Translate( e.key ); if( inputChar.length != 1 ) @@ -160,7 +182,6 @@ feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) ); this.__rec( inputChar ); - }; INSERT.prototype.getMessage = function() diff --git a/botanjs/src/Components/Vim/Actions/VISUAL.js b/botanjs/src/Components/Vim/Actions/VISUAL.js index b53b47d..d650abd 100644 --- a/botanjs/src/Components/Vim/Actions/VISUAL.js +++ b/botanjs/src/Components/Vim/Actions/VISUAL.js @@ -294,7 +294,7 @@ var i = 0; do { - if( line.lineNum == l ) break; + if( line.lineNum == l || line.placeholder ) break; pstart += line.toString().length + 1; } while( line = line.next ); diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js index 876614e..0fddee3 100644 --- a/botanjs/src/Components/Vim/Cursor.js +++ b/botanjs/src/Components/Vim/Cursor.js @@ -147,7 +147,9 @@ if( 0 < this.__off ) { - d += this.__off; + if( 0 < d && phantomSpace ) + d += this.__off; + this.__off = 0; } diff --git a/botanjs/src/Components/Vim/State/Stator.js b/botanjs/src/Components/Vim/State/Stator.js index a17687d..e3efae5 100644 --- a/botanjs/src/Components/Vim/State/Stator.js +++ b/botanjs/src/Components/Vim/State/Stator.js @@ -8,17 +8,12 @@ this.__startState = this.__saveCur(); }; - Stator.prototype.save = function( insertLength, contentUndo ) + Stator.prototype.save = function( insertLength, contentUndo, removeLen ) { + if( removeLen == undefined ) removeLen = 0; var cur = this.__cursor; var feeder = cur.feeder; - var startPos = this.__startPosition; - - if( insertLength < 0 ) - { - startPos += insertLength; - insertLength = 0; - } + var startPos = this.__startPosition - removeLen; var sSt = this.__startState; var eSt = this.__saveCur(); @@ -38,6 +33,7 @@ cur.PEnd = st.p + 1; cur.X = st.x; cur.Y = st.y; + cur.pX = st.cpX - 1; feeder.panX = st.px; feeder.panY = st.py; @@ -54,6 +50,7 @@ p: c.PStart , x: c.X , y: c.Y + , cpX: c.pX , px: c.feeder.panX , py: c.feeder.panY };