commit dc63a882e38a2143904ff10487136ac686b5420a
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2016-03-19T11:05:07Z |
| subject | Aaiu, cursor position |
commit dc63a882e38a2143904ff10487136ac686b5420a
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2016-03-19T11:05:07Z
Aaiu, cursor position
---
botanjs/src/Components/Vim/Actions/INSERT.js | 37 +++++++++++++++++++++++++---
botanjs/src/Components/Vim/Controls.js | 9 ++++---
botanjs/src/Components/Vim/Cursor.js | 11 ++++++---
3 files changed, 46 insertions(+), 11 deletions(-)
diff --git a/botanjs/src/Components/Vim/Actions/INSERT.js b/botanjs/src/Components/Vim/Actions/INSERT.js
index 0628330..d97d34c 100644
--- a/botanjs/src/Components/Vim/Actions/INSERT.js
+++ b/botanjs/src/Components/Vim/Actions/INSERT.js
@@ -27,12 +27,24 @@
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
- this.__startX = Cursor.aPos;
+ this.__startState = this.__saveCur();
// Initialize this stack
this.__rec( "", true );
};
+ INSERT.prototype.__saveCur = function()
+ {
+ var c = this.__cursor;
+ return {
+ p: c.P
+ , x: c.X
+ , y: c.Y
+ , px: c.feeder.panX
+ , py: c.feeder.panY
+ };
+ }
+
INSERT.prototype.dispose = function()
{
this.__cursor.moveX( -1 );
@@ -46,8 +58,11 @@
var insertLength = this.__insertLength;
var contentUndo = this.__contentUndo;
var startPos = this.__startPosition;
- var startX = this.__startX;
+ var sSt = this.__startState;
+ var eSt = this.__saveCur();
+ var st = sSt;
+ // Calling this repeatedly will swap between UNDO / REDO state
return function() {
var contentRedo = feeder.content.substr( startPos, insertLength );
feeder.content =
@@ -57,7 +72,15 @@
insertLength = contentUndo.length;
contentUndo = contentRedo;
+ cur.P = st.p;
+ cur.X = st.x;
+ cur.Y = st.y;
+ feeder.panX = st.px;
+ feeder.panY = st.py;
+
feeder.pan();
+
+ st = ( st == sSt ) ? eSt : sSt;
};
};
@@ -168,7 +191,15 @@
this.__rec( inputChar );
- cur.moveX( 1 );
+ if( inputChar == "\n" )
+ {
+ cur.moveY( 1 );
+ cur.lineStart();
+ }
+ else
+ {
+ cur.moveX( 1 );
+ }
};
INSERT.prototype.getMessage = function()
diff --git a/botanjs/src/Components/Vim/Controls.js b/botanjs/src/Components/Vim/Controls.js
index dcaa9dc..5e4d892 100644
--- a/botanjs/src/Components/Vim/Controls.js
+++ b/botanjs/src/Components/Vim/Controls.js
@@ -55,6 +55,7 @@
};
Controls.prototype.__comboT = function( e ) { return false; };
+ Controls.prototype.__comboD = function( e ) { return false; };
// <
Controls.prototype.__comboLeftShift = function( e ) { return false; };
@@ -65,6 +66,7 @@
Controls.prototype.__comboKey = function( e )
{
return this.__comboG( e )
+ || this.__comboD( e )
|| this.__comboT( e )
|| this.__comboLeftShift( e )
|| this.__comboRightShift( e );
@@ -159,11 +161,12 @@
break;
// Insert
+ case SHIFT + A: // Append at the line end
+ ccur.lineEnd();
case A: // Append
cMoveX( 1, true, true );
- ccur.openAction( "INSERT" );
- break;
case I: // Insert
+ ccur.openAction( "INSERT" );
break;
case U: // Undo
ccur.openRunAction( "UNDO", e );
@@ -173,8 +176,6 @@
break;
case X: // Del
break;
- case SHIFT + A: // Append at the line end
- break;
case SHIFT + X: // Delete before
break;
case SHIFT + U: // Undo previous changes in oneline
diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js
index 682232a..b57650f 100644
--- a/botanjs/src/Components/Vim/Cursor.js
+++ b/botanjs/src/Components/Vim/Cursor.js
@@ -112,11 +112,14 @@
var buffs = this.feeder.lineBuffers;
- if( penentrate && x < 0 && ( 0 < this.feeder.panY || 0 < this.Y ) )
+ if( penentrate )
{
- this.moveY( -1 );
- this.lineEnd( phantomSpace );
- return;
+ if( x < 0 && ( 0 < this.feeder.panY || 0 < this.Y ) )
+ {
+ this.moveY( -1 );
+ this.lineEnd( phantomSpace );
+ return;
+ }
}
/** @type {Components.Vim.LineBuffer} */