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/BackendBindings/WixBinding Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,8 +37,10 @@ public ITextEditor FindTextEditorForDocument(WixDocument document)
3737 {
3838 foreach ( IViewContent view in workbench . ViewContentCollection ) {
3939 ITextEditor textEditor = view . GetService < ITextEditor > ( ) ;
40- if ( AreFileNamesEqual ( view . PrimaryFileName , document . FileName ) ) {
41- return textEditor ;
40+ if ( textEditor != null ) {
41+ if ( AreFileNamesEqual ( view . PrimaryFileName , document . FileName ) ) {
42+ return textEditor ;
43+ }
4244 }
4345 }
4446 return null ;
Original file line number Diff line number Diff line change 1818
1919using System ;
2020using ICSharpCode . SharpDevelop ;
21+ using ICSharpCode . SharpDevelop . Editor ;
2122using ICSharpCode . WixBinding ;
2223using NUnit . Framework ;
2324using WixBinding . Tests . Utils ;
@@ -37,7 +38,7 @@ public void Init()
3738 {
3839 SD . InitializeForUnitTests ( ) ;
3940 existingTextEditor = new MockTextEditor ( ) ;
40- MockTextEditorViewContent viewContent = new MockTextEditorViewContent ( ) ;
41+ var viewContent = new MockTextEditorViewContent ( ) ;
4142 viewContent . TextEditor = existingTextEditor ;
4243 viewContent . SetFileName ( @"d:\projects\test\file.wxs" ) ;
4344
@@ -64,5 +65,19 @@ public void CannotFindTextEditorForUnknownWixDocumentFileName()
6465 unknownDocument . FileName = @"d:\unknown-file.wxs" ;
6566 Assert . IsNull ( openEditors . FindTextEditorForDocument ( unknownDocument ) ) ;
6667 }
68+
69+ [ Test ]
70+ public void FindTextEditorForDocument_FirstViewContentHasNoTextEditorAndNoPrimaryFileName_DoesNotThrowNullReferenceException ( )
71+ {
72+ var viewContent = new MockViewContent ( ) ;
73+ viewContent . PrimaryFile = null ;
74+ workbench . ViewContentCollection . Add ( viewContent ) ;
75+ var unknownDocument = new WixDocument ( ) ;
76+ unknownDocument . FileName = @"d:\unknown-file.wxs" ;
77+
78+ ITextEditor textEditor = openEditors . FindTextEditorForDocument ( unknownDocument ) ;
79+
80+ Assert . IsNull ( textEditor ) ;
81+ }
6782 }
6883}
Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ public IList<OpenedFile> Files {
6565
6666 public OpenedFile PrimaryFile {
6767 get { return primaryFile ; }
68+ set { primaryFile = value ; }
6869 }
6970
7071 public FileName PrimaryFileName {
You can’t perform that action at this time.
0 commit comments