From b0f72f1281b2f557bf9b3da185689a17aeedcd2b 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, 30 Jan 2017 13:41:05 +0800 Subject: [PATCH] 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 );