Dispatch a "change" Event on quit to notify other handlers

This commit is contained in:
斟酌 鵬兄 2018-07-22 01:06:22 +08:00
parent 9da78e2711
commit 7a29206edb
4 changed files with 50 additions and 23 deletions

View File

@ -48,9 +48,19 @@
return i; return i;
}; };
/** marker @type {Components.Vim.State.Marks} */ var lineInfo = function( c )
var MarkSelected = function( marker, PStart, PEnd )
{ {
return {
lineNum: c.getLine().lineNum
, aX: c.aX
};
};
/** marker @type {Components.Vim.State.Marks} */
var MarkSelected = function( marker, s, e )
{
marker.set( "<", s.lineNum, s.aX );
marker.set( ">", e.lineNum, e.aX );
}; };
/** @type {Components.Vim.IAction} */ /** @type {Components.Vim.IAction} */
@ -68,14 +78,12 @@
/** @type {Components.Vim.Cursor} */ /** @type {Components.Vim.Cursor} */
this.__cursor = Cursor; this.__cursor = Cursor;
var s = { var s = lineInfo( Cursor );
lineNum: Cursor.getLine().lineNum
, X: Cursor.X
, aPos: Cursor.aPos
, pstart: Cursor.PStart
};
s.aStart = s.aPos - Cursor.aX; s.aPos = Cursor.aPos;
s.X = Cursor.X;
s.pStart = Cursor.PStart;
s.aStart = s.aPos - s.aX;
Cursor.suppressEvent(); Cursor.suppressEvent();
Cursor.lineEnd( true ); Cursor.lineEnd( true );
@ -220,7 +228,7 @@
Action.dispose(); Action.dispose();
cur.unsuppressEvent(); cur.unsuppressEvent();
startLine.pstart = cur.PStart; startLine.pStart = cur.PStart;
return true; return true;
} }
@ -253,13 +261,13 @@
debug.Info( "Min aPos: " + minAp, "Max aPos: " + maxAp ); debug.Info( "Min aPos: " + minAp, "Max aPos: " + maxAp );
var pstart = startLine.X; var pStart = startLine.X;
var nstart = cur.PStart; var nstart = cur.PStart;
// highlight from the start // highlight from the start
if( startLine.aPos < minAp ) if( startLine.aPos < minAp )
{ {
pstart = 0; pStart = 0;
if( this.__mode == MODE_LINE ) if( this.__mode == MODE_LINE )
{ {
@ -276,14 +284,14 @@
// highlight from the end // highlight from the end
else if( maxAp < startLine.aPos ) else if( maxAp < startLine.aPos )
{ {
pstart = -2; pStart = -2;
var i = 0; var i = 0;
do do
{ {
if( line.placeholder ) break; if( line.placeholder ) break;
if( i <= feeder.moreAt ) if( i <= feeder.moreAt )
{ {
pstart += line.toString().length + 1; pStart += line.toString().length + 1;
} }
i ++; i ++;
} }
@ -295,11 +303,11 @@
if( this.__mode == MODE_LINE ) if( this.__mode == MODE_LINE )
{ {
cur.suppressEvent(); cur.suppressEvent();
pstart = 0; pStart = 0;
if( currAp < startLine.aPos ) if( currAp < startLine.aPos )
{ {
pstart = -1; pStart = -1;
l ++; l ++;
cur.lineStart(); cur.lineStart();
@ -316,7 +324,7 @@
cur.lineStart(); cur.lineStart();
nstart = cur.PStart; nstart = cur.PStart;
cur.lineEnd( true ); cur.lineEnd( true );
pstart = cur.PStart; pStart = cur.PStart;
l = line.lineNum; l = line.lineNum;
} }
@ -334,12 +342,12 @@
do do
{ {
if( line.lineNum == l || line.placeholder ) break; if( line.lineNum == l || line.placeholder ) break;
pstart += line.toString().length + 1; pStart += line.toString().length + 1;
} }
while( line = line.next ); while( line = line.next );
} }
var prevPos = pstart; var prevPos = pStart;
var newPos = nstart; var newPos = nstart;
var posDiff = newPos - prevPos; var posDiff = newPos - prevPos;
@ -351,12 +359,14 @@
if( 0 <= posDiff ) if( 0 <= posDiff )
{ {
newPos = newPos + 1; newPos = newPos + 1;
MarkSelected( e.target.marks, startLine, lineInfo( cur ) );
} }
// e<--s // e<--s
else if( posDiff < 0 ) else if( posDiff < 0 )
{ {
prevPos += posDiff; prevPos += posDiff;
newPos = pstart + 1; newPos = pStart + 1;
MarkSelected( e.target.marks, lineInfo( cur ), startLine );
} }
cur.PStart = prevPos; cur.PStart = prevPos;

View File

@ -240,7 +240,7 @@
if( this.__content[ i + 1 ] == "\t" ) tabs ++; if( this.__content[ i + 1 ] == "\t" ) tabs ++;
i ++; i ++;
} }
while( i < l ) while( i < l );
if( tabs ) if( tabs )
{ {

View File

@ -6,7 +6,7 @@
var beep = __import( "Components.Vim.Beep" ); var beep = __import( "Components.Vim.Beep" );
var Keys = "'ABCDEFGHIJKLMNOPQRSTUVWXYabcdefghijklmnopqrstuvwxy\"[]^.<>"; var Keys = "'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\"[]^.<>";
var Marks = function() var Marks = function()
{ {
@ -25,12 +25,28 @@
return true; return true;
}; };
Marks.prototype.save = function()
{
var saved = {};
// A-z
for( var i = 1; i < 53; i ++ )
{
var k = Keys[ i ];
if( this.__marks[ k ] != undefined )
{
saved[ k ] = this.__marks[ k ];
}
}
return saved;
};
Marks.prototype.get = function( t ) Marks.prototype.get = function( t )
{ {
return this.__marks[ t ]; return this.__marks[ t ];
}; };
__readOnly( Marks, "Keys", function() { return Keys; } ); __const( Marks, "Keys", Keys );
ns[ NS_EXPORT ]( EX_CLASS, "Marks", Marks ); ns[ NS_EXPORT ]( EX_CLASS, "Marks", Marks );

View File

@ -381,6 +381,7 @@
stage.element.value = this.content; stage.element.value = this.content;
delete Insts[ this.__instIndex ]; delete Insts[ this.__instIndex ];
stage.dispatchEvent( new Event( "change" ) );
}; };
__readOnly( VimArea.prototype, "index", function() __readOnly( VimArea.prototype, "index", function()