penguin/AstroJS

Javascript framework for my blog

commit 2b3eb9db31385a85e68932bad58415fb6809ba15

author斟酌 鵬兄 <tgckpg@gmail.com>
date2016-04-03T01:24:14Z
subjectJOIN_LINES for single action
commit 2b3eb9db31385a85e68932bad58415fb6809ba15
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2016-04-03T01:24:14Z

    JOIN_LINES for single action
---
 botanjs/src/Components/Vim/Actions/JOIN_LINES.js | 89 ++++++++++++++++++++++++
 botanjs/src/Components/Vim/Controls.js           |  1 +
 2 files changed, 90 insertions(+)

diff --git a/botanjs/src/Components/Vim/Actions/JOIN_LINES.js b/botanjs/src/Components/Vim/Actions/JOIN_LINES.js
new file mode 100644
index 0000000..4f21af6
--- /dev/null
+++ b/botanjs/src/Components/Vim/Actions/JOIN_LINES.js
@@ -0,0 +1,89 @@
+(function(){
+	var ns = __namespace( "Components.Vim.Actions" );
+
+	/** @type {System.Debug} */
+	var debug                                  = __import( "System.Debug" );
+	/** @type {Components.Vim.State.Stator} */
+	var Stator                                 = __import( "Components.Vim.State.Stator" );
+	/** @type {Components.Vim.State.Stack} */
+	var Stack                                  = __import( "Components.Vim.State.Stack" );
+
+	var beep = __import( "Components.Vim.Beep" );
+	var Mesg = __import( "Components.Vim.Message" );
+
+	var occurance = __import( "System.utils.Perf.CountSubstr" );
+
+	/** @type {Components.Vim.IAction} */
+	var JOIN_LINES = function( Cursor )
+	{
+		/** @type {Components.Vim.Cursor} */
+		this.__cursor = Cursor;
+		this.__msg = "";
+		Cursor.suppressEvent();
+	};
+
+	JOIN_LINES.prototype.dispose = function()
+	{
+		this.__cursor.unsuppressEvent();
+	};
+
+	JOIN_LINES.prototype.handler = function( e, range )
+	{
+		e.preventDefault();
+
+		var cur = this.__cursor;
+		var feeder = cur.feeder;
+
+		var start;
+		var end;
+
+		var stack;
+		var stator;
+
+		var contentUndo;
+		if( range )
+		{
+			start = range.start;
+			end = range.close;
+		}
+		else
+		{
+			var oPos = cur.aPos;
+			cur.lineEnd( true );
+			stator = new Stator( cur );
+			start = cur.aPos;
+			cur.moveY( 1 );
+			cur.lineStart();
+			end = cur.aPos;
+
+			// This happens on the last line
+			if( end < start )
+			{
+				cur.moveTo( oPos );
+				beep();
+				return true;
+			}
+
+			var content = feeder.content;
+
+			contentUndo = feeder.content.substring( start, end );
+			feeder.content = content.substring( 0, start ) + " " + content.substr( end );
+		}
+
+		feeder.pan();
+
+		cur.moveTo( start );
+
+		var stack = new Stack();
+		stack.store( stator.save( 1, contentUndo ) );
+
+		cur.rec.record( stack );
+	};
+
+	JOIN_LINES.prototype.getMessage = function()
+	{
+		return this.__msg;
+	};
+
+	ns[ NS_EXPORT ]( EX_CLASS, "JOIN_LINES", JOIN_LINES );
+})();
diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js
index b52b7c2..2ee60c4 100644
--- a/botanjs/src/Components/Vim/Controls.js
+++ b/botanjs/src/Components/Vim/Controls.js
@@ -262,6 +262,7 @@
 			case SHIFT + I: // Append before the line start, after spaces
 				break;
 			case SHIFT + J: // Join lines
+				ccur.openRunAction( "JOIN_LINES", e );
 				break;
 			case SHIFT + K: // Find the manual entry
 				break;