penguin/AstroJS

Javascript framework for my blog

commit c9c5ff25afc5076b0106c8b069ec6af983137472

author斟酌 鵬兄 <tgckpg@gmail.com>
date2017-03-14T03:32:35Z
subjectFIND does not work properly due to 5311dc0
commit c9c5ff25afc5076b0106c8b069ec6af983137472
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2017-03-14T03:32:35Z

    FIND does not work properly due to 5311dc0
---
 botanjs/src/Components/Vim/Actions/VISUAL.js | 18 ++++++++----
 botanjs/src/Components/Vim/Controls.js       | 42 +++++++++++++++++++++++++++-
 botanjs/src/Components/Vim/Cursor.js         | 12 +++++---
 3 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/botanjs/src/Components/Vim/Actions/VISUAL.js b/botanjs/src/Components/Vim/Actions/VISUAL.js
index 3bdb8d3..6770cac 100644
--- a/botanjs/src/Components/Vim/Actions/VISUAL.js
+++ b/botanjs/src/Components/Vim/Actions/VISUAL.js
@@ -182,10 +182,13 @@
 					startLine.aPos = startLine.aEnd;
 				}
 			}
-			// Cursor position adjustment
-			// this swap the cursor direction from LTR to RTL
-			// i.e. treat all delete as "e<----s" flow
-			// to keep the cursor position as the top on UNDO / REDO
+
+			/**
+			 * Content Modifier:
+			 *   This swaps the cursor direction from LTR to RTL
+			 *   i.e. treat all delete as "e<----s" flow to keep
+			 *        the cursor position as the top on UNDO / REDO
+			 **/
 			var IsContMod = ~[ DELETE, PUT ].indexOf( Action.constructor );
 			if( IsContMod && startLine.aPos < cur.aPos )
 			{
@@ -196,7 +199,12 @@
 
 			Action.handler( e, startLine.aPos, lineMode );
 
-			if( !IsContMod )
+			/**
+			 * Cursor Modifier:
+			 *   Whether the cursor position is already handled
+			 **/
+			var IsCurMod = ~[ DELETE, PUT, SHIFT_LINES ].indexOf( Action.constructor );
+			if( !IsCurMod )
 			{
 				cur.moveTo( startLine.aPos );
 			}
diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js
index 5f4e4d7..20654f1 100644
--- a/botanjs/src/Components/Vim/Controls.js
+++ b/botanjs/src/Components/Vim/Controls.js
@@ -136,6 +136,7 @@
 			case ")": Mod = SHIFT; case "0": kCode = Mod + _0; break;
 			case "<": Mod = SHIFT; case ",": kCode = Mod + COMMA; break;
 			case ">": Mod = SHIFT; case ".": kCode = Mod + FULLSTOP; break;
+			case "\"": Mod = SHIFT; case "'": kCode = Mod + QUOTE; break;
 
 			default:
 				throw new Error( "Unsupport keys: " + str );
@@ -779,6 +780,30 @@
 				this.__divedCCmd = new ExCommand( ccur, "/" );
 				this.__divedCCmd.handler( e );
 				break;
+
+			case SHIFT + SEMI_COLON: // ":", only happens within action
+				if( !ccur.action )
+				{
+					cursorHandled = false;
+					break;
+				}
+
+				this.__cMovement = true;
+
+				var exCmd = new ExCommand( ccur, ":" );
+				exCmd.handler( e );
+
+				// Auto define range '< and '>
+				var cSel = ccur.position;
+				if( 1 < ( cSel.end - cSel.start ) )
+				{
+					ActionEvent
+						.__createEventList( e.sender, "'<,'>" )
+						.forEach( function( e2 ) { exCmd.handler( e2 ); } );
+				}
+
+				this.__divedCCmd = exCmd;
+				break;
 			default:
 				cursorHandled = false;
 		}
@@ -861,7 +886,10 @@
 				{
 					var SubCommand = !this.__compositeReg;
 					this.__cursorCommand( e, kCode );
-					if( SubCommand && this.__compositeReg )
+
+					// Check if Sub / Dived composite command has been initiated
+					// within the CursorCommand
+					if( ( SubCommand && this.__compositeReg ) || this.__divedCCmd )
 					{
 						e.preventDefault();
 						return;
@@ -927,6 +955,18 @@
 		this.__range = null;
 	};
 
+	ActionEvent.__createEventList = function( sender, KeyDefs )
+	{
+		var l = KeyDefs.length;
+		var List = [];
+		for( var i = 0; i < l; i ++ )
+		{
+			List.push( new ActionEvent( sender, KeyDefs[ i ] ) );
+		}
+
+		return List;
+	};
+
 	__readOnly( ActionEvent.prototype, "target", function() { return this.__target; } );
 	__readOnly( ActionEvent.prototype, "key", function() { return this.__key; } );
 	__readOnly( ActionEvent.prototype, "keyCode", function() { return this.__kCode; } );
diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js
index 0e87891..ab3d28b 100644
--- a/botanjs/src/Components/Vim/Cursor.js
+++ b/botanjs/src/Components/Vim/Cursor.js
@@ -134,14 +134,18 @@
 		if( jumpY )
 		{
 			this.moveY( jumpY );
-
-			// Because moveTo is a direct jump function
-			// We'll auto reveal the target line here
-			if( this.feeder.moreAt == this.Y ) this.moveY( 1 );
 		}
 
 		pline = this.getLine();
 
+		// Because moveTo is a direct jump function
+		// We'll have to auto reveal the target line here
+		if( pline.lineNum != expLineNum )
+		{
+			this.moveY( expLineNum - pline.lineNum );
+			pline = this.getLine();
+		}
+
 		var jumpX = aPos < lineStart ? lineStart - aPos : aPos - lineStart;
 		var kX = jumpX - pline.content.length;