Delete (Tested): dd diw d{bracket} dG dgg

This commit is contained in:
斟酌 鵬兄 2016-03-31 18:52:20 +08:00
parent 8c5f50ec2c
commit c24f74f70c
2 changed files with 98 additions and 10 deletions

View File

@ -20,6 +20,7 @@
this.__cursor = Cursor; this.__cursor = Cursor;
this.__nline = 0; this.__nline = 0;
this.__startX = Cursor.aPos; this.__startX = Cursor.aPos;
this.__panY = this.__cursor.feeder.panY;
}; };
DELETE.prototype.allowMovement = true; DELETE.prototype.allowMovement = true;
@ -33,6 +34,7 @@
{ {
e.preventDefault(); e.preventDefault();
if( e.ModKeys ) return;
/** @type {Components.Vim.State.Registers} */ /** @type {Components.Vim.State.Registers} */
var reg = e.target.registers; var reg = e.target.registers;
@ -44,18 +46,90 @@
if( sp == undefined ) if( sp == undefined )
{ {
if( this.__startX != cur.aPos ) Triggered = true;
{
Triggered = true;
if( e.kMap( "l" ) ) sp = this.__startX;
cur.suppressEvent();
var currAp = cur.aPos;
if( this.__startX != currAp )
{
// Remove to start
if( e.kMap( "^" ) )
{
sp --;
}
// Remove char in cursor
else if( e.kMap( "l" ) )
{ {
cur.moveX( -1 ); cur.moveX( -1 );
} }
// Remove char before cursor
sp = this.__startX; else if( e.kMap( "h" ) )
{
sp = currAp;
}
// Remove the current and the following line
else if( e.kMap( "j" ) )
{
cur.lineEnd( true );
sp = cur.aPos;
cur.moveY( -1 );
cur.lineStart();
this.__startX = cur.aPos;
}
// Remove the current and the preceding line
else if( e.kMap( "k" ) )
{
cur.moveY( 1 );
cur.lineEnd( true );
sp = cur.aPos;
cur.moveY( -1 );
cur.lineStart();
}
else if( this.__startX < currAp )
{
// Swap the movement
// This is to move the REDO / UNDO Cursor
// position to the earlier position
sp = currAp;
cur.moveTo( this.__startX );
}
} }
else return; // Remove the current line
else
{
if( e.kMap( "d" ) )
{
cur.lineEnd( true );
sp = cur.aPos;
cur.lineStart();
}
else if( e.range )
{
sp = e.range.close;
cur.moveTo( e.range.open, true );
}
else if( e.kMap( "^" ) )
{
// Do nothing as nothing can be removed
// since there is no successful movement
return true;
}
// this is the same as kMap( "h" ) above
else if( e.kMap( "$" ) )
{
sp = cur.aPos;
}
else
{
cur.unsuppressEvent();
return false;
}
}
cur.unsuppressEvent();
} }
var c = feeder.content; var c = feeder.content;
@ -76,6 +150,15 @@
feeder.content = c.substring( 0, s ) + c.substring( e + 1 ); 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
: undefined
);
cur.moveTo( s );
var stator = new Stator( cur, s ); var stator = new Stator( cur, s );
var stack = new Stack(); var stack = new Stack();
@ -96,8 +179,6 @@
cur.rec.record( stack ); cur.rec.record( stack );
feeder.pan();
return Triggered; return Triggered;
}; };

View File

@ -92,7 +92,14 @@
Cursor.prototype.moveTo = function( aPos, phantomSpace ) Cursor.prototype.moveTo = function( aPos, phantomSpace )
{ {
var content = this.feeder.content; var content = this.feeder.content;
var lastLineNum = this.getLine().lineNum; var pline = this.getLine();
var lastLineNum = pline.lineNum;
if( pline.placeholder )
{
lastLineNum = 0;
this.Y = 0;
}
var expLineNum = 0; var expLineNum = 0;
var lineStart = 0; var lineStart = 0;