@@ -235,21 +235,19 @@ void FormulaEditMove(Rect editWindowBounds, Rect excelTooltipBounds)
235235 void FormulaEditTextChange ( string formulaPrefix , Rect editWindowBounds , Rect excelTooltipBounds )
236236 {
237237 Debug . Print ( $ "^^^ FormulaEditStateChanged. CurrentPrefix: { formulaPrefix } , Thread { Thread . CurrentThread . ManagedThreadId } ") ;
238- var match = Regex . Match ( formulaPrefix , @"^=(?<functionName>\w*)\(" ) ;
239- if ( match . Success )
238+ string functionName ;
239+ int currentArgIndex ;
240+ if ( FormulaParser . TryGetFormulaInfo ( formulaPrefix , out functionName , out currentArgIndex ) )
240241 {
241- string functionName = match . Groups [ "functionName" ] . Value ;
242-
243242 IntelliSenseFunctionInfo functionInfo ;
244243 if ( _functionInfoMap . TryGetValue ( functionName , out functionInfo ) )
245244 {
246- // TODO: Fix this: Need to consider subformulae
247- int currentArgIndex = formulaPrefix . Count ( c => c == ',' ) ;
248245 _argumentsToolTip . ShowToolTip (
249246 GetFunctionIntelliSense ( functionInfo , currentArgIndex ) ,
250247 ( int ) editWindowBounds . Left , ( int ) editWindowBounds . Bottom + 5 ) ;
251248 return ;
252249 }
250+
253251 }
254252
255253 // All other paths, we hide the box
@@ -288,15 +286,19 @@ void FunctionListSelectedItemChange(string selectedItemText, Rect selectedItemBo
288286 if ( _functionInfoMap . TryGetValue ( selectedItemText , out functionInfo ) )
289287 {
290288 // It's ours!
291- _descriptionToolTip . ShowToolTip (
292- text : new FormattedText { GetFunctionDescription ( functionInfo ) } ,
293- left : ( int ) selectedItemBounds . Right + 25 ,
294- top : ( int ) selectedItemBounds . Top ) ;
295- }
296- else
297- {
298- _descriptionToolTip . Hide ( ) ;
289+ var descriptionLines = GetFunctionDescriptionOrNull ( functionInfo ) ;
290+ if ( descriptionLines != null )
291+ {
292+ _descriptionToolTip . ShowToolTip (
293+ text : new FormattedText { GetFunctionDescriptionOrNull ( functionInfo ) } ,
294+ left : ( int ) selectedItemBounds . Right + 25 ,
295+ top : ( int ) selectedItemBounds . Top ) ;
296+ return ;
297+ }
299298 }
299+
300+ // Not ours or no description
301+ _descriptionToolTip . Hide ( ) ;
300302 }
301303
302304 void FunctionListMove ( Rect selectedItemBounds )
@@ -307,18 +309,20 @@ void FunctionListMove(Rect selectedItemBounds)
307309 // TODO: Performance / efficiency - cache these somehow
308310 // TODO: Probably not a good place for LINQ !?
309311 static readonly string [ ] s_newLineStringArray = new string [ ] { Environment . NewLine } ;
310- IEnumerable < TextLine > GetFunctionDescription ( IntelliSenseFunctionInfo functionInfo )
312+ IEnumerable < TextLine > GetFunctionDescriptionOrNull ( IntelliSenseFunctionInfo functionInfo )
311313 {
312- return
313- functionInfo . Description
314- . Split ( s_newLineStringArray , StringSplitOptions . None )
315- . Select ( line =>
316- new TextLine {
317- new TextRun
318- {
319- Style = System . Drawing . FontStyle . Regular ,
320- Text = line
321- } } ) ;
314+ var description = functionInfo . Description ;
315+ if ( string . IsNullOrEmpty ( description ) )
316+ return null ;
317+
318+ return description . Split ( s_newLineStringArray , StringSplitOptions . None )
319+ . Select ( line =>
320+ new TextLine {
321+ new TextRun
322+ {
323+ Style = System . Drawing . FontStyle . Regular ,
324+ Text = line
325+ } } ) ;
322326 }
323327
324328 FormattedText GetFunctionIntelliSense ( IntelliSenseFunctionInfo functionInfo , int currentArgIndex )
@@ -357,12 +361,13 @@ FormattedText GetFunctionIntelliSense(IntelliSenseFunctionInfo functionInfo, int
357361 }
358362 nameLine . Add ( new TextRun { Text = ")" } ) ;
359363
360- var descriptionLines = GetFunctionDescription ( functionInfo ) ;
364+ var descriptionLines = GetFunctionDescriptionOrNull ( functionInfo ) ;
361365
362366 var formattedText = new FormattedText { nameLine , descriptionLines } ;
363367 if ( functionInfo . ArgumentList . Count > currentArgIndex )
364368 {
365- formattedText . Add ( GetArgumentDescription ( functionInfo . ArgumentList [ currentArgIndex ] ) ) ;
369+ var description = GetArgumentDescription ( functionInfo . ArgumentList [ currentArgIndex ] ) ;
370+ formattedText . Add ( description ) ;
366371 }
367372
368373 return formattedText ;
@@ -379,7 +384,7 @@ TextLine GetArgumentDescription(IntelliSenseFunctionInfo.ArgumentInfo argumentIn
379384 new TextRun
380385 {
381386 Style = System . Drawing . FontStyle . Italic ,
382- Text = argumentInfo . Description
387+ Text = argumentInfo . Description ?? ""
383388 } ,
384389 } ;
385390 }
@@ -399,6 +404,7 @@ public void Dispose()
399404 _argumentsToolTip . Dispose ( ) ;
400405 _argumentsToolTip = null ;
401406 }
407+ _uiMonitor . Dispose ( ) ;
402408 } , null ) ;
403409
404410 _syncContextMain = null ;
0 commit comments