penguin/AstroJS

Javascript framework for my blog

commit fbb4bae316c4015b217a3f2f24045919a12232ac

author斟酌 鵬兄 <tgckpg@gmail.com>
date2016-04-03T12:55:36Z
subjectAdded b & w
commit fbb4bae316c4015b217a3f2f24045919a12232ac
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2016-04-03T12:55:36Z

    Added b & w
---
 botanjs/src/Components/Vim/Actions/WORD.js | 74 ++++++++++++++++++++++++++++++
 botanjs/src/Components/Vim/Controls.js     | 13 +++++-
 botanjs/src/Components/Vim/Syntax/Word.js  |  4 ++
 3 files changed, 90 insertions(+), 1 deletion(-)

diff --git a/botanjs/src/Components/Vim/Actions/WORD.js b/botanjs/src/Components/Vim/Actions/WORD.js
new file mode 100644
index 0000000..7d69be4
--- /dev/null
+++ b/botanjs/src/Components/Vim/Actions/WORD.js
@@ -0,0 +1,74 @@
+(function(){
+	var ns = __namespace( "Components.Vim.Actions" );
+
+	/** @type {System.Debug} */
+	var debug                                 = __import( "System.Debug" );
+
+	/** @type {Components.Vim.IAction} */
+	var WORD = function( Cursor )
+	{
+		/** @type {Components.Vim.Cursor} */
+		this.__cursor = Cursor;
+		this.__msg = "<WORD COMMAND>";
+		Cursor.suppressEvent();
+	};
+
+	WORD.prototype.dispose = function()
+	{
+		this.__cursor.unsuppressEvent();
+	};
+
+	WORD.prototype.handler = function( e )
+	{
+		e.preventDefault();
+
+		var cur = this.__cursor;
+		var feeder = cur.feeder;
+
+		var analyzer = cur.Vim.contentAnalyzer;
+		var p = cur.aPos;
+
+
+		var d = 1;
+		// forward
+		if( e.kMap( "w" ) || e.kMap( "W" ) )
+		{
+			if( feeder.content[ p + 1 ] == "\n" )
+			{
+				p ++;
+			}
+
+			var wordRange = analyzer.wordAt( p );
+			if( wordRange.open != -1 )
+			{
+				p = wordRange.close + 1;
+			}
+		}
+		// Backward
+		if( e.kMap( "b" ) || e.kMap( "B" ) )
+		{
+			if( p == 0 ) return;
+			d = -1;
+
+			var wordRange = analyzer.wordAt( p - 1 );
+			if( wordRange.open != -1 )
+			{
+				p = wordRange.open;
+			}
+		}
+
+		while( " \t".indexOf( feeder.content[ p ] ) != -1 )
+		{
+			p += d;
+		}
+
+		cur.moveTo( p );
+	};
+
+	WORD.prototype.getMessage = function()
+	{
+		return this.__msg;
+	};
+
+	ns[ NS_EXPORT ]( EX_CLASS, "WORD", WORD );
+})();
diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js
index 6b9efe6..f38b847 100644
--- a/botanjs/src/Components/Vim/Controls.js
+++ b/botanjs/src/Components/Vim/Controls.js
@@ -378,7 +378,11 @@
 				break;
 			case SHIFT + L: // Last line buffer
 				break;
-			case SHIFT + _6: // ^, Start
+
+			case _0: // Really - line Start
+				ccur.lineStart();
+				break;
+			case SHIFT + _6: // ^, line Start, XXX: skip tabs
 				ccur.lineStart();
 				break;
 			case SHIFT + _4: // $, End
@@ -439,6 +443,13 @@
 
 				break;
 
+			case W: // word
+			case SHIFT + W:
+			case B:
+			case SHIFT + B:
+				ccur.openRunAction( "WORD", e );
+				break
+
 
 			case I: // In between boundary
 				if( !ccur.action )
diff --git a/botanjs/src/Components/Vim/Syntax/Word.js b/botanjs/src/Components/Vim/Syntax/Word.js
index d879e59..e76818b 100644
--- a/botanjs/src/Components/Vim/Syntax/Word.js
+++ b/botanjs/src/Components/Vim/Syntax/Word.js
@@ -199,6 +199,10 @@
 			// C1 Controls and Latin-1 Supplement (Extended ASCII)
 			[ 0x00A1, 0x00AC ], [ 0x00AE, 0x00BF ]
 		]
+		,
+		[ // Spaces & tabs
+			[ 0x0020, 0x0020 ], [ 0x0009, 0x0009 ]
+		]
 	];
 
 	var NUM_KINGDOM = KINGDOMS.length;