commit b17ca21420261025607816441764f165c6380005
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2016-03-18T00:34:36Z |
| subject | fixed G / gg issue on some cases |
commit b17ca21420261025607816441764f165c6380005
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2016-03-18T00:34:36Z
fixed G / gg issue on some cases
---
botanjs/src/Components/Vim/Cursor.js | 62 ++++++++++++++++++++++++------------
1 file changed, 42 insertions(+), 20 deletions(-)
diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js
index 09765b1..682232a 100644
--- a/botanjs/src/Components/Vim/Cursor.js
+++ b/botanjs/src/Components/Vim/Cursor.js
@@ -55,6 +55,25 @@
return offset;
};
+ // Rush cursor to wanted position "d" then get the actual position
+ var GetRushPos = function( c, d )
+ {
+ var line = c.getLine();
+ var l = c.Y + d;
+ var i = c.Y;
+
+ // First line ( visual ) does not count
+ if( line != c.feeder.firstBuffer ) i --;
+
+ for( ; i < l; line = line.nextLine )
+ {
+ if( line.placeholder ) break;
+ if( line.br ) i ++;
+ }
+
+ return i;
+ };
+
var Cursor = function( feeder )
{
/** @type {Components.Vim.LineFeeder} */
@@ -151,24 +170,26 @@
Cursor.prototype.moveY = function( d, penentrate )
{
+ var i;
var Y = this.Y + d;
+ var feeder = this.feeder;
var line;
if( Y < 0 )
{
- this.feeder.pan( undefined, d );
+ feeder.pan( undefined, d );
this.Y = 0;
this.moveX();
this.updatePosition();
- this.feeder.softReset();
+ feeder.softReset();
return;
}
- else if( this.feeder.moreAt < Y )
+ // More at bottom, start panning
+ else if( !feeder.EOF && feeder.moreAt < Y )
{
var feeder = this.feeder;
- var i = 0;
if( penentrate )
{
@@ -180,6 +201,8 @@
{
feeder.pan( undefined, 1 );
}
+
+ i = GetRushPos( this, d );
}
else
{
@@ -204,15 +227,16 @@
// The line number cursor need to be in
Y = lastLine + lineShift;
- }
- // Calculate the visual line position "i"
- for( i = 0, line = feeder.firstBuffer;
- line != feeder.lastBuffer;
- line = line.next )
- {
- if( line.br ) i ++;
- if( line.lineNum == Y || line.next.placeholder ) break;
+ // Calculate the visual line position "i"
+ for( i = 0, line = feeder.firstBuffer;
+ line != feeder.lastBuffer;
+ line = line.next )
+ {
+ if( line.br ) i ++;
+ if( line.lineNum == Y || line.next.placeholder ) break;
+ }
+
}
this.Y = i;
@@ -220,20 +244,18 @@
this.moveX();
this.updatePosition();
+ // Because it is panned, soft reset is needed
feeder.softReset();
return;
}
else if ( 0 < d )
{
- // If panning is forward
- // and next line does not exists
- line = this.getLine().nextLine;
- if( !line || line.placeholder )
- {
- // do nothing
- return;
- }
+ var line = this.getLine();
+ // If already at bottom
+ if( line.nextLine.placeholder ) return;
+
+ Y = GetRushPos( this, d );
}
this.Y = Y;