botanjs/src/Components/Vim/LineBuffer.js
raw ยท 2069 bytes
(function(){
var ns = __namespace( "Components.Vim" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
/** @type {Dandelion.IDOMElement} */
var IDOMElement = __import( "Dandelion.IDOMElement" );
/** @type {Dandelion.IDOMObject} */
var IDOMObject = __import( "Dandelion.IDOMObject" );
/** @type {System.Cycle} */
var Cycle = __import( "System.Cycle" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var LineBuffer = function( cols, nextLineBuffer )
{
this.prev = null;
this.cols = cols;
this.next = nextLineBuffer;
this.br = false;
this.placeholder = true;
if( nextLineBuffer )
{
nextLineBuffer.prev = this;
}
};
LineBuffer.prototype.Push = function( content, wrap )
{
if( content == undefined || content === "" )
{
this.content = "~";
this.placeholder = true;
if( this.next ) this.next.Push( content, wrap );
return;
}
this.placeholder = false;
var line = "";
var br = false;
if( wrap )
{
for( var i = 0; i < this.cols; i ++ )
{
var c = content[i];
if( c === undefined ) break;
if( c == "\n" )
{
br = true;
i ++;
break;
}
line += c;
}
}
else
{
br = true;
for( var i = 0; true; i ++ )
{
var c = content[i];
if( c === undefined ) break;
if( c == "\n" )
{
i ++;
break;
}
if( i < this.cols )
{
line += c;
}
}
}
if( this.next )
{
this.next.br = br;
this.next.Push( content.substr( i ), wrap );
}
this.content = line;
};
LineBuffer.prototype.toString = function()
{
return this.content || " ";
};
__readOnly( LineBuffer.prototype, "visualLines", function()
{
var lines = [ this ];
var line = this;
while( ( line = line.next ) && !line.br )
{
lines.push( line );
}
return lines;
} );
ns[ NS_EXPORT ]( EX_CLASS, "LineBuffer", LineBuffer );
})();