forked from Botanical/BotanJS
JOIN_LINES for single action
This commit is contained in:
parent
593462f1e5
commit
2b3eb9db31
89
botanjs/src/Components/Vim/Actions/JOIN_LINES.js
Normal file
89
botanjs/src/Components/Vim/Actions/JOIN_LINES.js
Normal 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 );
|
||||
})();
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user