From 5311dc043df35bc528c533c33d3a3e1fe9b94598 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: Tue, 7 Mar 2017 12:07:58 +0800 Subject: [PATCH 1/3] Fixed a cursor jumping issue for word-wrapped lines --- botanjs/src/Components/Vim/Cursor.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js index f6cd72a..be9c9a0 100644 --- a/botanjs/src/Components/Vim/Cursor.js +++ b/botanjs/src/Components/Vim/Cursor.js @@ -131,9 +131,14 @@ } var jumpY = expLineNum - lastLineNum; - var jumpX = aPos < lineStart ? lineStart - aPos : aPos - lineStart; + if( jumpY ) this.moveY( jumpY ); + pline = this.getLine(); + + var jumpX = aPos < lineStart ? lineStart - aPos : aPos - lineStart; var kX = jumpX - pline.content.length; + + // This handles word-wrapped long line phantom "\n" while( 0 < kX ) { jumpX ++; @@ -142,8 +147,6 @@ kX -= pline.content.length; } - if( jumpY ) this.moveY( jumpY ); - // This is needed because first line does not contain the first "\n" character if( 0 < this.getLine().lineNum && lineStart <= aPos ) jumpX --; From 08865e062ee121b7199f8bd9590a79b92d7679ad 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: Tue, 7 Mar 2017 15:01:40 +0800 Subject: [PATCH 2/3] Fixed reverse FIND does not work properly --- botanjs/src/Components/Vim/Actions/DELETE.js | 5 +++++ botanjs/src/Components/Vim/Actions/FIND.js | 13 ++++++++++++- botanjs/src/Components/Vim/Cursor.js | 9 ++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/botanjs/src/Components/Vim/Actions/DELETE.js b/botanjs/src/Components/Vim/Actions/DELETE.js index bf675da..00693fb 100644 --- a/botanjs/src/Components/Vim/Actions/DELETE.js +++ b/botanjs/src/Components/Vim/Actions/DELETE.js @@ -121,6 +121,7 @@ cur.moveY( -1 ); cur.lineStart(); } + // Remove to Cursor jumps else if( this.__startX < currAp ) { // Swap the movement @@ -128,6 +129,10 @@ // position to the earlier position sp = currAp; cur.moveTo( this.__startX ); + + // Special case for cw dn cursor jumps that + // does not remove the start position + if( e.kMap( "w" ) || e.kMap( "n" ) ) sp --; } } // Remove the current line diff --git a/botanjs/src/Components/Vim/Actions/FIND.js b/botanjs/src/Components/Vim/Actions/FIND.js index f93aeaa..316f15c 100644 --- a/botanjs/src/Components/Vim/Actions/FIND.js +++ b/botanjs/src/Components/Vim/Actions/FIND.js @@ -102,6 +102,8 @@ var r; var Hit; var FirstHit; + + var l = 0; var PrevStack = []; var LoopGuard; @@ -125,6 +127,7 @@ } PrevStack.push( r.index ); + l ++; LoopGuard = r.index; } @@ -132,11 +135,19 @@ if( e.kMap( "N" ) ) { - Hit = PrevStack[ PrevStack.length - 2 ]; + // The search loop above always search for next match + // So use the previous match + Hit = PrevStack[ l - 1 ]; + + // Adjust if cursor is already in the previous match + if( Hit == p ) Hit = PrevStack[ l - 2 ]; + if( Hit == undefined ) { this.__msg = Mesg( "SEARCH_HIT_TOP" ); + // This resets the exec state in previous loop + search = new RegExp( search ); while( ( r = search.exec( content ) ) !== null ) Hit = r.index; } } diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js index be9c9a0..25e858c 100644 --- a/botanjs/src/Components/Vim/Cursor.js +++ b/botanjs/src/Components/Vim/Cursor.js @@ -131,7 +131,14 @@ } var jumpY = expLineNum - lastLineNum; - if( jumpY ) this.moveY( jumpY ); + if( jumpY ) + { + this.moveY( jumpY ); + + // Because moveTo is a direct jump function + // We'll auto reveal the target line here + if( this.feeder.moreAt == this.Y ) this.moveY( 1 ); + } pline = this.getLine(); From 96b0a691c510d8e269b69e6989e6dd5d66b7fa60 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: Tue, 7 Mar 2017 15:54:25 +0800 Subject: [PATCH 3/3] Advanced version number --- botanjs/src/Components/Vim/_this.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/botanjs/src/Components/Vim/_this.js b/botanjs/src/Components/Vim/_this.js index bd9c236..afe9494 100644 --- a/botanjs/src/Components/Vim/_this.js +++ b/botanjs/src/Components/Vim/_this.js @@ -1,4 +1,4 @@ -var VIMRE_VERSION = "1.0.1"; +var VIMRE_VERSION = "1.0.2"; (function(){ var ns = __namespace( "Components.Vim" );