Various bug fixes, rename InputEvent to ActionEvent

This commit is contained in:
斟酌 鵬兄 2016-04-07 23:11:23 +08:00
parent 397239705c
commit 6f7a1cc92c
7 changed files with 122 additions and 48 deletions

View File

@ -128,6 +128,8 @@
LoopGuard = r.index; LoopGuard = r.index;
} }
this.__msg = PATTERN.join( "" )
if( e.kMap( "N" ) ) if( e.kMap( "N" ) )
{ {
Hit = PrevStack[ PrevStack.length - 2 ]; Hit = PrevStack[ PrevStack.length - 2 ];
@ -144,10 +146,6 @@
Hit = FirstHit; Hit = FirstHit;
this.__msg = Mesg( "SEARCH_HIT_BOTTOM" ); this.__msg = Mesg( "SEARCH_HIT_BOTTOM" );
} }
else
{
this.__msg = PATTERN.join( "" )
}
if( Hit == undefined ) if( Hit == undefined )
{ {

View File

@ -37,7 +37,7 @@
var msg = ":register"; var msg = ":register";
msg += "\n" + Mesg( "REGISTERS" ); msg += "\n" + Mesg( "REGISTERS" );
var regs = "\"0123456789-.:%/="; var regs = "\"0123456789abcdefghijklmnopqrstuvwxyz-.:%/=";
for( var i = 0, j = regs[ i ]; j != undefined; i ++, j = regs[ i ] ) for( var i = 0, j = regs[ i ]; j != undefined; i ++, j = regs[ i ] )
{ {
var r = reg.get( j ); var r = reg.get( j );

View File

@ -47,6 +47,8 @@
var COMMA = 188; var FULLSTOP = 190; var COMMA = 188; var FULLSTOP = 190;
var SLASH = 191; var BACK_SLASH = 220; var SLASH = 191; var BACK_SLASH = 220;
var QUOTE = 222;
var ANY_KEY = -1; var ANY_KEY = -1;
var __maps = {}; var __maps = {};
@ -177,9 +179,8 @@
{ {
if( compReg.i == keys.length ) if( compReg.i == keys.length )
{ {
compReg.handler( e );
this.__compositeReg = null; this.__compositeReg = null;
this.__cMovement = false; compReg.handler( e );
} }
return true; return true;
@ -188,7 +189,6 @@
if( this.__compositeReg ) beep(); if( this.__compositeReg ) beep();
this.__compositeReg = null; this.__compositeReg = null;
this.__cMovement = false;
return false; return false;
}; };
@ -219,13 +219,13 @@
case SHIFT + O: // new line before insert case SHIFT + O: // new line before insert
ccur.lineStart(); ccur.lineStart();
ccur.openAction( "INSERT" ); ccur.openAction( "INSERT" );
ccur.action.handler( new InputEvent( e.sender, "Enter" ) ); ccur.action.handler( new ActionEvent( e.sender, "Enter" ) );
ccur.moveY( -1 ); ccur.moveY( -1 );
break; break;
case O: // new line insert case O: // new line insert
ccur.lineEnd( true ); ccur.lineEnd( true );
ccur.openAction( "INSERT" ); ccur.openAction( "INSERT" );
ccur.action.handler( new InputEvent( e.sender, "Enter" ) ); ccur.action.handler( new ActionEvent( e.sender, "Enter" ) );
break; break;
case U: // Undo case U: // Undo
@ -320,6 +320,60 @@
return false; return false;
}; };
Controls.prototype.__modCommand = function( e )
{
var catchCommand = false;
if( this.__mod )
{
e.preventDefault();
this.__composite( e );
return catchCommand;
}
var _self = this;
var mod = true;
var cur = this.__cursor;
switch( e.keyCode )
{
case SHIFT + QUOTE:
this.__composite( e, function( e2 ) {
e2.target.registers.select( e2.key );
_self.__mod = false;
}, ANY_KEY );
break;
case _0: case _1: case _2: case _3: case _4:
case _5: case _6: case _7: case _8: case _9:
var Count = e.key;
var recurNum = function( e2 ) {
switch( e2.keyCode )
{
case _0: case _1: case _2:
case _3: case _4: case _5:
case _6: case _7: case _8: case _9:
Count += e2.key;
_self.__composite( e2, recurNum, ANY_KEY );
return;
}
debug.Info( "Count is: " + Count );
catchCommand = true;
_self.__mod = false;
};
this.__composite( e, recurNum, ANY_KEY );
break;
default:
mod = false;
}
this.__mod = mod;
if( mod ) e.preventDefault();
return mod;
};
Controls.prototype.__cursorCommand = function( e ) Controls.prototype.__cursorCommand = function( e )
{ {
var kCode = e.keyCode; var kCode = e.keyCode;
@ -329,6 +383,7 @@
if( !e.ModKeys ) if( !e.ModKeys )
{ {
this.__composite( e ); this.__composite( e );
this.__cMovement = false;
return true; return true;
} }
} }
@ -520,7 +575,7 @@
/** /**
* sender @param {Components.Vim.VimArea} * sender @param {Components.Vim.VimArea}
* e @param {Components.Vim.Controls.InputEvent} * e @param {Components.Vim.Controls.ActionEvent}
* */ * */
Controls.prototype.handler = function( sender, e ) Controls.prototype.handler = function( sender, e )
{ {
@ -567,6 +622,8 @@
if( e.canceled ) return; if( e.canceled ) return;
} }
if( this.__modCommand( e ) ) return;
var cfeeder = this.__cfeeder; var cfeeder = this.__cfeeder;
var ccur = this.__ccur; var ccur = this.__ccur;
@ -607,7 +664,7 @@
if( this.__actionCommand( e ) ) return; if( this.__actionCommand( e ) ) return;
}; };
var InputEvent = function( sender, e ) var ActionEvent = function( sender, e )
{ {
this.__target = sender; this.__target = sender;
this.__canceled = false; this.__canceled = false;
@ -641,19 +698,20 @@
this.__key = e.key; this.__key = e.key;
} }
this.__count = 1;
this.__range = null; this.__range = null;
}; };
InputEvent.prototype.cancel = function() { this.__canceled = true; }; ActionEvent.prototype.cancel = function() { this.__canceled = true; };
__readOnly( InputEvent.prototype, "target", function() { return this.__target; } ); __readOnly( ActionEvent.prototype, "target", function() { return this.__target; } );
__readOnly( InputEvent.prototype, "key", function() { return this.__key; } ); __readOnly( ActionEvent.prototype, "key", function() { return this.__key; } );
__readOnly( InputEvent.prototype, "keyCode", function() { return this.__kCode; } ); __readOnly( ActionEvent.prototype, "keyCode", function() { return this.__kCode; } );
__readOnly( InputEvent.prototype, "ModKeys", function() { return this.__modKeys; } ); __readOnly( ActionEvent.prototype, "ModKeys", function() { return this.__modKeys; } );
__readOnly( InputEvent.prototype, "Escape", function() { return this.__escape; } ); __readOnly( ActionEvent.prototype, "Escape", function() { return this.__escape; } );
__readOnly( InputEvent.prototype, "canceled", function() { return this.__canceled; } ); __readOnly( ActionEvent.prototype, "canceled", function() { return this.__canceled; } );
__readOnly( InputEvent.prototype, "range", function() { __readOnly( ActionEvent.prototype, "range", function() {
/** @type {Components.Vim.Syntax.TokenMatch} */ /** @type {Components.Vim.Syntax.TokenMatch} */
var r = this.__range; var r = this.__range;
@ -666,16 +724,20 @@
return r; return r;
} ); } );
InputEvent.prototype.kMap = function( map ) __readOnly( ActionEvent.prototype, "count", function() {
return this.__count;
} );
ActionEvent.prototype.kMap = function( map )
{ {
return this.__kCode == Map( map ); return this.__kCode == Map( map );
}; };
InputEvent.prototype.preventDefault = function() ActionEvent.prototype.preventDefault = function()
{ {
if( this.__e ) this.__e.preventDefault(); if( this.__e ) this.__e.preventDefault();
}; };
ns[ NS_EXPORT ]( EX_CLASS, "Controls", Controls ); ns[ NS_EXPORT ]( EX_CLASS, "Controls", Controls );
ns[ NS_EXPORT ]( EX_CLASS, "InputEvent", InputEvent ); ns[ NS_EXPORT ]( EX_CLASS, "ActionEvent", ActionEvent );
})(); })();

View File

@ -15,6 +15,9 @@
*/ */
var ns = __namespace( "Components.Vim.State" ); var ns = __namespace( "Components.Vim.State" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
var Register = function( str, n ) var Register = function( str, n )
{ {
this.__str = str + ""; this.__str = str + "";
@ -43,7 +46,8 @@
{ {
var reg = new Register( str, newLine ); var reg = new Register( str, newLine );
this.__unnamed( reg ); this.__unnamed( reg );
this.__registers[ 0 ] = reg; this.__registers[ this.__selRegister || 0 ] = reg;
this.__selRegister = false;
}; };
Registers.prototype.change = function( str, newLine ) Registers.prototype.change = function( str, newLine )
@ -60,16 +64,24 @@
} }
r[ 1 ] = reg; r[ 1 ] = reg;
this.__selRegister = false;
}; };
Registers.prototype.get = function( r ) Registers.prototype.get = function( r )
{ {
// 0 is one of the registers // 0 is one of the registers
if( !r && r !== 0 ) r = "\""; if( !r && r !== 0 ) r = this.__selRegister || "\"";
this.__selRegister = false;
return this.__registers[ r ]; return this.__registers[ r ];
}; };
Registers.prototype.select = function( r )
{
debug.Info( "Selecting Register: " + r );
this.__selRegister = r;
};
ns[ NS_EXPORT ]( EX_CLASS, "Registers", Registers ); ns[ NS_EXPORT ]( EX_CLASS, "Registers", Registers );
})(); })();

View File

@ -23,7 +23,7 @@
var StatusBar = ns[ NS_INVOKE ]( "StatusBar" ); var StatusBar = ns[ NS_INVOKE ]( "StatusBar" );
var VimControls = ns[ NS_INVOKE ]( "Controls" ); var VimControls = ns[ NS_INVOKE ]( "Controls" );
var InputEvent = ns[ NS_INVOKE ]( "InputEvent" ); var ActionEvent = ns[ NS_INVOKE ]( "ActionEvent" );
var mesg = ns[ NS_INVOKE ]( "Message" ); var mesg = ns[ NS_INVOKE ]( "Message" );
var Insts = []; var Insts = [];
@ -38,7 +38,7 @@
if ( e.keyCode ) code = e.keyCode; if ( e.keyCode ) code = e.keyCode;
else if ( e.which ) code = e.which; else if ( e.which ) code = e.which;
handler( sender, new InputEvent( sender, e ) ); handler( sender, new ActionEvent( sender, e ) );
}; };
}; };

View File

@ -0,0 +1,23 @@
/** @constructor */
Components.Vim.Controls.ActionEvent = function(){};
/** @type {Components.Vim.VimArea} */
Components.Vim.Controls.ActionEvent.target;
/** @type {Components.Vim.Syntax.TokenMatch} */
Components.Vim.Controls.ActionEvent.range;
/** @type {Components.Vim.Syntax.Number} */
Components.Vim.Controls.ActionEvent.count;
/** @type String */
Components.Vim.Controls.ActionEvent.key;
/** @type Boolean */
Components.Vim.Controls.ActionEvent.ModKeys;
/** @type Boolean */
Components.Vim.Controls.ActionEvent.Escape;
/** @type Boolean */
Components.Vim.Controls.ActionEvent.canceled;
/** @type Number */
Components.Vim.Controls.ActionEvent.keyCode;
/** @type Function */
Components.Vim.Controls.ActionEvent.kMap;
/** @type Function */
Components.Vim.Controls.ActionEvent.cancel;

View File

@ -1,21 +0,0 @@
/** @constructor */
Components.Vim.Controls.InputEvent = function(){};
/** @type {Components.Vim.VimArea} */
Components.Vim.Controls.InputEvent.target;
/** @type {Components.Vim.Syntax.TokenMatch} */
Components.Vim.Controls.InputEvent.range;
/** @type String */
Components.Vim.Controls.InputEvent.key;
/** @type Boolean */
Components.Vim.Controls.InputEvent.ModKeys;
/** @type Boolean */
Components.Vim.Controls.InputEvent.Escape;
/** @type Boolean */
Components.Vim.Controls.InputEvent.canceled;
/** @type Number */
Components.Vim.Controls.InputEvent.keyCode;
/** @type Function */
Components.Vim.Controls.InputEvent.kMap;
/** @type Function */
Components.Vim.Controls.InputEvent.cancel;