Added b & w

This commit is contained in:
斟酌 鵬兄 2016-04-03 20:55:36 +08:00
parent 3d2f3b889a
commit fbb4bae316
3 changed files with 90 additions and 1 deletions

View File

@ -0,0 +1,74 @@
(function(){
var ns = __namespace( "Components.Vim.Actions" );
/** @type {System.Debug} */
var debug = __import( "System.Debug" );
/** @type {Components.Vim.IAction} */
var WORD = function( Cursor )
{
/** @type {Components.Vim.Cursor} */
this.__cursor = Cursor;
this.__msg = "<WORD COMMAND>";
Cursor.suppressEvent();
};
WORD.prototype.dispose = function()
{
this.__cursor.unsuppressEvent();
};
WORD.prototype.handler = function( e )
{
e.preventDefault();
var cur = this.__cursor;
var feeder = cur.feeder;
var analyzer = cur.Vim.contentAnalyzer;
var p = cur.aPos;
var d = 1;
// forward
if( e.kMap( "w" ) || e.kMap( "W" ) )
{
if( feeder.content[ p + 1 ] == "\n" )
{
p ++;
}
var wordRange = analyzer.wordAt( p );
if( wordRange.open != -1 )
{
p = wordRange.close + 1;
}
}
// Backward
if( e.kMap( "b" ) || e.kMap( "B" ) )
{
if( p == 0 ) return;
d = -1;
var wordRange = analyzer.wordAt( p - 1 );
if( wordRange.open != -1 )
{
p = wordRange.open;
}
}
while( " \t".indexOf( feeder.content[ p ] ) != -1 )
{
p += d;
}
cur.moveTo( p );
};
WORD.prototype.getMessage = function()
{
return this.__msg;
};
ns[ NS_EXPORT ]( EX_CLASS, "WORD", WORD );
})();

View File

@ -378,7 +378,11 @@
break; break;
case SHIFT + L: // Last line buffer case SHIFT + L: // Last line buffer
break; break;
case SHIFT + _6: // ^, Start
case _0: // Really - line Start
ccur.lineStart();
break;
case SHIFT + _6: // ^, line Start, XXX: skip tabs
ccur.lineStart(); ccur.lineStart();
break; break;
case SHIFT + _4: // $, End case SHIFT + _4: // $, End
@ -439,6 +443,13 @@
break; break;
case W: // word
case SHIFT + W:
case B:
case SHIFT + B:
ccur.openRunAction( "WORD", e );
break
case I: // In between boundary case I: // In between boundary
if( !ccur.action ) if( !ccur.action )

View File

@ -199,6 +199,10 @@
// C1 Controls and Latin-1 Supplement (Extended ASCII) // C1 Controls and Latin-1 Supplement (Extended ASCII)
[ 0x00A1, 0x00AC ], [ 0x00AE, 0x00BF ] [ 0x00A1, 0x00AC ], [ 0x00AE, 0x00BF ]
] ]
,
[ // Spaces & tabs
[ 0x0020, 0x0020 ], [ 0x0009, 0x0009 ]
]
]; ];
var NUM_KINGDOM = KINGDOMS.length; var NUM_KINGDOM = KINGDOMS.length;