b should not goes to the end of WORD

This commit is contained in:
斟酌 鵬兄 2017-01-30 13:41:05 +08:00
parent 7000a67b4b
commit b0f72f1281
1 changed files with 25 additions and 8 deletions

View File

@ -3,6 +3,7 @@
/** @type {System.Debug} */ /** @type {System.Debug} */
var debug = __import( "System.Debug" ); var debug = __import( "System.Debug" );
var beep = __import( "Components.Vim.Beep" );
/** @type {Components.Vim.IAction} */ /** @type {Components.Vim.IAction} */
var WORD = function( Cursor ) var WORD = function( Cursor )
@ -47,19 +48,35 @@
// Backward // Backward
if( e.kMap( "b" ) || e.kMap( "B" ) ) if( e.kMap( "b" ) || e.kMap( "B" ) )
{ {
if( p == 0 ) return; if( p == 0 )
{
beep();
return;
}
d = -1; d = -1;
var wordRange = analyzer.wordAt( p - 1 ); while( " \t".indexOf( feeder.content[ p + d ] ) != -1 )
{
d --;
}
// No more results
if( ( p + d ) == -1 )
{
p = 0;
}
else
{
var wordRange = analyzer.wordAt( p + d );
if( wordRange.open != -1 ) if( wordRange.open != -1 )
{ {
p = wordRange.open; p = wordRange.open;
} }
}
while( " \t".indexOf( feeder.content[ p ] ) != -1 ) // If the very first char is " " or "\t"
{ if( " \t".indexOf( feeder.content[ p ] ) != -1 ) p ++;
p += d; }
} }
cur.moveTo( p ); cur.moveTo( p );