forked from Botanical/BotanJS
Proper REDO / UNDO function ( without cursor pos )
This commit is contained in:
parent
f1653727f2
commit
865530709b
@ -57,6 +57,7 @@
|
|||||||
|
|
||||||
INSERT.prototype.dispose = function()
|
INSERT.prototype.dispose = function()
|
||||||
{
|
{
|
||||||
|
this.__cursor.moveX( -1 );
|
||||||
this.__rec( "", true );
|
this.__rec( "", true );
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,12 +69,6 @@
|
|||||||
var contentUndo = this.__contentUndo;
|
var contentUndo = this.__contentUndo;
|
||||||
var startPos = this.__startPosition;
|
var startPos = this.__startPosition;
|
||||||
|
|
||||||
if( insertLength < 0 )
|
|
||||||
{
|
|
||||||
startPos += insertLength;
|
|
||||||
insertLength = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return function() {
|
return function() {
|
||||||
var contentRedo = feeder.content.substr( startPos, insertLength );
|
var contentRedo = feeder.content.substr( startPos, insertLength );
|
||||||
feeder.content =
|
feeder.content =
|
||||||
@ -128,8 +123,15 @@
|
|||||||
|
|
||||||
var f = ContentPosition( feeder );
|
var f = ContentPosition( feeder );
|
||||||
|
|
||||||
this.__contentUndo = feeder.content.substr( f, 1 ) + this.__contentUndo;
|
if( this.__insertLength <= 0 )
|
||||||
this.__insertLength --;
|
{
|
||||||
|
this.__contentUndo = feeder.content.substr( f, 1 ) + this.__contentUndo;
|
||||||
|
this.__startPosition --;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.__insertLength --;
|
||||||
|
}
|
||||||
|
|
||||||
feeder.content =
|
feeder.content =
|
||||||
feeder.content.substring( 0, f )
|
feeder.content.substring( 0, f )
|
||||||
@ -140,7 +142,6 @@
|
|||||||
var f = ContentPosition( feeder );
|
var f = ContentPosition( feeder );
|
||||||
|
|
||||||
this.__contentUndo += feeder.content.substr( f, 1 );
|
this.__contentUndo += feeder.content.substr( f, 1 );
|
||||||
this.__insertLength ++;
|
|
||||||
|
|
||||||
feeder.content =
|
feeder.content =
|
||||||
feeder.content.substring( 0, f )
|
feeder.content.substring( 0, f )
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var kCode = e.keyCode
|
var kCode = e.keyCode
|
||||||
+ ( e.shiftKey ? SHIFT : 0 )
|
+ ( e.shiftKey || e.getModifierState( "CapsLock" ) ? SHIFT : 0 )
|
||||||
+ ( e.ctrlKey ? CTRL : 0 );
|
+ ( e.ctrlKey ? CTRL : 0 );
|
||||||
|
|
||||||
var cfeeder = sender.contentFeeder;
|
var cfeeder = sender.contentFeeder;
|
||||||
|
@ -13,19 +13,16 @@
|
|||||||
if( i == -1 || !this.__steps.length ) return null;
|
if( i == -1 || !this.__steps.length ) return null;
|
||||||
|
|
||||||
|
|
||||||
this.__i -= 2;
|
return this.__steps[ this.__i = i ];
|
||||||
return this.__steps[ i ];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Recorder.prototype.redo = function()
|
Recorder.prototype.redo = function()
|
||||||
{
|
{
|
||||||
var i = this.__i + 1;
|
var State = this.__steps[ this.__i ];
|
||||||
if( i == -1 || !this.__steps.length ) return null;
|
|
||||||
|
|
||||||
var State = this.__steps[ i ];
|
|
||||||
if( State )
|
if( State )
|
||||||
{
|
{
|
||||||
this.__i += 2;
|
this.__i ++;
|
||||||
return State;
|
return State;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,9 +32,7 @@
|
|||||||
Recorder.prototype.record = function( StateObj )
|
Recorder.prototype.record = function( StateObj )
|
||||||
{
|
{
|
||||||
this.__steps[ this.__i ] = StateObj;
|
this.__steps[ this.__i ] = StateObj;
|
||||||
StateObj.id = this.__i;
|
StateObj.id = this.__i ++;
|
||||||
|
|
||||||
delete this.__steps[ ++ this.__i ];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ns[ NS_EXPORT ]( EX_CLASS, "Recorder", Recorder );
|
ns[ NS_EXPORT ]( EX_CLASS, "Recorder", Recorder );
|
||||||
|
Loading…
Reference in New Issue
Block a user