commit 08865e062ee121b7199f8bd9590a79b92d7679ad
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2017-03-07T07:01:40Z |
| subject | Fixed reverse FIND does not work properly |
commit 08865e062ee121b7199f8bd9590a79b92d7679ad
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2017-03-07T07:01:40Z
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();