JOIN_LINES for single action

This commit is contained in:
斟酌 鵬兄 2016-04-03 09:24:14 +08:00
parent 593462f1e5
commit 2b3eb9db31
2 changed files with 90 additions and 0 deletions

View File

@ -0,0 +1,89 @@
(function(){
var ns = __namespace( "Components.Vim.Actions" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
/** @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 beep = __import( "Components.Vim.Beep" );
var Mesg = __import( "Components.Vim.Message" );
var occurance = __import( "System.utils.Perf.CountSubstr" );
/** @type {Components.Vim.IAction} */
var JOIN_LINES = function( Cursor )
{
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
this.__msg = "";
Cursor.suppressEvent();
};
JOIN_LINES.prototype.dispose = function()
{
this.__cursor.unsuppressEvent();
};
JOIN_LINES.prototype.handler = function( e, range )
{
e.preventDefault();
var cur = this.__cursor;
var feeder = cur.feeder;
var start;
var end;
var stack;
var stator;
var contentUndo;
if( range )
{
start = range.start;
end = range.close;
}
else
{
var oPos = cur.aPos;
cur.lineEnd( true );
stator = new Stator( cur );
start = cur.aPos;
cur.moveY( 1 );
cur.lineStart();
end = cur.aPos;
// This happens on the last line
if( end < start )
{
cur.moveTo( oPos );
beep();
return true;
}
var content = feeder.content;
contentUndo = feeder.content.substring( start, end );
feeder.content = content.substring( 0, start ) + " " + content.substr( end );
}
feeder.pan();
cur.moveTo( start );
var stack = new Stack();
stack.store( stator.save( 1, contentUndo ) );
cur.rec.record( stack );
};
JOIN_LINES.prototype.getMessage = function()
{
return this.__msg;
};
ns[ NS_EXPORT ]( EX_CLASS, "JOIN_LINES", JOIN_LINES );
})();

View File

@ -262,6 +262,7 @@
case SHIFT + I: // Append before the line start, after spaces
break;
case SHIFT + J: // Join lines
ccur.openRunAction( "JOIN_LINES", e );
break;
case SHIFT + K: // Find the manual entry
break;