forked from Botanical/BotanJS
Quote in between & PUT impl
This commit is contained in:
parent
664b0f2ec1
commit
a6ccf7e4db
@ -8,7 +8,7 @@ Visit the demo over [here](https://tgckpg.github.io/VimArea)
|
|||||||
Common commands are now supported. I am now going to list the commands that yet to be made.
|
Common commands are now supported. I am now going to list the commands that yet to be made.
|
||||||
```
|
```
|
||||||
Commands that are going to implement soon:
|
Commands that are going to implement soon:
|
||||||
auto indent ( new line from bracket ), [action]i[quote]
|
auto indent ( new line from bracket )
|
||||||
:'<,'>
|
:'<,'>
|
||||||
|
|
||||||
Commands that are planning to implement in near future:
|
Commands that are planning to implement in near future:
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
this.__cursor.unsuppressEvent();
|
this.__cursor.unsuppressEvent();
|
||||||
};
|
};
|
||||||
|
|
||||||
PUT.prototype.handler = function( e )
|
PUT.prototype.handler = function( e, sp, newLine )
|
||||||
{
|
{
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
@ -63,20 +63,32 @@
|
|||||||
|
|
||||||
var stator = new Stator( cur );
|
var stator = new Stator( cur );
|
||||||
var aP = cur.aPos;
|
var aP = cur.aPos;
|
||||||
|
var contentUndo = "";
|
||||||
|
|
||||||
feeder.content = feeder.content.substring( 0, aP )
|
if( sp == undefined )
|
||||||
+ cput
|
{
|
||||||
+ feeder.content.substring( aP );
|
feeder.content = feeder.content.substring( 0, aP )
|
||||||
|
+ cput + feeder.content.substring( aP );
|
||||||
|
|
||||||
feeder.pan();
|
feeder.pan();
|
||||||
|
cur.moveTo( 0 < nLines ? aP : aP + clen, true );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sp ++;
|
||||||
|
contentUndo = feeder.content.substring( aP, sp );
|
||||||
|
feeder.content = feeder.content.substring( 0, aP )
|
||||||
|
+ cput + feeder.content.substring( sp );
|
||||||
|
|
||||||
cur.moveTo( 0 < nLines ? aP : aP + clen, true );
|
feeder.pan();
|
||||||
|
cur.moveTo( aP + clen, true );
|
||||||
|
}
|
||||||
|
|
||||||
var stack = new Stack();
|
var stack = new Stack();
|
||||||
|
|
||||||
if( newLine )
|
if( newLine )
|
||||||
{
|
{
|
||||||
var f = stator.save( clen, "" );
|
var f = stator.save( clen, contentUndo );
|
||||||
stack.store( function()
|
stack.store( function()
|
||||||
{
|
{
|
||||||
f();
|
f();
|
||||||
@ -85,7 +97,7 @@
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stack.store( stator.save( clen, "" ) );
|
stack.store( stator.save( clen, contentUndo ) );
|
||||||
}
|
}
|
||||||
cur.rec.record( stack );
|
cur.rec.record( stack );
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
|
|
||||||
if( 0 < n ) p ++;
|
if( 0 < n ) p ++;
|
||||||
|
|
||||||
var lowerLimmit = p;
|
var lowerLimit = p;
|
||||||
|
|
||||||
var Char = et.key;
|
var Char = et.key;
|
||||||
if( et.kMap( "Tab" ) )
|
if( et.kMap( "Tab" ) )
|
||||||
@ -64,7 +64,7 @@
|
|||||||
tX = f.content.lastIndexOf( Char, cur.aPos - 1 );
|
tX = f.content.lastIndexOf( Char, cur.aPos - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( lowerLimmit <= tX && tX < upperLimit )
|
if( lowerLimit <= tX && tX < upperLimit )
|
||||||
{
|
{
|
||||||
cur.moveTo( tX );
|
cur.moveTo( tX );
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@
|
|||||||
var DELETE = ns[ NS_INVOKE ]( "DELETE" );
|
var DELETE = ns[ NS_INVOKE ]( "DELETE" );
|
||||||
/** @type {Components.Vim.IAction} */
|
/** @type {Components.Vim.IAction} */
|
||||||
var SHIFT_LINES = ns[ NS_INVOKE ]( "SHIFT_LINES" );
|
var SHIFT_LINES = ns[ NS_INVOKE ]( "SHIFT_LINES" );
|
||||||
|
/** @type {Components.Vim.IAction} */
|
||||||
|
var PUT = ns[ NS_INVOKE ]( "PUT" );
|
||||||
|
|
||||||
var MODE_NULL = -1;
|
var MODE_NULL = -1;
|
||||||
var MODE_VISUAL = 0;
|
var MODE_VISUAL = 0;
|
||||||
@ -121,6 +123,10 @@
|
|||||||
{
|
{
|
||||||
Action = new DELETE( cur );
|
Action = new DELETE( cur );
|
||||||
}
|
}
|
||||||
|
else if( e.kMap( "p" ) )
|
||||||
|
{
|
||||||
|
Action = new PUT( cur );
|
||||||
|
}
|
||||||
else if( e.kMap( "V" ) )
|
else if( e.kMap( "V" ) )
|
||||||
{
|
{
|
||||||
if( this.__mode == MODE_LINE ) return true;
|
if( this.__mode == MODE_LINE ) return true;
|
||||||
@ -180,7 +186,8 @@
|
|||||||
// this swap the cursor direction from LTR to RTL
|
// this swap the cursor direction from LTR to RTL
|
||||||
// i.e. treat all delete as "e<----s" flow
|
// i.e. treat all delete as "e<----s" flow
|
||||||
// to keep the cursor position as the top on UNDO / REDO
|
// to keep the cursor position as the top on UNDO / REDO
|
||||||
if( Action.constructor == DELETE && startLine.aPos < cur.aPos )
|
var IsContMod = ~[ DELETE, PUT ].indexOf( Action.constructor );
|
||||||
|
if( IsContMod && startLine.aPos < cur.aPos )
|
||||||
{
|
{
|
||||||
var o = cur.aPos;
|
var o = cur.aPos;
|
||||||
cur.moveTo( startLine.aPos, true );
|
cur.moveTo( startLine.aPos, true );
|
||||||
@ -189,7 +196,7 @@
|
|||||||
|
|
||||||
Action.handler( e, startLine.aPos, lineMode );
|
Action.handler( e, startLine.aPos, lineMode );
|
||||||
|
|
||||||
if( Action.constructor != DELETE )
|
if( !IsContMod )
|
||||||
{
|
{
|
||||||
cur.moveTo( startLine.aPos );
|
cur.moveTo( startLine.aPos );
|
||||||
}
|
}
|
||||||
|
@ -616,14 +616,26 @@
|
|||||||
var BracketMatch = analyzer.bracketIn( "[", ccur.aPos );
|
var BracketMatch = analyzer.bracketIn( "[", ccur.aPos );
|
||||||
e2.__range = BracketMatch;
|
e2.__range = BracketMatch;
|
||||||
};
|
};
|
||||||
|
var singleQuote = function( e2 ) {
|
||||||
|
var BracketMatch = analyzer.quoteIn( "'", ccur.aPos );
|
||||||
|
e2.__range = BracketMatch;
|
||||||
|
};
|
||||||
|
var doubleQuote = function( e2 ) {
|
||||||
|
var BracketMatch = analyzer.quoteIn( "\"", ccur.aPos );
|
||||||
|
e2.__range = BracketMatch;
|
||||||
|
};
|
||||||
|
|
||||||
// Bracket boundaries
|
// Bracket boundaries
|
||||||
this.__composite( e, bracket , SHIFT + _0 );
|
this.__composite( e, bracket, SHIFT + _0 );
|
||||||
this.__composite( e, bracket, SHIFT + _9 );
|
this.__composite( e, bracket, SHIFT + _9 );
|
||||||
this.__composite( e, squareBracket, S_BRACKET_L );
|
this.__composite( e, squareBracket, S_BRACKET_L );
|
||||||
this.__composite( e, squareBracket, S_BRACKET_R );
|
this.__composite( e, squareBracket, S_BRACKET_R );
|
||||||
this.__composite( e, curlyBracket, SHIFT + S_BRACKET_L );
|
this.__composite( e, curlyBracket, SHIFT + S_BRACKET_L );
|
||||||
this.__composite( e, curlyBracket, SHIFT + S_BRACKET_R );
|
this.__composite( e, curlyBracket, SHIFT + S_BRACKET_R );
|
||||||
|
|
||||||
|
// Quote boundaries
|
||||||
|
this.__composite( e, singleQuote, QUOTE );
|
||||||
|
this.__composite( e, doubleQuote, SHIFT + QUOTE );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case G:
|
case G:
|
||||||
@ -725,7 +737,7 @@
|
|||||||
var cfeeder = this.__cfeeder;
|
var cfeeder = this.__cfeeder;
|
||||||
var ccur = this.__ccur;
|
var ccur = this.__ccur;
|
||||||
|
|
||||||
if( !ccur.action || ccur.action.allowMovement )
|
if( !this.__cMovement && ( !ccur.action || ccur.action.allowMovement ) )
|
||||||
{
|
{
|
||||||
this.__modCommand( e );
|
this.__modCommand( e );
|
||||||
if( e.canceled ) return;
|
if( e.canceled ) return;
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
/** @type {System.Debug} */
|
/** @type {System.Debug} */
|
||||||
var debug = __import( "System.Debug" );
|
var debug = __import( "System.Debug" );
|
||||||
|
|
||||||
|
var beep = __import( "Components.Vim.Beep" );
|
||||||
|
|
||||||
/** @type {Components.Vim.Syntax.Word} */
|
/** @type {Components.Vim.Syntax.Word} */
|
||||||
var Word = ns[ NS_INVOKE ]( "Word" );
|
var Word = ns[ NS_INVOKE ]( "Word" );
|
||||||
|
|
||||||
@ -265,6 +267,73 @@
|
|||||||
return new TokenMatch();
|
return new TokenMatch();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Analyzer.prototype.quoteIn = function( Char )
|
||||||
|
{
|
||||||
|
var f = this.__feeder;
|
||||||
|
var cur = f.cursor;
|
||||||
|
var n = cur.getLine().lineNum;
|
||||||
|
|
||||||
|
var p = 0;
|
||||||
|
for( var i = 0; p != -1 && i < n; i ++ ) p = f.content.indexOf( "\n", p + 1 );
|
||||||
|
|
||||||
|
var upperLimit = f.content.indexOf( "\n", p + 1 );
|
||||||
|
|
||||||
|
if( 0 < n ) p ++;
|
||||||
|
|
||||||
|
var lowerLimit = p;
|
||||||
|
|
||||||
|
// Cursor is at the quote character
|
||||||
|
// Move cursor inside the matching quote
|
||||||
|
if( f.content[ cur.aPos ] == Char )
|
||||||
|
{
|
||||||
|
// Mark all quotes on current line
|
||||||
|
var quotePos = [];
|
||||||
|
var l = 0;
|
||||||
|
|
||||||
|
for( var i = lowerLimit; i < upperLimit; i ++ )
|
||||||
|
{
|
||||||
|
if( f.content[ i ] == Char )
|
||||||
|
quotePos[ l ++ ] = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
var indexQuote = quotePos.indexOf( cur.aPos );
|
||||||
|
var indexEnd = ( indexQuote == ( l - 1 ) );
|
||||||
|
|
||||||
|
// Length is even: Quotes are matched
|
||||||
|
// OR
|
||||||
|
// Length is odd and cursor is not at the last quote
|
||||||
|
if( l % 2 == 0 || !indexEnd )
|
||||||
|
{
|
||||||
|
cur.moveX( indexQuote % 2 == 0 ? 1 : -1 );
|
||||||
|
}
|
||||||
|
// Cursor is at the last quote
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Beep because last quote of odd length is an unmatch quote
|
||||||
|
beep();
|
||||||
|
return new TokenMatch();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Forward
|
||||||
|
var fX = f.content.indexOf( Char, cur.aPos + 1 );
|
||||||
|
// backward
|
||||||
|
var bX = f.content.lastIndexOf( Char, cur.aPos - 1 );
|
||||||
|
|
||||||
|
if( lowerLimit <= bX && fX < upperLimit )
|
||||||
|
{
|
||||||
|
var tMatch = new TokenMatch();
|
||||||
|
tMatch.__open = bX + 1;
|
||||||
|
tMatch.__close = fX - 1;
|
||||||
|
tMatch.__selected = Char;
|
||||||
|
return tMatch;
|
||||||
|
}
|
||||||
|
else beep();
|
||||||
|
|
||||||
|
return new TokenMatch();
|
||||||
|
};
|
||||||
|
|
||||||
Analyzer.prototype.__getPairs = function( def, reload )
|
Analyzer.prototype.__getPairs = function( def, reload )
|
||||||
{
|
{
|
||||||
if( !reload && this.__tokpairs[ def ] )
|
if( !reload && this.__tokpairs[ def ] )
|
||||||
|
@ -6,6 +6,8 @@ Components.Vim.Syntax.Analyzer.bracketAt;
|
|||||||
/** @type Function */
|
/** @type Function */
|
||||||
Components.Vim.Syntax.Analyzer.bracketIn;
|
Components.Vim.Syntax.Analyzer.bracketIn;
|
||||||
/** @type Function */
|
/** @type Function */
|
||||||
|
Components.Vim.Syntax.Analyzer.quoteIn;
|
||||||
|
/** @type Function */
|
||||||
Components.Vim.Syntax.Analyzer.wordAt;
|
Components.Vim.Syntax.Analyzer.wordAt;
|
||||||
/** @type Function */
|
/** @type Function */
|
||||||
Components.Vim.Syntax.Analyzer.quoteAt;
|
Components.Vim.Syntax.Analyzer.quoteAt;
|
||||||
|
Loading…
Reference in New Issue
Block a user