Various basic editor commands

This commit is contained in:
2016-04-03 07:50:19 +08:00
parent f4dc0e7d9c
commit be1fc29d39
12 changed files with 394 additions and 22 deletions

View File

@@ -0,0 +1,78 @@
(function(){
var ns = __namespace( "Components.Vim.Actions" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
/** @type {Dandelion} */
var Dand = __import( "Dandelion" );
var Mesg = __import( "Components.Vim.Message" );
var occurance = __import( "System.utils.Perf.CountSubstr" );
var shadowImport = __import;
var ESCAPE = function( reg )
{
var str = reg.toString();
return str.replace( "\t", "^I" ).replace( "\n", "^J" );
};
/** @type {Components.Vim.IAction} */
var BUFFERS = function( Cursor )
{
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
this.__msg = "";
Cursor.suppressEvent();
};
BUFFERS.prototype.dispose = function()
{
this.__cursor.unsuppressEvent();
};
BUFFERS.prototype.handler = function( e, p )
{
e.preventDefault();
var areas = Dand.tag( "textarea" );
var cur = this.__cursor;
var Vim = cur.Vim;
var Insts = VimArea.Instances;
var msg = ":buffers";
for( var i in Insts )
{
/** @type {Components.Vim.VimArea} */
var inst = Insts[ i ];
var b = inst.index + " ";
var icur = inst.contentFeeder.cursor;
b += ( inst == Vim ? "%a" : " " ) + " ";
b += ( icur.rec.changed ? "+" : " " ) + " ";
b += "\"" + inst.stage.element.id + "\"" + " line " + ( icur.getLine().lineNum + 1 );
msg += "\n " + b;
}
var lastLine = Mesg( "WAIT_FOR_INPUT" );
var l = this.__cursor.feeder.firstBuffer.cols;
for( var i = msg.length; i < l; i ++ ) msg += " ";
this.__msg = msg + "\n" + lastLine;
};
BUFFERS.prototype.getMessage = function()
{
return this.__msg;
};
ns[ NS_EXPORT ]( EX_CLASS, "BUFFERS", BUFFERS );
})();

View File

@@ -66,7 +66,6 @@
case "buffers":
case "ls":
out[ CMD_TYPE ] = "BUFFERS";
break;
case "w":
case "write":

View File

@@ -0,0 +1,60 @@
(function(){
var ns = __namespace( "Components.Vim.Actions" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var VimError = __import( "Components.Vim.Error" );
var occurance = __import( "System.utils.Perf.CountSubstr" );
var ESCAPE = function( reg )
{
var str = reg.toString();
return str.replace( "\t", "^I" ).replace( "\n", "^J" );
};
/** @type {Components.Vim.IAction} */
var QUIT = function( Cursor )
{
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
this.__msg = "";
Cursor.suppressEvent();
};
QUIT.prototype.dispose = function()
{
this.__cursor.unsuppressEvent();
};
QUIT.prototype.handler = function( e, p )
{
e.preventDefault();
var cur = this.__cursor;
var Vim = cur.Vim;
if( cur.rec.changed )
{
var msg = VimError( "E37" );
var l = this.__cursor.feeder.firstBuffer.cols;
for( var i = msg.length; i < l; i ++ ) msg += " ";
this.__msg = msg;
}
else
{
Vim.dispose();
return true;
}
};
QUIT.prototype.getMessage = function()
{
return this.__msg;
};
ns[ NS_EXPORT ]( EX_CLASS, "QUIT", QUIT );
})();

View File

@@ -0,0 +1,64 @@
(function(){
var ns = __namespace( "Components.Vim.Actions" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var VimError = __import( "Components.Vim.Error" );
var Mesg = __import( "Components.Vim.Message" );
var ESCAPE = function( reg )
{
var str = reg.toString();
return str.replace( "\t", "^I" ).replace( "\n", "^J" );
};
/** @type {Components.Vim.IAction} */
var REGISTERS = function( Cursor )
{
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
this.__msg = "";
Cursor.suppressEvent();
};
REGISTERS.prototype.dispose = function()
{
this.__cursor.unsuppressEvent();
};
REGISTERS.prototype.handler = function( e, p )
{
e.preventDefault();
/** @type {Components.Vim.State.Registers} */
var reg = e.target.registers;
var msg = ":register";
msg += "\n" + Mesg( "REGISTERS" );
var regs = "\"0123456789-.:%/=";
for( var i = 0, j = regs[ i ]; j != undefined; i ++, j = regs[ i ] )
{
var r = reg.get( j );
if( r )
{
msg += "\n\"" + j + " " + ESCAPE( r );
}
}
var lastLine = Mesg( "WAIT_FOR_INPUT" );
var l = this.__cursor.feeder.firstBuffer.cols;
for( var i = msg.length; i < l; i ++ ) msg += " ";
this.__msg = msg + "\n" + lastLine;
};
REGISTERS.prototype.getMessage = function()
{
return this.__msg;
};
ns[ NS_EXPORT ]( EX_CLASS, "REGISTERS", REGISTERS );
})();

View File

@@ -0,0 +1,58 @@
(function(){
var ns = __namespace( "Components.Vim.Actions" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var VimError = __import( "Components.Vim.Error" );
var Mesg = __import( "Components.Vim.Message" );
var ESCAPE = function( reg )
{
var str = reg.toString();
return str.replace( "\t", "^I" ).replace( "\n", "^J" );
};
/** @type {Components.Vim.IAction} */
var VERSION = function( Cursor )
{
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
this.__msg = "";
Cursor.suppressEvent();
};
VERSION.prototype.dispose = function()
{
this.__cursor.unsuppressEvent();
};
VERSION.prototype.handler = function( e, p )
{
e.preventDefault();
/** @type {Components.Vim.State.Registers} */
var reg = e.target.registers;
var msg = ":version";
msg += "\nVim;Re - Vim; Reverse Engineered for textarea v" + VIMRE_VERSION;
msg += "\n + BotanJS - v" + BOTANJS_VERSION;
msg += "\nProject home - https://github.com/tgckpg/BotanJS-vim";
msg += "\n by \u659F\u914C\u9D6C\u5144 (penguin) - https://blog.astropenguin.net/";
msg += "\n";
var lastLine = Mesg( "WAIT_FOR_INPUT" );
var l = this.__cursor.feeder.firstBuffer.cols;
for( var i = msg.length; i < l; i ++ ) msg += " ";
this.__msg = msg + "\n" + lastLine;
};
VERSION.prototype.getMessage = function()
{
return this.__msg;
};
ns[ NS_EXPORT ]( EX_CLASS, "VERSION", VERSION );
})();

View File

@@ -0,0 +1,49 @@
(function(){
var ns = __namespace( "Components.Vim.Actions" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var Mesg = __import( "Components.Vim.Message" );
var occurance = __import( "System.utils.Perf.CountSubstr" );
/** @type {Components.Vim.IAction} */
var WRITE = function( Cursor )
{
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
this.__msg = "";
Cursor.suppressEvent();
};
WRITE.prototype.dispose = function()
{
this.__cursor.unsuppressEvent();
};
WRITE.prototype.handler = function( e, p )
{
e.preventDefault();
var cur = this.__cursor;
var Vim = cur.Vim;
Vim.content = cur.feeder.content.slice( 0, -1 );
var msg = Mesg( "WRITE", Vim.stage.element.id, occurance( Vim.content, "\n" ), Vim.content.length );
cur.rec.save();
var l = this.__cursor.feeder.firstBuffer.cols;
for( var i = msg.length; i < l; i ++ ) msg += " ";
this.__msg = msg;
};
WRITE.prototype.getMessage = function()
{
return this.__msg;
};
ns[ NS_EXPORT ]( EX_CLASS, "WRITE", WRITE );
})();