forked from Botanical/BotanJS
Various basic editor commands
This commit is contained in:
78
botanjs/src/Components/Vim/Actions/BUFFERS.js
Normal file
78
botanjs/src/Components/Vim/Actions/BUFFERS.js
Normal 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 );
|
||||
})();
|
@@ -66,7 +66,6 @@
|
||||
case "buffers":
|
||||
case "ls":
|
||||
out[ CMD_TYPE ] = "BUFFERS";
|
||||
|
||||
break;
|
||||
case "w":
|
||||
case "write":
|
||||
|
60
botanjs/src/Components/Vim/Actions/QUIT.js
Normal file
60
botanjs/src/Components/Vim/Actions/QUIT.js
Normal 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 );
|
||||
})();
|
64
botanjs/src/Components/Vim/Actions/REGISTERS.js
Normal file
64
botanjs/src/Components/Vim/Actions/REGISTERS.js
Normal 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 );
|
||||
})();
|
58
botanjs/src/Components/Vim/Actions/VERSION.js
Normal file
58
botanjs/src/Components/Vim/Actions/VERSION.js
Normal 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 );
|
||||
})();
|
49
botanjs/src/Components/Vim/Actions/WRITE.js
Normal file
49
botanjs/src/Components/Vim/Actions/WRITE.js
Normal 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 );
|
||||
})();
|
Reference in New Issue
Block a user