Stator bug fix for UNDO / REDO

This commit is contained in:
斟酌 鵬兄 2016-04-05 04:36:29 +08:00
parent fcfe5d9b60
commit 11dbf01ddf
4 changed files with 37 additions and 17 deletions

View File

@ -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()

View File

@ -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 );

View File

@ -147,7 +147,9 @@
if( 0 < this.__off )
{
d += this.__off;
if( 0 < d && phantomSpace )
d += this.__off;
this.__off = 0;
}

View File

@ -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
};