forked from Botanical/BotanJS
		
	Put command
This commit is contained in:
		@@ -151,9 +151,9 @@
 | 
				
			|||||||
		feeder.content = c.substring( 0, s ) + c.substring( e + 1 );
 | 
							feeder.content = c.substring( 0, s ) + c.substring( e + 1 );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Try to keep the original panning if possible
 | 
							// Try to keep the original panning if possible
 | 
				
			||||||
		cur.feeder.pan( undefined
 | 
							feeder.pan( undefined
 | 
				
			||||||
			, this.__panY < cur.feeder.panY
 | 
								, this.__panY < feeder.panY
 | 
				
			||||||
				? this.__panY - cur.feeder.panY
 | 
									? this.__panY - feeder.panY
 | 
				
			||||||
				: undefined
 | 
									: undefined
 | 
				
			||||||
		);
 | 
							);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,7 @@
 | 
				
			|||||||
		/** @type {Components.Vim.Cursor} */
 | 
							/** @type {Components.Vim.Cursor} */
 | 
				
			||||||
		this.__cursor = Cursor;
 | 
							this.__cursor = Cursor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		this.__Stator = new Stator( Cursor );
 | 
							this.__stator = new Stator( Cursor );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Initialize this stack
 | 
							// Initialize this stack
 | 
				
			||||||
		this.__rec( "", true );
 | 
							this.__rec( "", true );
 | 
				
			||||||
@@ -55,7 +55,7 @@
 | 
				
			|||||||
				) return;
 | 
									) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				this.__stack.store(
 | 
									this.__stack.store(
 | 
				
			||||||
					this.__Stator.save( this.__insertLength, this.__contentUndo )
 | 
										this.__stator.save( this.__insertLength, this.__contentUndo )
 | 
				
			||||||
				);
 | 
									);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				this.__cursor.rec.record( this.__stack );
 | 
									this.__cursor.rec.record( this.__stack );
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										81
									
								
								botanjs/src/Components/Vim/Actions/PUT.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										81
									
								
								botanjs/src/Components/Vim/Actions/PUT.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,81 @@
 | 
				
			|||||||
 | 
					(function(){
 | 
				
			||||||
 | 
						var ns = __namespace( "Components.Vim.Actions" );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var Mesg = __import( "Components.Vim.Message" );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** @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 Mesg = __import( "Components.Vim.Message" );
 | 
				
			||||||
 | 
						var occurence = __import( "System.utils.Perf.CountSubstr" );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/** @type {Components.Vim.Cursor.IAction} */
 | 
				
			||||||
 | 
						var PUT = function( Cursor )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							/** @type {Components.Vim.Cursor} */
 | 
				
			||||||
 | 
							this.__cursor = Cursor;
 | 
				
			||||||
 | 
							this.__stator = new Stator( Cursor );
 | 
				
			||||||
 | 
							this.__msg = "";
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						PUT.prototype.allowMovement = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						PUT.prototype.dispose = function()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						PUT.prototype.handler = function( e )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							e.preventDefault();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// TODO: Get the input for determinating registers
 | 
				
			||||||
 | 
							var inputStack = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var cput = this.__cursor.Vim.registers.get( inputStack );
 | 
				
			||||||
 | 
							if( !cput ) return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var clen = cput.length;
 | 
				
			||||||
 | 
							var nLines = occurence( cput, "\n" );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var cur = this.__cursor;
 | 
				
			||||||
 | 
							var feeder = cur.feeder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var aP = cur.aPos;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							feeder.content = feeder.content.substring( 0, aP )
 | 
				
			||||||
 | 
								+ cput
 | 
				
			||||||
 | 
								+ feeder.content.substring( aP );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							cur.suppressEvent();
 | 
				
			||||||
 | 
							feeder.pan();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							cur.moveTo( 0 < nLines ? aP : aP + clen, true );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							var stack = new Stack();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							stack.store( this.__stator.save( clen, "" ) );
 | 
				
			||||||
 | 
							cur.rec.record( stack );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							this.__put = cput;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							if( nLines )
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								this.__msg = Mesg( "LINE_MORE", nLines );
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							cur.moveX( -1 );
 | 
				
			||||||
 | 
							cur.unsuppressEvent();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return true;
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						PUT.prototype.getMessage = function()
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							console.log( this.__msg );
 | 
				
			||||||
 | 
							return this.__msg;
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						ns[ NS_EXPORT ]( EX_CLASS, "PUT", PUT );
 | 
				
			||||||
 | 
					})();
 | 
				
			||||||
@@ -76,6 +76,12 @@
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			Action.handler( e, this.__startaP );
 | 
								Action.handler( e, this.__startaP );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								if( Action.constructor != DELETE )
 | 
				
			||||||
 | 
								{
 | 
				
			||||||
 | 
									cur.moveTo( this.__startaP );
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			this.__leaveMesg = Action.getMessage();
 | 
								this.__leaveMesg = Action.getMessage();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			Action.dispose();
 | 
								Action.dispose();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -35,6 +35,7 @@
 | 
				
			|||||||
	var F11 = 122; var F12 = 123;
 | 
						var F11 = 122; var F12 = 123;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var COMMA = 188; var FULLSTOP = 190;
 | 
						var COMMA = 188; var FULLSTOP = 190;
 | 
				
			||||||
 | 
						var SLASH = 191; var BACK_SLASH = 220;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var __maps = {};
 | 
						var __maps = {};
 | 
				
			||||||
	var Map = function( str )
 | 
						var Map = function( str )
 | 
				
			||||||
@@ -128,12 +129,12 @@
 | 
				
			|||||||
		this.__ccur = this.__cfeeder.cursor;
 | 
							this.__ccur = this.__cfeeder.cursor;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	Controls.prototype.__comp = function( e, handler )
 | 
						Controls.prototype.__composite = function( e, handler )
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		if( handler )
 | 
							if( handler )
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if( !this.__compReg ) this.__compReg = [];
 | 
								if( !this.__compositeReg ) this.__compositeReg = [];
 | 
				
			||||||
			this.__compReg.push({
 | 
								this.__compositeReg.push({
 | 
				
			||||||
				keys: Array.prototype.slice.call( arguments, 2 )
 | 
									keys: Array.prototype.slice.call( arguments, 2 )
 | 
				
			||||||
				, handler: handler
 | 
									, handler: handler
 | 
				
			||||||
				, i: 0
 | 
									, i: 0
 | 
				
			||||||
@@ -143,9 +144,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		var kCode = e.keyCode;
 | 
							var kCode = e.keyCode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for( var i = 0; i < this.__compReg.length; i ++ )
 | 
							for( var i = 0; i < this.__compositeReg.length; i ++ )
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			var compReg = this.__compReg[i];
 | 
								var compReg = this.__compositeReg[i];
 | 
				
			||||||
			var keys = compReg.keys;
 | 
								var keys = compReg.keys;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			if( keys[ compReg.i ++ ] == kCode )
 | 
								if( keys[ compReg.i ++ ] == kCode )
 | 
				
			||||||
@@ -153,7 +154,7 @@
 | 
				
			|||||||
				if( compReg.i == keys.length )
 | 
									if( compReg.i == keys.length )
 | 
				
			||||||
				{
 | 
									{
 | 
				
			||||||
					compReg.handler( e );
 | 
										compReg.handler( e );
 | 
				
			||||||
					this.__compReg = null;
 | 
										this.__compositeReg = null;
 | 
				
			||||||
					this.__cMovement = false;
 | 
										this.__cMovement = false;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -161,8 +162,8 @@
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( this.__compReg ) beep();
 | 
							if( this.__compositeReg ) beep();
 | 
				
			||||||
		this.__compReg = null;
 | 
							this.__compositeReg = null;
 | 
				
			||||||
		this.__cMovement = false;
 | 
							this.__cMovement = false;
 | 
				
			||||||
		return false;
 | 
							return false;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
@@ -191,6 +192,15 @@
 | 
				
			|||||||
			case D: // Del with motion
 | 
								case D: // Del with motion
 | 
				
			||||||
				ccur.openAction( "DELETE" );
 | 
									ccur.openAction( "DELETE" );
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case P: // Put
 | 
				
			||||||
 | 
									ccur.suppressEvent();
 | 
				
			||||||
 | 
									ccur.moveX( 1, false, true );
 | 
				
			||||||
 | 
									ccur.unsuppressEvent();
 | 
				
			||||||
 | 
								case SHIFT + P: // Put before
 | 
				
			||||||
 | 
									ccur.openRunAction( "PUT", e );
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case X: // Del
 | 
								case X: // Del
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
			case SHIFT + X: // Delete before
 | 
								case SHIFT + X: // Delete before
 | 
				
			||||||
@@ -247,11 +257,11 @@
 | 
				
			|||||||
	{
 | 
						{
 | 
				
			||||||
		var kCode = e.keyCode;
 | 
							var kCode = e.keyCode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if( this.__cMovement && this.__comp )
 | 
							if( this.__cMovement && this.__composite )
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if( !e.ModKeys )
 | 
								if( !e.ModKeys )
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				this.__comp( e );
 | 
									this.__composite( e );
 | 
				
			||||||
				return true;
 | 
									return true;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -344,7 +354,7 @@
 | 
				
			|||||||
				this.__cMovement = true;
 | 
									this.__cMovement = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// Word boundary
 | 
									// Word boundary
 | 
				
			||||||
				this.__comp( e, function( e2 ) {
 | 
									this.__composite( e, function( e2 ) {
 | 
				
			||||||
					var WordMatch = analyzer.wordAt( ccur.aPos );
 | 
										var WordMatch = analyzer.wordAt( ccur.aPos );
 | 
				
			||||||
					e2.__range = WordMatch;
 | 
										e2.__range = WordMatch;
 | 
				
			||||||
				}, W );
 | 
									}, W );
 | 
				
			||||||
@@ -363,25 +373,28 @@
 | 
				
			|||||||
				};
 | 
									};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// Bracket boundaries
 | 
									// Bracket boundaries
 | 
				
			||||||
				this.__comp( e, bracket , SHIFT + _0 );
 | 
									this.__composite( e, bracket , SHIFT + _0 );
 | 
				
			||||||
				this.__comp( e, bracket, SHIFT + _9 );
 | 
									this.__composite( e, bracket, SHIFT + _9 );
 | 
				
			||||||
				this.__comp( e, squareBracket, S_BRACKET_L );
 | 
									this.__composite( e, squareBracket, S_BRACKET_L );
 | 
				
			||||||
				this.__comp( e, squareBracket, S_BRACKET_R );
 | 
									this.__composite( e, squareBracket, S_BRACKET_R );
 | 
				
			||||||
				this.__comp( e, curlyBracket, SHIFT + S_BRACKET_L );
 | 
									this.__composite( e, curlyBracket, SHIFT + S_BRACKET_L );
 | 
				
			||||||
				this.__comp( e, curlyBracket, SHIFT + S_BRACKET_R );
 | 
									this.__composite( e, curlyBracket, SHIFT + S_BRACKET_R );
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			case G: // Go to top
 | 
								case G: // Go to top
 | 
				
			||||||
				this.__cMovement = true;
 | 
									this.__cMovement = true;
 | 
				
			||||||
				this.__comp( e, function(){
 | 
									this.__composite( e, function(){
 | 
				
			||||||
					ccur.moveY( -Number.MAX_VALUE );
 | 
										ccur.moveY( -Number.MAX_VALUE );
 | 
				
			||||||
					ccur.moveX( -Number.MAX_VALUE, true );
 | 
										ccur.moveX( -Number.MAX_VALUE, true );
 | 
				
			||||||
				}, G );
 | 
									}, G );
 | 
				
			||||||
				this.__comp( e, function(){
 | 
									this.__composite( e, function(){
 | 
				
			||||||
					ccur.openRunAction( "PRINT_HEX", e );
 | 
										ccur.openRunAction( "PRINT_HEX", e );
 | 
				
			||||||
				}, _8 );
 | 
									}, _8 );
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								case SLASH: // "/" Seach movement
 | 
				
			||||||
 | 
									this.__cMovement = true;
 | 
				
			||||||
 | 
									break;
 | 
				
			||||||
			default:
 | 
								default:
 | 
				
			||||||
				cursorHandled = false;
 | 
									cursorHandled = false;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
@@ -402,9 +415,9 @@
 | 
				
			|||||||
		) return;
 | 
							) return;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Clear composite command
 | 
							// Clear composite command
 | 
				
			||||||
		if( e.Escape && this.__compReg )
 | 
							if( e.Escape && this.__compositeReg )
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			this.__compReg = null;
 | 
								this.__compositeReg = null;
 | 
				
			||||||
			this.__cMovement = false;
 | 
								this.__cMovement = false;
 | 
				
			||||||
			beep();
 | 
								beep();
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -46,5 +46,13 @@
 | 
				
			|||||||
		r[ 1 ] = str;
 | 
							r[ 1 ] = str;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						Registers.prototype.get = function( r )
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							// 0 is one of the registers
 | 
				
			||||||
 | 
							if( !r && r !== 0  ) r = "\"";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return this.__registers[ r ];
 | 
				
			||||||
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ns[ NS_EXPORT ]( EX_CLASS, "Registers", Registers );
 | 
						ns[ NS_EXPORT ]( EX_CLASS, "Registers", Registers );
 | 
				
			||||||
})();
 | 
					})();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -19,6 +19,7 @@
 | 
				
			|||||||
		, "REDO_LIMIT": "Already at newest change"
 | 
							, "REDO_LIMIT": "Already at newest change"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		, "LINE_FEWER": "%1 fewer lines"
 | 
							, "LINE_FEWER": "%1 fewer lines"
 | 
				
			||||||
 | 
							, "LINE_MORE": "%1 more lines"
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var errors = {
 | 
						var errors = {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user