forked from Botanical/BotanJS
Fix wrong position of lines with tab character
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
(function(){
|
||||
var ns = __namespace( "Components.Vim.Actions" );
|
||||
|
||||
/** @type {System.Debug} */
|
||||
var debug = __import( "System.Debug" );
|
||||
var Mesg = __import( "Components.Vim.Message" );
|
||||
|
||||
/** @type {Components.Vim.State.Stack} */
|
||||
var Stack = __import( "Components.Vim.State.Stack" );
|
||||
|
||||
var Translate = function( c )
|
||||
{
|
||||
switch( c )
|
||||
@@ -16,15 +17,75 @@
|
||||
}
|
||||
};
|
||||
|
||||
/* @param {Components.Vim.LineFeeder} */
|
||||
var ContentPosition = function( f )
|
||||
{
|
||||
var line = f.cursor.getLine();
|
||||
var n = line.lineNum;
|
||||
|
||||
var p = 0;
|
||||
if( 0 < n )
|
||||
{
|
||||
p = f.content.indexOf( "\n" );
|
||||
for( i = 1; p != -1 && i < n; i ++ )
|
||||
{
|
||||
p = f.content.indexOf( "\n", p + 1 );
|
||||
}
|
||||
|
||||
if( f.wrap )
|
||||
{
|
||||
// wordwrap offset
|
||||
p ++;
|
||||
}
|
||||
}
|
||||
|
||||
p += f.cursor.aX;
|
||||
return p;
|
||||
};
|
||||
|
||||
/** @type {Components.Vim.Cursor.IAction} */
|
||||
var INSERT = function( Cursor )
|
||||
{
|
||||
/** @type {Components.Vim.Cursor} */
|
||||
this.cursor = Cursor;
|
||||
this.__cursor = Cursor;
|
||||
|
||||
// Initialize this stack
|
||||
this.__rec( "", true );
|
||||
};
|
||||
|
||||
INSERT.prototype.dispose = function()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
INSERT.prototype.__storeState = function( c, pos )
|
||||
{
|
||||
return function() {
|
||||
debug.Inf( pos, c );
|
||||
};
|
||||
};
|
||||
|
||||
INSERT.prototype.__rec = function( c, newRec )
|
||||
{
|
||||
if( newRec || !this.__stack )
|
||||
{
|
||||
if( this.__stack )
|
||||
{
|
||||
var c = this.__content;
|
||||
|
||||
this.__stack.store(
|
||||
this.__storeState( c, this.__startPosition )
|
||||
);
|
||||
|
||||
this.__cursor.rec.store( this.__stack );
|
||||
}
|
||||
|
||||
this.__content = "";
|
||||
this.__stack = new Stack();
|
||||
this.__startPosition = ContentPosition( this.__cursor.feeder );
|
||||
}
|
||||
|
||||
this.__content += c;
|
||||
};
|
||||
|
||||
INSERT.prototype.handler = function( e )
|
||||
@@ -34,42 +95,27 @@
|
||||
|
||||
if( inputChar.length != 1 ) return;
|
||||
|
||||
var cur = this.cursor;
|
||||
var cur = this.__cursor;
|
||||
var feeder = cur.feeder;
|
||||
|
||||
var line = cur.getLine();
|
||||
var n = line.lineNum;
|
||||
var f = ContentPosition( feeder );
|
||||
|
||||
var cont = feeder.content;
|
||||
feeder.content =
|
||||
feeder.content.substring( 0, f )
|
||||
+ inputChar
|
||||
+ feeder.content.substring( f );
|
||||
|
||||
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" ) );
|
||||
|
||||
this.__rec( inputChar );
|
||||
|
||||
cur.moveX( 1 );
|
||||
};
|
||||
|
||||
INSERT.prototype.getMessage = function()
|
||||
{
|
||||
var l = this.cursor.feeder.firstBuffer.cols;
|
||||
var l = this.__cursor.feeder.firstBuffer.cols;
|
||||
var msg = Mesg( "INSERT" );
|
||||
|
||||
for( var i = msg.length; i < l; i ++ ) msg += " ";
|
||||
|
41
botanjs/src/Components/Vim/Actions/UNDO.js
Normal file
41
botanjs/src/Components/Vim/Actions/UNDO.js
Normal file
@@ -0,0 +1,41 @@
|
||||
(function(){
|
||||
var ns = __namespace( "Components.Vim.Actions" );
|
||||
|
||||
var Mesg = __import( "Components.Vim.Message" );
|
||||
|
||||
/** @type {Components.Vim.Cursor.IAction} */
|
||||
var UNDO = function( Cursor )
|
||||
{
|
||||
/** @type {Components.Vim.Cursor} */
|
||||
this.__cursor = Cursor;
|
||||
this.__message = "UNDO COMMAND";
|
||||
};
|
||||
|
||||
UNDO.prototype.dispose = function()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
UNDO.prototype.handler = function( e )
|
||||
{
|
||||
e.preventDefault();
|
||||
|
||||
/** @type {Components.Vim.State.Stack} */
|
||||
var stack = this.__cursor.rec.undo();
|
||||
if( stack )
|
||||
{
|
||||
stack.play();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.__message = Mesg( "UNDO_LIMIT" );
|
||||
}
|
||||
};
|
||||
|
||||
UNDO.prototype.getMessage = function()
|
||||
{
|
||||
return this.__message;
|
||||
};
|
||||
|
||||
ns[ NS_EXPORT ]( EX_CLASS, "UNDO", UNDO );
|
||||
})();
|
Reference in New Issue
Block a user