commit b0f72f1281b2f557bf9b3da185689a17aeedcd2b
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2017-01-30T05:41:05Z |
| subject | b should not goes to the end of WORD |
commit b0f72f1281b2f557bf9b3da185689a17aeedcd2b
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2017-01-30T05:41:05Z
b should not goes to the end of WORD
---
botanjs/src/Components/Vim/Actions/WORD.js | 33 ++++++++++++++++++++++--------
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/botanjs/src/Components/Vim/Actions/WORD.js b/botanjs/src/Components/Vim/Actions/WORD.js
index 7d69be4..df514f5 100644
--- a/botanjs/src/Components/Vim/Actions/WORD.js
+++ b/botanjs/src/Components/Vim/Actions/WORD.js
@@ -3,6 +3,7 @@
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
+ var beep = __import( "Components.Vim.Beep" );
/** @type {Components.Vim.IAction} */
var WORD = function( Cursor )
@@ -47,19 +48,35 @@
// Backward
if( e.kMap( "b" ) || e.kMap( "B" ) )
{
- if( p == 0 ) return;
+ if( p == 0 )
+ {
+ beep();
+ return;
+ }
+
d = -1;
- var wordRange = analyzer.wordAt( p - 1 );
- if( wordRange.open != -1 )
+ while( " \t".indexOf( feeder.content[ p + d ] ) != -1 )
{
- p = wordRange.open;
+ d --;
}
- }
- while( " \t".indexOf( feeder.content[ p ] ) != -1 )
- {
- p += d;
+ // No more results
+ if( ( p + d ) == -1 )
+ {
+ p = 0;
+ }
+ else
+ {
+ var wordRange = analyzer.wordAt( p + d );
+ if( wordRange.open != -1 )
+ {
+ p = wordRange.open;
+ }
+
+ // If the very first char is " " or "\t"
+ if( " \t".indexOf( feeder.content[ p ] ) != -1 ) p ++;
+ }
}
cur.moveTo( p );