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 ) if( line.next && line.next.placeholder )
break LineLoop; break LineLoop;
if( line.next && line.next.br ) // Using toString because tab is 1 byte
{ // but variable width
offset += line.toString().length + 1; offset += line.toString().length + 1;
line = line.next; line = line.next;
break;
}
else
{
offset += line.toString().length + 1;
}
line = line.next; if( line && line.br ) break;
} }
} }
@ -142,6 +136,7 @@
Cursor.prototype.moveY = function( d ) Cursor.prototype.moveY = function( d )
{ {
var Y = this.Y; var Y = this.Y;
var line;
Y += d; Y += d;
if( Y < 0 ) if( Y < 0 )
@ -152,13 +147,16 @@
{ {
var feeder = this.feeder; var feeder = this.feeder;
var lastLine = feeder.lastBuffer.lineNum; var lastLine = feeder.lastBuffer.lineNum;
var lineShift = Y - feeder.moreAt;
var i = 0; var i = 0;
while( true ) 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 // until the entire line cosumes the screen
if( feeder.lastBuffer.lineNum == lastLine ) if( feeder.lastBuffer.lineNum == lastLine )
{ {
@ -167,6 +165,10 @@
else break; else break;
} }
// The line number cursor need to be in
Y = lastLine + lineShift;
// Calculate the visual line position
for( i = 0, line = feeder.firstBuffer; for( i = 0, line = feeder.firstBuffer;
line != feeder.lastBuffer; line != feeder.lastBuffer;
line = line.next ) line = line.next )
@ -184,6 +186,17 @@
return; 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; this.Y = Y;

View File

@ -33,6 +33,7 @@
this.lineNum = n; this.lineNum = n;
if( content == undefined || content === "" ) if( content == undefined || content === "" )
{ {
this.lineNum = ++n;
this.content = "~"; this.content = "~";
this.br = true; this.br = true;
this.placeholder = true; this.placeholder = true;
@ -107,6 +108,16 @@
return this.content || " "; 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() __readOnly( LineBuffer.prototype, "visualLines", function()
{ {
var lines = [ this ]; var lines = [ this ];

View File

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