Added ability to detect the screen size

This commit is contained in:
斟酌 鵬兄 2016-04-04 02:05:27 +08:00
parent cde4dd8c60
commit 21221a6e4e
1 changed files with 72 additions and 4 deletions

View File

@ -42,7 +42,7 @@
}; };
/* stage @param {Dandelion.IDOMElement} */ /* stage @param {Dandelion.IDOMElement} */
var VimArea = function( stage ) var VimArea = function( stage, detectScreenSize )
{ {
if( !stage ) throw new Error( "Invalid argument" ); if( !stage ) throw new Error( "Invalid argument" );
@ -80,10 +80,16 @@
, new EventKey( "Blur", function() { _self.__active = false; } ) , new EventKey( "Blur", function() { _self.__active = false; } )
]; ];
this.__removeText
// Init if( detectScreenSize )
this.VisualizeVimFrame( element.value ); {
var val = element.value;
this.__testScreen(function() { _self.VisualizeVimFrame( val ); });
}
else
{
this.VisualizeVimFrame( element.value );
}
// Set buffer index // Set buffer index
this.__instIndex = InstIndex ++; this.__instIndex = InstIndex ++;
@ -92,6 +98,68 @@
Insts[ this.__instIndex ] = this; Insts[ this.__instIndex ] = this;
}; };
VimArea.prototype.__testScreen = function( handler )
{
var area = this.stage.element;
area.value = "";
var msg = "Please wait while Vim;Re is testing for screen dimensions";
var m = function() { return msg[ i ++ ] || "."; };
var i = 0;
var oX = area.style.overflowX;
var oY = area.style.overflowY;
area.style.whiteSpace = "nowrap";
var oWidth = area.scrollWidth;
var testWidth = function()
{
area.value += m();
if( oWidth == area.scrollWidth )
{
Cycle.next( testWidth );
}
else
{
var t = "";
i -= 3;
for( var k = 0; k < i; k ++ ) t += ".";
area.value = t;
area.style.whiteSpace = "";
m = function() { return "\n" + t; };
testHeight();
}
};
testWidth();
var oHeight = area.scrollHeight;
var l = 0;
var _self = this;
var testHeight = function() {
area.value += m();
l ++;
if( oHeight == area.scrollHeight )
{
Cycle.next( testHeight );
}
else
{
_self.rows = l;
_self.cols = i;
handler();
}
};
};
VimArea.prototype.select = function( sel ) VimArea.prototype.select = function( sel )
{ {
if( !this.__active ) return; if( !this.__active ) return;