This repository was archived by the owner on Oct 16, 2020. It is now read-only.
File tree Expand file tree Collapse file tree
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -78,7 +78,12 @@ public override IInsightWindow ShowInsightWindow(IEnumerable<IInsightItem> items
7878 }
7979
8080 public override IInsightWindow ActiveInsightWindow {
81- get { return textEditor . ActiveInsightWindow . activeAdapter ; }
81+ get {
82+ if ( textEditor . ActiveInsightWindow != null )
83+ return textEditor . ActiveInsightWindow . activeAdapter ;
84+ else
85+ return null ;
86+ }
8287 }
8388
8489 public override ICompletionListWindow ActiveCompletionWindow {
Original file line number Diff line number Diff line change @@ -94,17 +94,24 @@ protected override void DetachEvents()
9494
9595 void OnClosed ( object sender , EventArgs e )
9696 {
97- activeAdapter . OnClosed ( ) ;
97+ if ( activeAdapter != null )
98+ activeAdapter . OnClosed ( ) ;
9899 }
99100
100101 void caret_PositionChanged ( object sender , EventArgs e )
101102 {
102- activeAdapter . OnCaretPositionChanged ( e ) ;
103+ // It is possible that the insight window is not initialized correctly
104+ // due to an exception, and then caret_PositionChanged is called in a finally block
105+ // during exception handling.
106+ // Check for a null adapter to avoid a NullReferenceException that hides the first exception.
107+ if ( activeAdapter != null )
108+ activeAdapter . OnCaretPositionChanged ( e ) ;
103109 }
104110
105111 void document_Changed ( object sender , DocumentChangeEventArgs e )
106112 {
107- activeAdapter . OnDocumentChanged ( e ) ;
113+ if ( activeAdapter != null )
114+ activeAdapter . OnDocumentChanged ( e ) ;
108115 }
109116 }
110117
You can’t perform that action at this time.
0 commit comments