Added c command

This commit is contained in:
斟酌 鵬兄 2017-01-30 20:51:12 +08:00
parent 2fda27b7be
commit 0e84b4c260
3 changed files with 34 additions and 3 deletions

View File

@ -15,7 +15,7 @@
var occurence = __import( "System.utils.Perf.CountSubstr" ); var occurence = __import( "System.utils.Perf.CountSubstr" );
/** @type {Components.Vim.IAction} */ /** @type {Components.Vim.IAction} */
var DELETE = function( Cursor ) var DELETE = function( Cursor, e )
{ {
/** @type {Components.Vim.Cursor} */ /** @type {Components.Vim.Cursor} */
this.__cursor = Cursor; this.__cursor = Cursor;
@ -23,6 +23,10 @@
this.__startX = Cursor.aPos; this.__startX = Cursor.aPos;
this.__panY = this.__cursor.feeder.panY; this.__panY = this.__cursor.feeder.panY;
this.__cMode = e.kMap( "c" );
this.__cMode_c = false;
this.__enterEvent = e;
Cursor.suppressEvent(); Cursor.suppressEvent();
}; };
@ -30,7 +34,26 @@
DELETE.prototype.dispose = function() DELETE.prototype.dispose = function()
{ {
this.__cursor.unsuppressEvent(); var cur = this.__cursor;
cur.unsuppressEvent();
if( this.__cMode )
{
if( this.__cMode_c ) // Append, a
{
cur.fixTab();
cur.moveX( 1, false, true, true );
}
else // Insert, i
{
cur.moveX( -1, true );
cur.moveX( 1, true, true, true );
}
setTimeout( function() {
cur.openAction( "INSERT", this.__enterEvent );
}, 20 );
}
}; };
DELETE.prototype.handler = function( e, sp, newLine ) DELETE.prototype.handler = function( e, sp, newLine )
@ -117,6 +140,13 @@
sp = cur.aPos; sp = cur.aPos;
cur.lineStart(); cur.lineStart();
} }
else if( this.__cMode && e.kMap( "c" ) )
{
cur.lineEnd();
sp = cur.aPos;
cur.lineStart( true );
this.__cMode_c = true;
}
else if( e.range ) else if( e.range )
{ {
sp = e.range.close; sp = e.range.close;

View File

@ -311,6 +311,7 @@
break; break;
case D: // Del with motion case D: // Del with motion
case C: // Then insert
ccur.openAction( "DELETE", e ); ccur.openAction( "DELETE", e );
break; break;
case Y: // Yank with motion case Y: // Yank with motion
@ -743,6 +744,7 @@
{ {
j += lines[i].content.length; j += lines[i].content.length;
} }
j += Math.max( 0, Math.floor( j / dispLine.cols ) - 1 );
ccur.moveX( j ); ccur.moveX( j );
} }
} }

View File

@ -275,7 +275,6 @@
var ntabs = occurence( rline.substring( s + 1, e + 1 ), "\t" ); var ntabs = occurence( rline.substring( s + 1, e + 1 ), "\t" );
if( 1 < ntabs && rline[ e ] == "\t" ) ntabs --; if( 1 < ntabs && rline[ e ] == "\t" ) ntabs --;
x += ntabs * tabStep + isLF; x += ntabs * tabStep + isLF;
x += Math.max( 0, Math.floor( d / line.cols ) - 1 );
// Reset the distance to 1 as x is now calculated // Reset the distance to 1 as x is now calculated
d = 1; d = 1;