commit cfa2e45e3df176a56f6b0c197fc8e3cec3519516
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2016-03-31T12:25:43Z |
| subject | Put command |
commit cfa2e45e3df176a56f6b0c197fc8e3cec3519516
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2016-03-31T12:25:43Z
Put command
---
botanjs/src/Components/Vim/Actions/DELETE.js | 6 +-
botanjs/src/Components/Vim/Actions/INSERT.js | 4 +-
botanjs/src/Components/Vim/Actions/PUT.js | 81 +++++++++++++++++++++++++++
botanjs/src/Components/Vim/Actions/VISUAL.js | 6 ++
botanjs/src/Components/Vim/Controls.js | 55 +++++++++++-------
botanjs/src/Components/Vim/State/Registers.js | 8 +++
botanjs/src/Components/Vim/_this.js | 1 +
7 files changed, 135 insertions(+), 26 deletions(-)
diff --git a/botanjs/src/Components/Vim/Actions/DELETE.js b/botanjs/src/Components/Vim/Actions/DELETE.js
index f5af2e0..1f05cbb 100644
--- a/botanjs/src/Components/Vim/Actions/DELETE.js
+++ b/botanjs/src/Components/Vim/Actions/DELETE.js
@@ -151,9 +151,9 @@
feeder.content = c.substring( 0, s ) + c.substring( e + 1 );
// Try to keep the original panning if possible
- cur.feeder.pan( undefined
- , this.__panY < cur.feeder.panY
- ? this.__panY - cur.feeder.panY
+ feeder.pan( undefined
+ , this.__panY < feeder.panY
+ ? this.__panY - feeder.panY
: undefined
);
diff --git a/botanjs/src/Components/Vim/Actions/INSERT.js b/botanjs/src/Components/Vim/Actions/INSERT.js
index 7eb38eb..0e805ee 100644
--- a/botanjs/src/Components/Vim/Actions/INSERT.js
+++ b/botanjs/src/Components/Vim/Actions/INSERT.js
@@ -29,7 +29,7 @@
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
- this.__Stator = new Stator( Cursor );
+ this.__stator = new Stator( Cursor );
// Initialize this stack
this.__rec( "", true );
@@ -55,7 +55,7 @@
) return;
this.__stack.store(
- this.__Stator.save( this.__insertLength, this.__contentUndo )
+ this.__stator.save( this.__insertLength, this.__contentUndo )
);
this.__cursor.rec.record( this.__stack );
diff --git a/botanjs/src/Components/Vim/Actions/PUT.js b/botanjs/src/Components/Vim/Actions/PUT.js
new file mode 100644
index 0000000..164899b
--- /dev/null
+++ b/botanjs/src/Components/Vim/Actions/PUT.js
@@ -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 );
+})();
diff --git a/botanjs/src/Components/Vim/Actions/VISUAL.js b/botanjs/src/Components/Vim/Actions/VISUAL.js
index 7cac789..caac607 100644
--- a/botanjs/src/Components/Vim/Actions/VISUAL.js
+++ b/botanjs/src/Components/Vim/Actions/VISUAL.js
@@ -76,6 +76,12 @@
}
Action.handler( e, this.__startaP );
+
+ if( Action.constructor != DELETE )
+ {
+ cur.moveTo( this.__startaP );
+ }
+
this.__leaveMesg = Action.getMessage();
Action.dispose();
diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js
index e6f529a..522e35d 100644
--- a/botanjs/src/Components/Vim/Controls.js
+++ b/botanjs/src/Components/Vim/Controls.js
@@ -35,6 +35,7 @@
var F11 = 122; var F12 = 123;
var COMMA = 188; var FULLSTOP = 190;
+ var SLASH = 191; var BACK_SLASH = 220;
var __maps = {};
var Map = function( str )
@@ -128,12 +129,12 @@
this.__ccur = this.__cfeeder.cursor;
};
- Controls.prototype.__comp = function( e, handler )
+ Controls.prototype.__composite = function( e, handler )
{
if( handler )
{
- if( !this.__compReg ) this.__compReg = [];
- this.__compReg.push({
+ if( !this.__compositeReg ) this.__compositeReg = [];
+ this.__compositeReg.push({
keys: Array.prototype.slice.call( arguments, 2 )
, handler: handler
, i: 0
@@ -143,9 +144,9 @@
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;
if( keys[ compReg.i ++ ] == kCode )
@@ -153,7 +154,7 @@
if( compReg.i == keys.length )
{
compReg.handler( e );
- this.__compReg = null;
+ this.__compositeReg = null;
this.__cMovement = false;
}
@@ -161,8 +162,8 @@
}
}
- if( this.__compReg ) beep();
- this.__compReg = null;
+ if( this.__compositeReg ) beep();
+ this.__compositeReg = null;
this.__cMovement = false;
return false;
};
@@ -191,6 +192,15 @@
case D: // Del with motion
ccur.openAction( "DELETE" );
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
break;
case SHIFT + X: // Delete before
@@ -247,11 +257,11 @@
{
var kCode = e.keyCode;
- if( this.__cMovement && this.__comp )
+ if( this.__cMovement && this.__composite )
{
if( !e.ModKeys )
{
- this.__comp( e );
+ this.__composite( e );
return true;
}
}
@@ -344,7 +354,7 @@
this.__cMovement = true;
// Word boundary
- this.__comp( e, function( e2 ) {
+ this.__composite( e, function( e2 ) {
var WordMatch = analyzer.wordAt( ccur.aPos );
e2.__range = WordMatch;
}, W );
@@ -363,25 +373,28 @@
};
// Bracket boundaries
- this.__comp( e, bracket , SHIFT + _0 );
- this.__comp( e, bracket, SHIFT + _9 );
- this.__comp( e, squareBracket, S_BRACKET_L );
- this.__comp( e, squareBracket, S_BRACKET_R );
- this.__comp( e, curlyBracket, SHIFT + S_BRACKET_L );
- this.__comp( e, curlyBracket, SHIFT + S_BRACKET_R );
+ this.__composite( e, bracket , SHIFT + _0 );
+ this.__composite( e, bracket, SHIFT + _9 );
+ this.__composite( e, squareBracket, S_BRACKET_L );
+ this.__composite( e, squareBracket, S_BRACKET_R );
+ this.__composite( e, curlyBracket, SHIFT + S_BRACKET_L );
+ this.__composite( e, curlyBracket, SHIFT + S_BRACKET_R );
break;
case G: // Go to top
this.__cMovement = true;
- this.__comp( e, function(){
+ this.__composite( e, function(){
ccur.moveY( -Number.MAX_VALUE );
ccur.moveX( -Number.MAX_VALUE, true );
}, G );
- this.__comp( e, function(){
+ this.__composite( e, function(){
ccur.openRunAction( "PRINT_HEX", e );
}, _8 );
break;
+ case SLASH: // "/" Seach movement
+ this.__cMovement = true;
+ break;
default:
cursorHandled = false;
}
@@ -402,9 +415,9 @@
) return;
// Clear composite command
- if( e.Escape && this.__compReg )
+ if( e.Escape && this.__compositeReg )
{
- this.__compReg = null;
+ this.__compositeReg = null;
this.__cMovement = false;
beep();
return;
diff --git a/botanjs/src/Components/Vim/State/Registers.js b/botanjs/src/Components/Vim/State/Registers.js
index 220fe70..48ca4a3 100644
--- a/botanjs/src/Components/Vim/State/Registers.js
+++ b/botanjs/src/Components/Vim/State/Registers.js
@@ -46,5 +46,13 @@
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 );
})();
diff --git a/botanjs/src/Components/Vim/_this.js b/botanjs/src/Components/Vim/_this.js
index f9e572e..8a5b199 100644
--- a/botanjs/src/Components/Vim/_this.js
+++ b/botanjs/src/Components/Vim/_this.js
@@ -19,6 +19,7 @@
, "REDO_LIMIT": "Already at newest change"
, "LINE_FEWER": "%1 fewer lines"
+ , "LINE_MORE": "%1 more lines"
};
var errors = {