Put command

This commit is contained in:
2016-03-31 20:25:43 +08:00
parent c24f74f70c
commit cfa2e45e3d
7 changed files with 135 additions and 26 deletions

View File

@@ -151,9 +151,9 @@
feeder.content = c.substring( 0, s ) + c.substring( e + 1 );
// Try to keep the original panning if possible
cur.feeder.pan( undefined
, this.__panY < cur.feeder.panY
? this.__panY - cur.feeder.panY
feeder.pan( undefined
, this.__panY < feeder.panY
? this.__panY - feeder.panY
: undefined
);

View File

@@ -29,7 +29,7 @@
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
this.__Stator = new Stator( Cursor );
this.__stator = new Stator( Cursor );
// Initialize this stack
this.__rec( "", true );
@@ -55,7 +55,7 @@
) return;
this.__stack.store(
this.__Stator.save( this.__insertLength, this.__contentUndo )
this.__stator.save( this.__insertLength, this.__contentUndo )
);
this.__cursor.rec.record( this.__stack );

View File

@@ -0,0 +1,81 @@
(function(){
var ns = __namespace( "Components.Vim.Actions" );
var Mesg = __import( "Components.Vim.Message" );
/** @type {Components.Vim.State.Stator} */
var Stator = __import( "Components.Vim.State.Stator" );
/** @type {Components.Vim.State.Stack} */
var Stack = __import( "Components.Vim.State.Stack" );
var Mesg = __import( "Components.Vim.Message" );
var occurence = __import( "System.utils.Perf.CountSubstr" );
/** @type {Components.Vim.Cursor.IAction} */
var PUT = function( Cursor )
{
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
this.__stator = new Stator( Cursor );
this.__msg = "";
};
PUT.prototype.allowMovement = false;
PUT.prototype.dispose = function()
{
};
PUT.prototype.handler = function( e )
{
e.preventDefault();
// TODO: Get the input for determinating registers
var inputStack = false;
var cput = this.__cursor.Vim.registers.get( inputStack );
if( !cput ) return true;
var clen = cput.length;
var nLines = occurence( cput, "\n" );
var cur = this.__cursor;
var feeder = cur.feeder;
var aP = cur.aPos;
feeder.content = feeder.content.substring( 0, aP )
+ cput
+ feeder.content.substring( aP );
cur.suppressEvent();
feeder.pan();
cur.moveTo( 0 < nLines ? aP : aP + clen, true );
var stack = new Stack();
stack.store( this.__stator.save( clen, "" ) );
cur.rec.record( stack );
this.__put = cput;
if( nLines )
{
this.__msg = Mesg( "LINE_MORE", nLines );
}
cur.moveX( -1 );
cur.unsuppressEvent();
return true;
};
PUT.prototype.getMessage = function()
{
console.log( this.__msg );
return this.__msg;
};
ns[ NS_EXPORT ]( EX_CLASS, "PUT", PUT );
})();

View File

@@ -76,6 +76,12 @@
}
Action.handler( e, this.__startaP );
if( Action.constructor != DELETE )
{
cur.moveTo( this.__startaP );
}
this.__leaveMesg = Action.getMessage();
Action.dispose();