@@ -96,7 +96,7 @@ void _windowWatcher_FormulaBarWindowChanged(object sender, WindowWatcher.WindowC
9696 else if ( e . ObjectId == WindowWatcher . WindowChangedEventArgs . ChangeObjectId . Caret )
9797 {
9898 // We expect this on every text change (and it is our only detection of text changes)
99- UpdateEditState ( ) ;
99+ UpdateEditStateDelayed ( ) ;
100100 }
101101 else
102102 {
@@ -158,7 +158,7 @@ void _windowWatcher_InCellEditWindowChanged(object sender, WindowWatcher.WindowC
158158 else if ( e . ObjectId == WindowWatcher . WindowChangedEventArgs . ChangeObjectId . Caret )
159159 {
160160 // We expect this on every text change (and it is our only detection of text changes)
161- UpdateEditState ( ) ;
161+ UpdateEditStateDelayed ( ) ;
162162 }
163163 else
164164 {
@@ -282,6 +282,15 @@ void _windowLocationWatcher_LocationChanged(object sender, EventArgs e)
282282 // UpdateFormula(textChangedOnly: true);
283283 //}
284284
285+ void UpdateEditStateDelayed ( )
286+ {
287+ _syncContextAuto . Post ( _ =>
288+ {
289+ Thread . Sleep ( 50 ) ;
290+ UpdateEditState ( ) ;
291+ } , null ) ;
292+ }
293+
285294 // Switches to our Automation thread, updates current state and raises StateChanged event
286295 void UpdateEditState ( bool moveOnly = false )
287296 {
@@ -292,12 +301,10 @@ void UpdateEditState(bool moveOnly = false)
292301 bool prefixChanged = false ;
293302 if ( _formulaEditFocus == FormulaEditFocus . FormulaBar )
294303 {
295- //focusedEdit = _formulaBar;
296304 hwnd = _hwndFormulaBar ;
297305 }
298306 else if ( _formulaEditFocus == FormulaEditFocus . InCellEdit )
299307 {
300- //focusedEdit = _inCellEdit;
301308 hwnd = _hwndInCellEdit ;
302309 }
303310 else
@@ -317,14 +324,12 @@ void UpdateEditState(bool moveOnly = false)
317324 {
318325 EditWindowBounds = Win32Helper . GetWindowBounds ( hwnd ) ;
319326
320- var pt = Win32Helper . GetClientCursorPos ( hwnd ) ;
321-
322327 if ( ! IsEditingFormula )
323328 {
324329 IntPtr hwndTopLevel = Win32Helper . GetRootAncestor ( hwnd ) ;
325330 InstallLocationMonitor ( hwndTopLevel ) ;
331+ IsEditingFormula = true ;
326332 }
327- IsEditingFormula = true ;
328333
329334 var newPrefix = XlCall . GetFormulaEditPrefix ( ) ; // What thread do we have to use here ...?
330335 if ( CurrentPrefix != newPrefix )
@@ -346,14 +351,6 @@ void UpdateEditState(bool moveOnly = false)
346351 }
347352 }
348353
349- void UpdateFormula ( bool textChangedOnly = false )
350- {
351- Logger . WindowWatcher . Verbose ( $ ">>>> FormulaEditWatcher.UpdateFormula on thread { Thread . CurrentThread . ManagedThreadId } ") ;
352- CurrentPrefix = XlCall . GetFormulaEditPrefix ( ) ; // What thread do we have to use here ...?
353- Logger . WindowWatcher . Verbose ( $ ">>>> FormulaEditWatcher.UpdateFormula CurrentPrefix: { CurrentPrefix } ") ;
354- OnStateChanged ( textChangedOnly ? StateChangeType . TextChange : StateChangeType . Multiple ) ;
355- }
356-
357354 // We ensure that our event is raised on the Automation thread .. (Eases concurrency issues in handling it, though it will get passed on to the main thread...)
358355 void OnStateChanged ( StateChangeType stateChangeType )
359356 {
0 commit comments