Handle the DELETE / BACKSPACE on INSERT

This commit is contained in:
斟酌 鵬兄 2016-03-17 19:59:07 +08:00
parent 44fec5abfd
commit db922421be
4 changed files with 36 additions and 8 deletions

View File

@ -14,6 +14,8 @@
{
case "Tab":
return "\t";
case "Enter":
return "\n";
default:
return c;
}
@ -106,6 +108,11 @@
this.__startPosition = ContentPosition( this.__cursor.feeder );
}
if( c == "\n" )
{
// todo
}
this.__insertLength += c.length;
};
@ -117,9 +124,10 @@
switch( e.keyCode )
{
case 8: // Backspace
if( cur.X == 0 ) return;
var oY = feeder.panY + cur.Y;
if( cur.X == 0 && feeder.panY == 0 && cur.Y == 0 ) return;
cur.moveX( -1 );
cur.moveX( -1, true, true );
var f = ContentPosition( feeder );

View File

@ -54,6 +54,7 @@
{
// Cursor movements
case BACKSPACE: // Backspace, go back 1 char, regardless of line
cfeeder.cursor.moveX( -1, true );
break;
case H: // Left
cfeeder.cursor.moveX( -1 );
@ -70,7 +71,7 @@
// Insert
case A: // Append
cfeeder.cursor.moveX( 1 );
cfeeder.cursor.moveX( 1, true, true );
cfeeder.cursor.openAction( "INSERT" );
break;
case I: // Insert

View File

@ -82,7 +82,7 @@
// Can only be 1, -1
// 0 will be treated as undefined
Cursor.prototype.moveX = function( d )
Cursor.prototype.moveX = function( d, penentrate, phantomSpace )
{
var x = this.pX;
@ -93,15 +93,29 @@
var buffs = this.feeder.lineBuffers;
if( penentrate && x < 0 && ( 0 < this.feeder.panY || 0 < this.Y ) )
{
this.moveY( -1 );
this.lineEnd( phantomSpace );
return;
}
/** @type {Components.Vim.LineBuffer} */
var line = GetLine( buffs, this.Y );
var content = line.visualLines.join( "\n" );
var cLen = content.length;
var c = content[ x ];
if( c == undefined )
// Include empty lines befor cursor end
if( ( phantomSpace && cLen - 1 <= x ) || ( cLen == 1 && c == undefined ) )
{
x = d > 0 ? content.length - 1 : 0;
x = d > 0 ? cLen - 1 : 0;
}
// ( 2 < cLen ) Exclude empty lines at cursor end
else if( ( 2 < cLen && x == cLen - 1 && c == " " ) || c == undefined )
{
x = d > 0 ? cLen - 2 : 0;
}
else if( c == "\n" )
{
@ -124,9 +138,9 @@
this.updatePosition();
};
Cursor.prototype.lineEnd = function()
Cursor.prototype.lineEnd = function( phantomSpace )
{
this.moveX( Number.MAX_VALUE );
this.moveX( Number.MAX_VALUE, false, phantomSpace );
};
Cursor.prototype.updatePosition = function()

View File

@ -97,6 +97,11 @@
LineBuffer.prototype.toString = function()
{
if( this.content.length < this.cols )
{
return this.content + " ";
}
return this.content || " ";
};