penguin/AstroJS

Javascript framework for my blog

commit 36a2dfac797c11fa5b663944ff50b135f0554604

author斟酌 鵬兄 <tgckpg@gmail.com>
date2017-01-30T06:33:00Z
subjectFixed w motion, added e motion
commit 36a2dfac797c11fa5b663944ff50b135f0554604
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2017-01-30T06:33:00Z

    Fixed w motion, added e motion
---
 botanjs/src/Components/Vim/Actions/WORD.js | 58 +++++++++++++++++++++++-------
 botanjs/src/Components/Vim/Controls.js     |  6 ++--
 2 files changed, 50 insertions(+), 14 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,45 +30,79 @@
 		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
-		if( e.kMap( "b" ) || e.kMap( "B" ) )
+
+		// Forward WORD end
+		if( e.kMap( "e" ) || e.kMap( "E" ) )
 		{
-			if( p == 0 )
+			if( feeder.content[ p + 2 ] == undefined )
 			{
 				beep();
 				return;
 			}
 
-			d = -1;
+			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;
+				}
+			}
+		}
 
-			while( " \t".indexOf( feeder.content[ p + d ] ) != -1 )
+		// Backward WORD start
+		if( e.kMap( "b" ) || e.kMap( "B" ) )
+		{
+			if( p == 0 )
 			{
-				d --;
+				beep();
+				return;
 			}
 
+			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 )