partial insert support

This commit is contained in:
斟酌 鵬兄 2016-03-16 00:11:39 +08:00
parent b7c693be07
commit 8bc4db7283
6 changed files with 83 additions and 14 deletions

View File

@ -5,6 +5,17 @@
var debug = __import( "System.Debug" ); var debug = __import( "System.Debug" );
var Mesg = __import( "Components.Vim.Message" ); var Mesg = __import( "Components.Vim.Message" );
var Translate = function( c )
{
switch( c )
{
case "Tab":
return "\t";
default:
return c;
}
};
/** @type {Components.Vim.Cursor.IAction} */ /** @type {Components.Vim.Cursor.IAction} */
var INSERT = function( Cursor ) var INSERT = function( Cursor )
{ {
@ -19,7 +30,41 @@
INSERT.prototype.handler = function( e ) INSERT.prototype.handler = function( e )
{ {
e.preventDefault(); e.preventDefault();
var inputChar = e.key; var inputChar = Translate( e.key );
if( inputChar.length != 1 ) return;
var cur = this.cursor;
var feeder = cur.feeder;
var line = cur.getLine();
var n = line.lineNum;
var cont = feeder.content;
var f = 0;
if( 0 < n )
{
f = cont.indexOf( "\n" );
for( i = 1; f != -1 && i < n; i ++ )
{
f = cont.indexOf( "\n", f + 1 );
}
if( this.cursor.feeder.wrap )
{
// wordwrap offset
f ++;
}
}
f += cur.aX;
feeder.content = cont.substring( 0, f ) + inputChar + cont.substring( f );
feeder.pan();
feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) );
cur.moveX( 1 );
}; };
INSERT.prototype.getMessage = function() INSERT.prototype.getMessage = function()

View File

@ -238,12 +238,32 @@
return line; return line;
}; };
// The absX for current Line
__readOnly( Cursor.prototype, "aX", function()
{
var X = this.X;
var f = this.feeder;
// Calculate wordwrap offset
if( f.wrap )
{
var cols = f.firstBuffer.cols + 1;
var w = X < cols ? 0 : Math.floor( X / cols );
if( 0 < w )
{
X -= w;
}
}
return X;
} );
__readOnly( Cursor.prototype, "message", function() __readOnly( Cursor.prototype, "message", function()
{ {
return this.action && this.action.getMessage(); return this.action && this.action.getMessage();
} ); } );
__readOnly( Cursor.prototype, "position", function() __readOnly( Cursor.prototype, "position", function()
{ {
return { return {

View File

@ -39,9 +39,10 @@
var i = 0; var i = 0;
var numTabs = 0; var numTabs = 0;
var tabw = this.tabWidth - 1;
if( wrap ) if( wrap )
{ {
for( ; i < this.cols - numTabs * this.tabWidth; i ++ ) for( ; i < this.cols - numTabs * tabw; i ++ )
{ {
var c = content[i]; var c = content[i];
if( c === undefined ) break; if( c === undefined ) break;
@ -78,7 +79,7 @@
numTabs ++; numTabs ++;
} }
if( i < this.cols - numTabs * this.tabWidth ) if( i < this.cols - numTabs * tabw )
{ {
line += c; line += c;
} }

View File

@ -26,6 +26,8 @@
this.panX = 0; this.panX = 0;
this.panY = 0; this.panY = 0;
this.wrap = true;
this.setRender(); this.setRender();
this.cursor = new Cursor( this ); this.cursor = new Cursor( this );
@ -34,8 +36,6 @@
this.__clseLine = null; this.__clseLine = null;
this.__moreAt = -1; this.__moreAt = -1;
this.__rows = rows; this.__rows = rows;
this.__wrap = true;
}; };
Feeder.prototype.init = function( content, wrap ) Feeder.prototype.init = function( content, wrap )
@ -43,13 +43,15 @@
this.content = content; this.content = content;
this.setWrap( wrap ); this.setWrap( wrap );
this.firstBuffer.Push( content, this.__wrap, 0 ); this.firstBuffer.Push( content, this.wrap, 0 );
}; };
Feeder.prototype.setWrap = function( wrap ) Feeder.prototype.setWrap = function( wrap )
{ {
if( wrap == undefined ) return; if( wrap == undefined ) return;
this.__wrap = wrap; this.wrap = wrap;
// TODO: Update
}; };
Feeder.prototype.setRender = function( placeholder ) Feeder.prototype.setRender = function( placeholder )
@ -128,8 +130,6 @@
if( dX == undefined ) dX = 0; if( dX == undefined ) dX = 0;
if( dY == undefined ) dY = 0; if( dY == undefined ) dY = 0;
if( dX == 0 && dY == 0 ) return;
var X = this.panX + dX; var X = this.panX + dX;
var Y = this.panY + dY; var Y = this.panY + dY;
@ -150,7 +150,7 @@
this.firstBuffer.Push( this.firstBuffer.Push(
this.content.substr( f + 1 ) this.content.substr( f + 1 )
, this.__wrap, i ); , this.wrap, i );
this.panX = X; this.panX = X;
this.panY = Y; this.panY = Y;
@ -195,8 +195,7 @@
} ); } );
__readOnly( Feeder.prototype, "lineStat", function() { __readOnly( Feeder.prototype, "lineStat", function() {
var X = this.cursor.X; var X = this.cursor.aX;
var line = this.cursor.getLine(); var line = this.cursor.getLine();
var tabStat = ""; var tabStat = "";

View File

@ -28,6 +28,8 @@ Components.Vim.Cursor.pX;
/** @type Number */ /** @type Number */
Components.Vim.Cursor.P; Components.Vim.Cursor.P;
/** @type Number */ /** @type Number */
Components.Vim.Cursor.aX;
/** @type Number */
Components.Vim.Cursor.X; Components.Vim.Cursor.X;
/** @type Number */ /** @type Number */
Components.Vim.Cursor.Y; Components.Vim.Cursor.Y;

View File

@ -28,6 +28,8 @@ Components.Vim.LineFeeder.setWrap;
Components.Vim.LineFeeder.lineBuffers; Components.Vim.LineFeeder.lineBuffers;
/** @type Boolean */ /** @type Boolean */
Components.Vim.LineFeeder.EOF; Components.Vim.LineFeeder.EOF;
/** @type Boolean */
Components.Vim.LineFeeder.wrap;
/** @type Number */ /** @type Number */
Components.Vim.LineFeeder.panX; Components.Vim.LineFeeder.panX;
/** @type Number */ /** @type Number */