Handle the tabwidth

This commit is contained in:
斟酌 鵬兄 2016-03-14 03:33:36 +08:00
parent bd35ed56b1
commit 9757dec7a0
3 changed files with 68 additions and 7 deletions

View File

@ -54,7 +54,7 @@
}
else
{
offset += line.cols + 1;
offset += line.toString().length + 1;
}
line = line.next;
@ -180,6 +180,8 @@
this.moveX();
this.updatePosition();
feeder.softReset();
return;
}

View File

@ -20,6 +20,7 @@
this.br = false;
this.placeholder = true;
this.lineNum = 0;
this.tabWidth = 8;
if( nextLineBuffer )
{
@ -45,9 +46,10 @@
var br = false;
var i = 0;
var numTabs = 0;
if( wrap )
{
for( ; i < this.cols; i ++ )
for( ; i < this.cols - numTabs * this.tabWidth; i ++ )
{
var c = content[i];
if( c === undefined ) break;
@ -58,6 +60,10 @@
i ++;
break;
}
else if( c == "\t" )
{
numTabs ++;
}
line += c;
}
@ -75,8 +81,12 @@
i ++;
break;
}
else if( c == "\t" )
{
numTabs ++;
}
if( i < this.cols )
if( i < this.cols - numTabs * this.tabWidth )
{
line += c;
}

View File

@ -75,7 +75,8 @@
{
var display = ( line == undefined ? "" : line ) + "";
var atSpace = false
var atSpace = false;
for( var i = 0;
line && i < steps && ( line = line.next ) && placeholdCond( line );
i ++ )
@ -93,6 +94,23 @@
return display;
};
this.__softRender = function()
{
var line = _self.lineBuffers[ _self.__rStart ];
var steps = _self.__rLength;
for( var i = 0;
line && i < steps && ( line = line.next ) && placeholdCond( line );
i ++ )
{
if( line.br && steps < ( i + line.visualLines.length ) )
{
_self.__clseLine = line;
break;
}
}
};
}
Feeder.prototype.render = function( start, length )
@ -107,7 +125,9 @@
if( length == 0 ) return "";
return this.__render( buffs[ start ], length - 1 );
this.__rStart = start;
this.__rLength = length - 1;
return this.__render( buffs[ start ], this.__rLength );
};
Feeder.prototype.pan = function( dX, dY )
@ -137,6 +157,13 @@
this.panY = Y;
};
Feeder.prototype.softReset = function()
{
this.__moreAt = -1;
this.__clseLine = null;
this.__softRender();
};
__readOnly( Feeder.prototype, "firstBuffer", function() {
return this.lineBuffers[ 0 ];
} );
@ -145,6 +172,10 @@
return this.lineBuffers[ this.__rows - 1 ];
} );
__readOnly( Feeder.prototype, "EOF", function() {
return this.lineBuffers[ this.__rows ].placeholder;
} );
__readOnly( Feeder.prototype, "moreAt", function() {
if( 0 < this.__moreAt ) return this.__moreAt;
@ -159,18 +190,35 @@
}
while( line = line.next );
if( line == undefined ) i --;
return ( this.__moreAt = i );
} );
__readOnly( Feeder.prototype, "lineStat", function() {
var X = this.cursor.X;
return ( this.cursor.getLine().lineNum + 1 ) + "," + X + "-" + ( X );
var line = this.cursor.getLine();
var tabStat = "";
var tabs = line.content.match( /\t/g );
if( tabs )
{
tabStat = "-" + ( X + tabs.length * line.tabWidth );
}
return ( line.lineNum + 1 ) + "," + X + tabStat;
} );
__readOnly( Feeder.prototype, "docPos", function() {
var pos = "ALL";
if( this.panY == 0 )
if( 0 < this.panY && this.EOF )
{
pos = "BOTTOM";
}
else
{
if( this.__clseLine || !this.EOF )
{
@ -178,6 +226,7 @@
}
}
return pos;
} );