From 36a2dfac797c11fa5b663944ff50b135f0554604 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 14:33:00 +0800 Subject: [PATCH] Fixed w motion, added e motion --- botanjs/src/Components/Vim/Actions/WORD.js | 60 +++++++++++++++++----- botanjs/src/Components/Vim/Controls.js | 6 ++- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/botanjs/src/Components/Vim/Actions/WORD.js b/botanjs/src/Components/Vim/Actions/WORD.js index df514f5..7bd3b03 100644 --- a/botanjs/src/Components/Vim/Actions/WORD.js +++ b/botanjs/src/Components/Vim/Actions/WORD.js @@ -30,22 +30,60 @@ var p = cur.aPos; - var d = 1; - // forward + // Forword WORD start if( e.kMap( "w" ) || e.kMap( "W" ) ) { - if( feeder.content[ p + 1 ] == "\n" ) + // +2 because there is a closing "\n" + if( feeder.content[ p + 2 ] == undefined ) { - p ++; + beep(); + return; } var wordRange = analyzer.wordAt( p ); if( wordRange.open != -1 ) { p = wordRange.close + 1; + + while( " \t\n".indexOf( feeder.content[ p ] ) != -1 ) p ++; + + if( feeder.content[ p ] == undefined ) + { + // This is the last character + p --; + } } } - // Backward + + // Forward WORD end + if( e.kMap( "e" ) || e.kMap( "E" ) ) + { + if( feeder.content[ p + 2 ] == undefined ) + { + beep(); + return; + } + + p ++; + while( " \t\n".indexOf( feeder.content[ p ] ) != -1 ) p ++; + + // This is the last character + if( feeder.content[ p ] == undefined ) + { + p --; + } + else + { + var wordRange = analyzer.wordAt( p ); + + if( wordRange.open != -1 ) + { + p = wordRange.close; + } + } + } + + // Backward WORD start if( e.kMap( "b" ) || e.kMap( "B" ) ) { if( p == 0 ) @@ -54,21 +92,17 @@ return; } - d = -1; - - while( " \t".indexOf( feeder.content[ p + d ] ) != -1 ) - { - d --; - } + p --; + while( " \t".indexOf( feeder.content[ p ] ) != -1 ) p --; // No more results - if( ( p + d ) == -1 ) + if( p == -1 ) { p = 0; } else { - var wordRange = analyzer.wordAt( p + d ); + var wordRange = analyzer.wordAt( p ); if( wordRange.open != -1 ) { p = wordRange.open; diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js index 31d3cbd..f72e0a8 100644 --- a/botanjs/src/Components/Vim/Controls.js +++ b/botanjs/src/Components/Vim/Controls.js @@ -599,6 +599,8 @@ case SHIFT + W: case B: case SHIFT + B: + case E: + case SHIFT + E: ccur.openRunAction( "WORD", e ); break @@ -813,7 +815,7 @@ this.__key = RMap( e ); this.__modKeys = 0; this.__kCode = e; - this.__escape = this.__kCode == ESC || this.__kCode == ( CTRL + C ); + this.__escape = this.__kCode == ESC || this.__kCode == ( CTRL + C ) || this.__key == ( CTRL + S_BRACKET_L ); } else { @@ -827,7 +829,7 @@ var c = this.__e.keyCode; - this.__escape = c == ESC || ( e.ctrlKey && c == C ); + this.__escape = c == ESC || ( e.ctrlKey && ( c == C || c == S_BRACKET_L ) ); this.__kCode = c + ( e.shiftKey || e.getModifierState( "CapsLock" ) ? SHIFT : 0 ) + ( e.ctrlKey ? CTRL : 0 )