wordwrap panning for j

This commit is contained in:
斟酌 鵬兄 2016-03-14 23:28:30 +08:00
parent 9757dec7a0
commit 97480cd0c6
3 changed files with 42 additions and 15 deletions

View File

@ -46,18 +46,12 @@
if( line.next && line.next.placeholder )
break LineLoop;
if( line.next && line.next.br )
{
offset += line.toString().length + 1;
line = line.next;
break;
}
else
{
offset += line.toString().length + 1;
}
// Using toString because tab is 1 byte
// but variable width
offset += line.toString().length + 1;
line = line.next;
if( line && line.br ) break;
}
}
@ -142,6 +136,7 @@
Cursor.prototype.moveY = function( d )
{
var Y = this.Y;
var line;
Y += d;
if( Y < 0 )
@ -152,13 +147,16 @@
{
var feeder = this.feeder;
var lastLine = feeder.lastBuffer.lineNum;
var lineShift = Y - feeder.moreAt;
var i = 0;
while( true )
{
feeder.pan( undefined, Y - feeder.moreAt + i );
feeder.pan( undefined, lineShift + i );
// If it is the same line we keep scrolling it
// if it turns out to be the same line
// before after panning
// we keep scrolling it ( panning )
// until the entire line cosumes the screen
if( feeder.lastBuffer.lineNum == lastLine )
{
@ -167,6 +165,10 @@
else break;
}
// The line number cursor need to be in
Y = lastLine + lineShift;
// Calculate the visual line position
for( i = 0, line = feeder.firstBuffer;
line != feeder.lastBuffer;
line = line.next )
@ -184,6 +186,17 @@
return;
}
else if ( this.Y < Y )
{
// If panning is forward
// and next line does not exists
line = this.getLine().nextLine;
if( !line || line.placeholder )
{
// do nothing
return;
}
}
this.Y = Y;

View File

@ -33,6 +33,7 @@
this.lineNum = n;
if( content == undefined || content === "" )
{
this.lineNum = ++n;
this.content = "~";
this.br = true;
this.placeholder = true;
@ -107,6 +108,16 @@
return this.content || " ";
};
__readOnly( LineBuffer.prototype, "nextLine", function()
{
var line = this;
var thisLine = this.lineNum;
while( ( line = line.next ) && line.lineNum == thisLine );
return line;
} );
__readOnly( LineBuffer.prototype, "visualLines", function()
{
var lines = [ this ];

View File

@ -149,12 +149,15 @@
var r = this.rows;
var c = this.cols;
// StatusFeeder always consumes at least 1 line
var cRange = r - 1;
// Content feeder
var cfeeder = new LineFeeder( r, c );
var cfeeder = new LineFeeder( cRange, c );
cfeeder.init( content );
// Status feeder
// Status can consumes up to full screen, I think
sfeeder = new LineFeeder( r, c );
sfeeder.setRender( false );