Previous approach had performance issue, fixing it

This commit is contained in:
斟酌 鵬兄 2016-03-30 06:17:37 +08:00
parent 799a911e06
commit 564aef86aa
3 changed files with 51 additions and 51 deletions

View File

@ -292,18 +292,11 @@
break;
}
var d = 1;
var at = bracketMatch.close;
if( bracketMatch.selected == at )
{
d = -1;
at = bracketMatch.open;
}
while( ccur.aPos != at )
{
ccur.moveX( d, true );
}
ccur.moveTo(
bracketMatch.selected == bracketMatch.close
? bracketMatch.open
: bracketMatch.close
);
break;
case T: // To

View File

@ -88,6 +88,37 @@
// Set by VimArea
Cursor.prototype.Vim;
// Move to an absolute position
Cursor.prototype.moveTo = function( aPos )
{
var content = this.feeder.content;
var lastLineNum = this.getLine().lineNum;
var expLineNum = 0;
var lineStart = 0;
for( var i = content.indexOf( "\n" ); 0 <= i ; i = content.indexOf( "\n", i ) )
{
if( aPos <= i )
{
break;
}
lineStart = i;
i ++;
expLineNum ++;
}
var jumpY = expLineNum - lastLineNum;
var jumpX = aPos < lineStart ? lineStart - aPos : aPos - lineStart;
if( jumpY ) this.moveY( jumpY );
if( 0 < this.getLine().lineNum && lineStart <= aPos ) jumpX --;
this.moveX( - Number.MAX_VALUE );
this.moveX( jumpX );
};
// 0 will be treated as default ( 1 )
Cursor.prototype.moveX = function( d, penetrate, phantomSpace )
{
@ -120,38 +151,12 @@
// Motion includes empty lines before cursor end
if( ( phantomSpace && cLen - 1 <= x ) || ( cLen == 1 && c == undefined ) )
{
if( 0 < d )
{
x = cLen - 1;
if( penetrate )
{
this.X = 0;
this.moveY( 1 );
return;
}
}
else
{
x = 0;
}
x = 0 < d ? cLen - 1 : 0;
}
// ( 2 < cLen ) motion excludes empty lines at cursor end
else if( ( 2 <= cLen && x == cLen - 1 && c == " " ) || c == undefined )
{
if( 0 < d )
{
x = cLen - 2;
if( penetrate )
{
this.X = 0;
this.moveY( 1 );
return;
}
}
else
{
x = 0;
}
x = 0 < d ? cLen - 2 : 0;
}
else if( c == "\n" )
{
@ -199,7 +204,7 @@
this.feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) );
};
Cursor.prototype.moveY = function( d, penetrate )
Cursor.prototype.moveY = function( d )
{
var i;
var Y = this.Y + d;
@ -208,7 +213,7 @@
if( Y < 0 )
{
feeder.pan( undefined, d );
feeder.pan( undefined, Y );
this.Y = 0;
this.moveX();
@ -222,11 +227,7 @@
{
var feeder = this.feeder;
if( penetrate )
{
feeder.pan( undefined, Y - moreAt );
}
else if( feeder.linesTotal < Y )
if( feeder.linesTotal < Y )
{
while( !feeder.EOF )
{
@ -244,18 +245,22 @@
if( !feeder.EOF )
feeder.pan( undefined, lineShift );
// The line number cursor need to be in
Y = thisLine + d;
// if it turns out to be the same line
// OR the cursor can not reside on the needed line
// before after panning
// we keep scrolling it ( panning )
// until the entire line cosumes the screen
while( !feeder.EOF && feeder.lastBuffer.lineNum == lastLine )
while( !feeder.EOF && (
feeder.lastBuffer.lineNum == lastLine
|| feeder.lastBuffer.lineNum < Y
) )
{
feeder.pan( undefined, 1 );
}
// The line number cursor need to be in
Y = thisLine + d;
i = this.Y;
this.Y = 0;
// Calculate the visual line position "i"

View File

@ -10,6 +10,8 @@ Components.Vim.Cursor.action;
/** @type {Components.Vim.State.Recorder} */
Components.Vim.Cursor.rec;
/** @type Function */
Components.Vim.Cursor.moveTo;
/** @type Function */
Components.Vim.Cursor.moveX;
/** @type Function */