From cbec2c747589527be78f9f509e6ad235f45cb4ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= Date: Mon, 14 Mar 2016 23:57:17 +0800 Subject: [PATCH] wordwrap panning for k --- botanjs/src/Components/Vim/Cursor.js | 14 ++++++++++---- botanjs/src/Components/Vim/LineFeeder.js | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js index b9caecf..eba3821 100644 --- a/botanjs/src/Components/Vim/Cursor.js +++ b/botanjs/src/Components/Vim/Cursor.js @@ -135,13 +135,19 @@ Cursor.prototype.moveY = function( d ) { - var Y = this.Y; + var Y = this.Y + d; var line; - Y += d; if( Y < 0 ) { - Y = 0; + this.feeder.pan( undefined, d ); + + this.Y = 0; + this.moveX(); + this.updatePosition(); + + this.feeder.softReset(); + return; } else if( this.feeder.moreAt < Y ) { @@ -186,7 +192,7 @@ return; } - else if ( this.Y < Y ) + else if ( 0 < d ) { // If panning is forward // and next line does not exists diff --git a/botanjs/src/Components/Vim/LineFeeder.js b/botanjs/src/Components/Vim/LineFeeder.js index b86f17f..61807a2 100644 --- a/botanjs/src/Components/Vim/LineFeeder.js +++ b/botanjs/src/Components/Vim/LineFeeder.js @@ -130,6 +130,7 @@ return this.__render( buffs[ start ], this.__rLength ); }; + // Performs a line panning Feeder.prototype.pan = function( dX, dY ) { if( dX == undefined ) dX = 0; @@ -140,13 +141,19 @@ var X = this.panX + dX; var Y = this.panY + dY; - var f = this.content.indexOf( "\n" ); - var i = 1; + var f = -1; + var i = 0; - while( f != - 1 && i < Y ) + // Y cannot be negative + if( Y < 0 ) Y = 0; + + if( 0 < Y ) { - i ++; - f = this.content.indexOf( "\n", f + 1 ); + f = this.content.indexOf( "\n" ); + for( i = 1; f != - 1 && i < Y; i ++ ) + { + f = this.content.indexOf( "\n", f + 1 ); + } } this.firstBuffer.Push(