@@ -3674,7 +3674,7 @@ static public bool IsTextStyle(int style)
3674
3674
{
3675
3675
return style == 0 || style == 10 /*punctuation*/ || style == 11 /*identifier*/
3676
3676
|| style == 16 /*word2 (secondary keywords: class name)*/
3677
- || style == 24 /*word4 (add keywords4)*/ || style == 25 /*word5 (add keywords5)*/
3677
+ || style == 101 /*word4 (add keywords4)*/ || style == 102 /*word5 (add keywords5)*/
3678
3678
|| style == 127 /*PHP*/ ;
3679
3679
}
3680
3680
@@ -3686,8 +3686,8 @@ static public bool IsTextStyleEx(int style)
3686
3686
return style == 0 || style == 5 /*word (secondary keywords)*/
3687
3687
|| style == 10 /*punctuation*/ || style == 11 /*identifier*/
3688
3688
|| style == 16 /*word2 (secondary keywords: class name)*/
3689
- || style == 19 /*globalclass (primary keywords)*/ || style == 23 /*word3 (add keywords3)*/
3690
- || style == 24 /*word4 (add keywords4)*/ || style == 25 /*word5 (add keywords5)*/
3689
+ || style == 19 /*globalclass (primary keywords)*/ || style == 100 /*word3 (add keywords3)*/
3690
+ || style == 101 /*word4 (add keywords4)*/ || style == 102 /*word5 (add keywords5)*/
3691
3691
|| style == 127 /*PHP*/ ;
3692
3692
}
3693
3693
@@ -4274,74 +4274,73 @@ public static bool HasSnippet(string word)
4274
4274
/// <param name="sci"></param>
4275
4275
/// <param name="value">Character inserted</param>
4276
4276
/// <returns>Code was generated</returns>
4277
- static private bool CodeAutoOnChar ( ScintillaControl sci , int value )
4277
+ static bool CodeAutoOnChar ( ScintillaControl sci , int value )
4278
4278
{
4279
4279
if ( ASContext . Context . Settings == null || ! ASContext . Context . Settings . GenerateImports )
4280
4280
return false ;
4281
4281
4282
4282
int position = sci . CurrentPos ;
4283
4283
4284
- if ( value == '*' && position > 1 && sci . CharAt ( position - 2 ) == '.' && LastExpression != null )
4285
- {
4286
- // context
4287
- if ( LastExpression . Separator == ' ' && LastExpression . WordBefore != null
4288
- && ! ASContext . Context . Features . HasTypePreKey ( LastExpression . WordBefore ) )
4289
- return false ;
4284
+ if ( value == '*' && position > 1 && sci . CharAt ( position - 2 ) == '.' && LastExpression != null )
4285
+ return HandleWildcardList ( sci , position , LastExpression ) ;
4290
4286
4291
- FileModel cFile = ASContext . Context . CurrentModel ;
4292
- ClassModel cClass = ASContext . Context . CurrentClass ;
4293
- ASResult context = EvalExpression ( LastExpression . Value , LastExpression , cFile , cClass , true , false ) ;
4294
- if ( context . IsNull ( ) || ! context . IsPackage || context . InFile == null )
4295
- return false ;
4287
+ return false ;
4288
+ }
4296
4289
4297
- string package = LastExpression . Value ;
4298
- int startPos = LastExpression . Position ;
4299
- string check = "" ;
4300
- char c ;
4301
- while ( startPos > LastExpression . PositionExpression && check . Length <= package . Length && check != package )
4302
- {
4303
- c = ( char ) sci . CharAt ( -- startPos ) ;
4304
- if ( c > 32 ) check = c + check ;
4305
- }
4306
- if ( check != package )
4307
- return false ;
4290
+ /// <summary>
4291
+ /// User entered a qualified package with a wildcard, eg. flash.geom.*, at an unexpected position, eg. not after 'import'.
4292
+ /// Remove expression, generate coresponding wildcard import, and show list of types of this package
4293
+ /// </summary>
4294
+ static bool HandleWildcardList ( ScintillaControl sci , int position , ASExpr expr )
4295
+ {
4296
+ // validate context
4297
+ var context = ASContext . Context ;
4298
+ if ( expr . Separator == ' ' && expr . WordBefore != null
4299
+ && context . Features . HasTypePreKey ( expr . WordBefore ) )
4300
+ return false ;
4308
4301
4309
- // insert import
4310
- string statement = "import " + package + "*;" + LineEndDetector . GetNewLineMarker ( sci . EOLMode ) ;
4311
- int endPos = sci . CurrentPos ;
4312
- int line = 0 ;
4313
- int curLine = sci . LineFromPosition ( position ) ;
4314
- bool found = false ;
4315
- while ( line < curLine )
4302
+ var cFile = context . CurrentModel ;
4303
+ var cClass = context . CurrentClass ;
4304
+ var resolved = EvalExpression ( expr . Value , expr , cFile , cClass , true , false ) ;
4305
+ if ( resolved . IsNull ( ) || ! resolved . IsPackage || resolved . InFile == null )
4306
+ return false ;
4307
+
4308
+ string package = resolved . InFile . Package ;
4309
+ string check = Regex . Replace ( expr . Value , "\\ s" , "" ) . TrimEnd ( '.' ) ;
4310
+ if ( check != package )
4311
+ return false ;
4312
+
4313
+ sci . BeginUndoAction ( ) ;
4314
+ try
4315
+ {
4316
+ // remove temp wildcard
4317
+ int startPos = expr . PositionExpression ;
4318
+ sci . SetSel ( startPos , position ) ;
4319
+ sci . ReplaceSel ( "" ) ;
4320
+
4321
+ // generate import
4322
+ if ( context . Settings . GenerateImports )
4316
4323
{
4317
- if ( sci . GetLine ( line ++ ) . IndexOf ( "import" ) >= 0 ) found = true ;
4318
- else if ( found ) {
4319
- line -- ;
4320
- break ;
4324
+ var wildcard = new MemberModel { Name = "*" , Type = package + ".*" } ;
4325
+ if ( ! context . IsImported ( wildcard , sci . LineFromPosition ( position ) ) )
4326
+ {
4327
+ startPos += ASGenerator . InsertImport ( wildcard , true ) ;
4328
+ sci . SetSel ( startPos , startPos ) ;
4321
4329
}
4322
4330
}
4323
- if ( line == curLine ) line = 0 ;
4324
- position = sci . PositionFromLine ( line ) ;
4325
- line = sci . FirstVisibleLine ;
4326
- sci . SetSel ( position , position ) ;
4327
- sci . ReplaceSel ( statement ) ;
4328
-
4329
- // prepare insertion of the term as usual
4330
- startPos += statement . Length ;
4331
- endPos += statement . Length ;
4332
- sci . SetSel ( startPos , endPos ) ;
4333
- sci . ReplaceSel ( "" ) ;
4334
- sci . LineScroll ( 0 , line - sci . FirstVisibleLine + 1 ) ;
4335
-
4336
- // create classes list
4337
- List < ICompletionListItem > list = new List < ICompletionListItem > ( ) ;
4338
- foreach ( MemberModel import in cClass . InFile . Imports )
4339
- if ( import . Type . StartsWith ( package ) )
4340
- list . Add ( new MemberItem ( import ) ) ;
4341
- CompletionList . Show ( list , false ) ;
4342
- return true ;
4343
4331
}
4344
- return false ;
4332
+ finally
4333
+ {
4334
+ sci . EndUndoAction ( ) ;
4335
+ }
4336
+
4337
+ // show types
4338
+ var list = new List < ICompletionListItem > ( ) ;
4339
+ var imports = context . ResolvePackage ( package , false ) . Imports ;
4340
+ foreach ( MemberModel import in imports )
4341
+ list . Add ( new MemberItem ( import ) ) ;
4342
+ CompletionList . Show ( list , false ) ;
4343
+ return true ;
4345
4344
}
4346
4345
4347
4346
#endregion
0 commit comments