Merge remote-tracking branch 'vim/master' into Astro

This commit is contained in:
斟酌 鵬兄 2016-03-16 00:13:40 +08:00
commit e2d9d83938
15 changed files with 368 additions and 163 deletions

View File

@ -1,19 +1,21 @@
(function(){
var ns = __namespace( "Components.Vim.Actions" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
/** @type {Dandelion.IDOMElement} */
var IDOMElement = __import( "Dandelion.IDOMElement" );
/** @type {Dandelion.IDOMObject} */
var IDOMObject = __import( "Dandelion.IDOMObject" );
/** @type {System.Cycle} */
var Cycle = __import( "System.Cycle" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var debug = __import( "System.Debug" );
var Mesg = __import( "Components.Vim.Message" );
var Translate = function( c )
{
switch( c )
{
case "Tab":
return "\t";
default:
return c;
}
};
/** @type {Components.Vim.Cursor.IAction} */
var INSERT = function( Cursor )
{
@ -25,6 +27,46 @@
{
};
INSERT.prototype.handler = function( e )
{
e.preventDefault();
var inputChar = Translate( e.key );
if( inputChar.length != 1 ) return;
var cur = this.cursor;
var feeder = cur.feeder;
var line = cur.getLine();
var n = line.lineNum;
var cont = feeder.content;
var f = 0;
if( 0 < n )
{
f = cont.indexOf( "\n" );
for( i = 1; f != -1 && i < n; i ++ )
{
f = cont.indexOf( "\n", f + 1 );
}
if( this.cursor.feeder.wrap )
{
// wordwrap offset
f ++;
}
}
f += cur.aX;
feeder.content = cont.substring( 0, f ) + inputChar + cont.substring( f );
feeder.pan();
feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) );
cur.moveX( 1 );
};
INSERT.prototype.getMessage = function()
{
var l = this.cursor.feeder.firstBuffer.cols;

View File

@ -0,0 +1,101 @@
(function(){
var ns = __namespace( "Components.Vim" );
var debug = __import( "System.Debug" );
var Controls = function( sender, e )
{
// Neve capture these keys
if( e.altKey
// F2 - F12
|| ( 112 < e.keyCode && e.keyCode < 124 )
) return;
// Action Mode handled by the actions themselves
var cfeeder = sender.contentFeeder;
if( cfeeder.cursor.action )
{
// Esc OR Ctrl+c
if( e.keyCode == 27 || ( e.ctrlKey && e.keyCode == 67 ) )
{
e.preventDefault();
cfeeder.cursor.closeAction();
}
else
{
cfeeder.cursor.action.handler( e );
}
return;
}
e.preventDefault();
if( e.ctrlKey )
{
VimComboFunc( sender, e );
return;
}
var kCode = e.keyCode + ( e.shiftKey ? 1000 : 0 );
var cfeeder = sender.contentFeeder;
var sfeeder = sender.statusFeeder;
switch( kCode )
{
// Cursor movements
case 8: // Backspace, go back 1 char, regardless of line
break;
case 72: // h
cfeeder.cursor.moveX( -1 );
break;
case 74: // j
cfeeder.cursor.moveY( 1 );
break;
case 75: // k
cfeeder.cursor.moveY( -1 );
break;
case 76: // l
cfeeder.cursor.moveX( 1 );
break;
// Insert
case 65: // a
cfeeder.cursor.openAction( "INSERT" );
break;
case 1065: // A, append at the line end
break;
case 73: // i
break;
case 1073: // I, append before the line start, after spaces
break;
// remove characters
case 88: // x, remove in cursor
break;
case 1088: // X, remove before cursor
break;
case 1072: // H, First line buffer
break;
case 1076: // L, Last line buffer
break;
case 1052: // $
cfeeder.cursor.lineEnd();
break;
case 1053: // %
break;
case 1054: // ^
cfeeder.cursor.lineStart();
break;
case 1074: // J, Join lines
break;
case 1075: // K, manual entry
break;
case 112: // F1, help
}
};
ns[ NS_EXPORT ]( EX_FUNC, "Controls", Controls );
})();

View File

@ -1,16 +1,8 @@
(function(){
var ns = __namespace( "Components.Vim" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
/** @type {Dandelion.IDOMElement} */
var IDOMElement = __import( "Dandelion.IDOMElement" );
/** @type {Dandelion.IDOMObject} */
var IDOMObject = __import( "Dandelion.IDOMObject" );
/** @type {System.Cycle} */
var Cycle = __import( "System.Cycle" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var debug = __import( "System.Debug" );
var Actions = __import( "Components.Vim.Actions.*" );
@ -79,7 +71,6 @@
// The resulting position
this.P = 0;
/** @type {Components.Vim.IAction} */
this.action = null;
};
@ -215,13 +206,21 @@
this.updatePosition();
};
Cursor.prototype.openInsert = function()
Cursor.prototype.openAction = function( name )
{
var feeder = this.feeder;
if( this.action ) this.action.dispose();
this.action = new Actions[ "INSERT" ];
this.action = new (Actions[ name ])( this );
feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) );
this.feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) );
};
Cursor.prototype.closeAction = function()
{
if( !this.action ) return;
this.action.dispose();
this.action = null;
this.feeder.dispatcher.dispatchEvent( new BotanEvent( "VisualUpdate" ) );
};
Cursor.prototype.getLine = function()
@ -239,12 +238,32 @@
return line;
};
// The absX for current Line
__readOnly( Cursor.prototype, "aX", function()
{
var X = this.X;
var f = this.feeder;
// Calculate wordwrap offset
if( f.wrap )
{
var cols = f.firstBuffer.cols + 1;
var w = X < cols ? 0 : Math.floor( X / cols );
if( 0 < w )
{
X -= w;
}
}
return X;
} );
__readOnly( Cursor.prototype, "message", function()
{
return this.action && this.action.getMessage();
} );
__readOnly( Cursor.prototype, "position", function()
{
return {

View File

@ -1,16 +1,7 @@
(function(){
var ns = __namespace( "Components.Vim" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
/** @type {Dandelion.IDOMElement} */
var IDOMElement = __import( "Dandelion.IDOMElement" );
/** @type {Dandelion.IDOMObject} */
var IDOMObject = __import( "Dandelion.IDOMObject" );
/** @type {System.Cycle} */
var Cycle = __import( "System.Cycle" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var debug = __import( "System.Debug" );
var LineBuffer = function( cols, nextLineBuffer )
{
@ -48,9 +39,10 @@
var i = 0;
var numTabs = 0;
var tabw = this.tabWidth - 1;
if( wrap )
{
for( ; i < this.cols - numTabs * this.tabWidth; i ++ )
for( ; i < this.cols - numTabs * tabw; i ++ )
{
var c = content[i];
if( c === undefined ) break;
@ -87,7 +79,7 @@
numTabs ++;
}
if( i < this.cols - numTabs * this.tabWidth )
if( i < this.cols - numTabs * tabw )
{
line += c;
}

View File

@ -1,16 +1,8 @@
(function(){
var ns = __namespace( "Components.Vim" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
/** @type {Dandelion.IDOMElement} */
var IDOMElement = __import( "Dandelion.IDOMElement" );
/** @type {Dandelion.IDOMObject} */
var IDOMObject = __import( "Dandelion.IDOMObject" );
/** @type {System.Cycle} */
var Cycle = __import( "System.Cycle" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var debug = __import( "System.Debug" );
/** @type {Components.Vim.LineBuffer} */
var LineBuffer = ns[ NS_INVOKE ]( "LineBuffer" );
@ -34,6 +26,8 @@
this.panX = 0;
this.panY = 0;
this.wrap = true;
this.setRender();
this.cursor = new Cursor( this );
@ -42,8 +36,6 @@
this.__clseLine = null;
this.__moreAt = -1;
this.__rows = rows;
this.__wrap = true;
};
Feeder.prototype.init = function( content, wrap )
@ -51,13 +43,15 @@
this.content = content;
this.setWrap( wrap );
this.firstBuffer.Push( content, this.__wrap, 0 );
this.firstBuffer.Push( content, this.wrap, 0 );
};
Feeder.prototype.setWrap = function( wrap )
{
if( wrap == undefined ) return;
this.__wrap = wrap;
this.wrap = wrap;
// TODO: Update
};
Feeder.prototype.setRender = function( placeholder )
@ -136,8 +130,6 @@
if( dX == undefined ) dX = 0;
if( dY == undefined ) dY = 0;
if( dX == 0 && dY == 0 ) return;
var X = this.panX + dX;
var Y = this.panY + dY;
@ -150,7 +142,7 @@
if( 0 < Y )
{
f = this.content.indexOf( "\n" );
for( i = 1; f != - 1 && i < Y; i ++ )
for( i = 1; f != -1 && i < Y; i ++ )
{
f = this.content.indexOf( "\n", f + 1 );
}
@ -158,7 +150,7 @@
this.firstBuffer.Push(
this.content.substr( f + 1 )
, this.__wrap, i );
, this.wrap, i );
this.panX = X;
this.panY = Y;
@ -203,8 +195,7 @@
} );
__readOnly( Feeder.prototype, "lineStat", function() {
var X = this.cursor.X;
var X = this.cursor.aX;
var line = this.cursor.getLine();
var tabStat = "";

View File

@ -1,16 +1,7 @@
(function(){
var ns = __namespace( "Components.Vim" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
/** @type {Dandelion.IDOMElement} */
var IDOMElement = __import( "Dandelion.IDOMElement" );
/** @type {Dandelion.IDOMObject} */
var IDOMObject = __import( "Dandelion.IDOMObject" );
/** @type {System.Cycle} */
var Cycle = __import( "System.Cycle" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var debug = __import( "System.Debug" );
/** @type {Components.VimArea.LineFeeder} */
var LineFeeder = ns[ NS_INVOKE ]( "LineFeeder" );

View File

@ -1,12 +1,8 @@
(function(){
var ns = __namespace( "Components.Vim" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
/** @type {Dandelion.IDOMElement} */
var IDOMElement = __import( "Dandelion.IDOMElement" );
/** @type {Dandelion.IDOMObject} */
var IDOMObject = __import( "Dandelion.IDOMObject" );
/** @type {System.utils.DataKey} */
var DataKey = __import( "System.utils.DataKey" );
/** @type {System.Cycle} */
@ -19,6 +15,7 @@
/** @type {Components.Vim.StatusBar} */
var StatusBar = ns[ NS_INVOKE ]( "StatusBar" );
var VimControls = ns[ NS_INVOKE ]( "Controls" );
var mesg = ns[ NS_INVOKE ]( "Message" );
var KeyHandler = function( sender, handler )
@ -33,81 +30,6 @@
};
};
var VimControls = function( sender, e )
{
if( e.altKey
// F2 - F12
|| ( 112 < e.keyCode && e.keyCode < 124 )
) return;
e.preventDefault();
if( e.ctrlKey )
{
VimComboFunc( sender, e );
return;
}
var kCode = e.keyCode + ( e.shiftKey ? 1000 : 0 );
var cfeeder = sender.contentFeeder;
var sfeeder = sender.statusFeeder;
switch( kCode )
{
// Cursor movements
case 8: // Backspace, go back 1 char, regardless of line
break;
case 72: // h
cfeeder.cursor.moveX( -1 );
break;
case 74: // j
cfeeder.cursor.moveY( 1 );
break;
case 75: // k
cfeeder.cursor.moveY( -1 );
break;
case 76: // l
cfeeder.cursor.moveX( 1 );
break;
// Insert
case 65: // a
cfeeder.cursor.openInsert();
break;
case 1065: // A, append at the line end
break;
case 73: // i
break;
case 1073: // I, append before the line start, after spaces
break;
// remove characters
case 88: // x, remove in cursor
break;
case 1088: // X, remove before cursor
break;
case 1072: // H, First line buffer
break;
case 1076: // L, Last line buffer
break;
case 1052: // $
cfeeder.cursor.lineEnd();
break;
case 1053: // %
break;
case 1054: // ^
cfeeder.cursor.lineStart();
break;
case 1074: // J, Join lines
break;
case 1075: // K, manual entry
break;
case 112: // F1, help
}
};
/* stage @param {Dandelion.IDOMElement} */
var VimArea = function( stage )
{
@ -127,9 +49,6 @@
this.rows = element.rows;
this.cols = element.cols;
this.PosX = 1;
this.PosY = 1;
this.__active = false;
var _self = this;
@ -142,10 +61,6 @@
this.VisualizeVimFrame( element.value );
};
VimArea.prototype.startInput = function( mode )
{
};
VimArea.prototype.select = function( sel )
{
if( !this.__active ) return;

View File

@ -1,17 +1,6 @@
(function(){
var ns = __namespace( "Components.Vim" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
/** @type {Dandelion.IDOMElement} */
var IDOMElement = __import( "Dandelion.IDOMElement" );
/** @type {Dandelion.IDOMObject} */
var IDOMObject = __import( "Dandelion.IDOMObject" );
/** @type {System.Cycle} */
var Cycle = __import( "System.Cycle" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var messages = {
"INSERT": "-- INSERT --"
, "REPLACE": "-- REPLACE --"

View File

@ -0,0 +1,45 @@
/** @constructor */
Components.Vim.Cursor = function(){};
/** @type {Components.Vim.LineFeeder} */
Components.Vim.Cursor.feeder;
/** @type {Components.Vim.IAction} */
Components.Vim.Cursor.action;
/** @type Function */
Components.Vim.Cursor.moveX;
/** @type Function */
Components.Vim.Cursor.moveY;
/** @type Function */
Components.Vim.Cursor.lineStart;
/** @type Function */
Components.Vim.Cursor.lineEnd;
/** @type Function */
Components.Vim.Cursor.updatePosition;
/** @type Function */
Components.Vim.Cursor.openAction;
/** @type Function */
Components.Vim.Cursor.closeAction;
/** @type {Array} */
Components.Vim.Cursor.lineBuffers;
/** @type Number */
Components.Vim.Cursor.pX;
/** @type Number */
Components.Vim.Cursor.P;
/** @type Number */
Components.Vim.Cursor.aX;
/** @type Number */
Components.Vim.Cursor.X;
/** @type Number */
Components.Vim.Cursor.Y;
/** @type Number */
Components.Vim.Cursor.cols;
/** @type message */
Components.Vim.Cursor.string;
/** @type Object */
Components.Vim.Cursor.position;
/** @type Number */
Components.Vim.Cursor.position.start;
/** @type Number */
Components.Vim.Cursor.position.end;

View File

@ -0,0 +1,9 @@
/** @constructor */
Components.Vim.IAction = function(){};
/** @type Function */
Components.Vim.IAction.dispose;
/** @type Function */
Components.Vim.IAction.handler;
/** @type Function */
Components.Vim.IAction.getMessage;

View File

@ -0,0 +1,42 @@
/** @constructor */
Components.Vim.LineBuffer = function(){};
/** @type {Components.Vim.LineBuffer} */
Components.Vim.LineBuffer.next;
/** @type {Components.Vim.LineBuffer} */
Components.Vim.LineBuffer.prev;
/** @type {Components.Vim.LineBuffer} */
Components.Vim.LineBuffer.nextLine;
/** @type EventDispatcher */
Components.Vim.LineBuffer.dispatcher;
/** @type Function */
Components.Vim.LineBuffer.softReset;
/** @type Function */
Components.Vim.LineBuffer.pan;
/** @type Function */
Components.Vim.LineBuffer.render;
/** @type Function */
Components.Vim.LineBuffer.setRender;
/** @type Function */
Components.Vim.LineBuffer.init;
/** @type Function */
Components.Vim.LineBuffer.setWrap;
/** @type Array */
Components.Vim.LineBuffer.visualLines;
/** @type Boolean */
Components.Vim.LineBuffer.placeholder;
/** @type Boolean */
Components.Vim.LineBuffer.br;
/** @type Number */
Components.Vim.LineBuffer.cols;
/** @type Number */
Components.Vim.LineBuffer.lineNum;
/** @type Number */
Components.Vim.LineBuffer.tabWidth;
/** @type Number */
Components.Vim.LineBuffer.linesOccupied;
/** @type String */
Components.Vim.LineBuffer.content;

View File

@ -0,0 +1,46 @@
/** @constructor */
Components.Vim.LineFeeder = function(){};
/** @type {Components.Vim.Cursor} */
Components.Vim.LineFeeder.cursor;
/** @type {Components.Vim.LineBuffer} */
Components.Vim.LineFeeder.firstBuffer;
/** @type {Components.Vim.LineBuffer} */
Components.Vim.LineFeeder.lastBuffer;
/** @type EventDispatcher */
Components.Vim.LineFeeder.dispatcher;
/** @type Function */
Components.Vim.LineFeeder.softReset;
/** @type Function */
Components.Vim.LineFeeder.pan;
/** @type Function */
Components.Vim.LineFeeder.render;
/** @type Function */
Components.Vim.LineFeeder.setRender;
/** @type Function */
Components.Vim.LineFeeder.init;
/** @type Function */
Components.Vim.LineFeeder.setWrap;
/** @type {Array} */
Components.Vim.LineFeeder.lineBuffers;
/** @type Boolean */
Components.Vim.LineFeeder.EOF;
/** @type Boolean */
Components.Vim.LineFeeder.wrap;
/** @type Number */
Components.Vim.LineFeeder.panX;
/** @type Number */
Components.Vim.LineFeeder.panY;
/** @type Number */
Components.Vim.LineFeeder.moreAt;
/** @type Number */
Components.Vim.LineFeeder.linesOccupied;
/** @type String */
Components.Vim.LineFeeder.docPos;
/** @type String */
Components.Vim.LineFeeder.lineStat;
/** @type {String} */
Components.Vim.LineFeeder.content;

View File

@ -0,0 +1,7 @@
/** @constructor */
Components.Vim.StatusBar = function(){};
/** @type Function */
Components.Vim.StatusBar.stamp;
/** @type String */
Components.Vim.StatusBar.statusText;

View File

@ -0,0 +1,14 @@
/** @constructor */
Components.Vim.VimArea = function(){};
/** @type {Components.Vim.LineFeeder} */
Components.Vim.VimArea.contentFeeder;
/** @type {Components.Vim.LineFeeder} */
Components.Vim.VimArea.statusFeeder;
/** @type {Components.Vim.StatusBar} */
Components.Vim.VimArea.statusBar;
/** @type {Number} */
Components.Vim.VimArea.rows;
/** @type {Number} */
Components.Vim.VimArea.cols;

View File

@ -0,0 +1,2 @@
/** @object */
Components.Vim = {};