@@ -92,24 +92,32 @@ private SearchResultsViewModel CreateViewModel(Declaration declaration)
9292 private Declaration FindTarget ( object parameter )
9393 {
9494 var declaration = parameter as Declaration ;
95- if ( declaration = = null )
95+ if ( declaration ! = null )
9696 {
97- var selection = _vbe . ActiveCodePane . GetSelection ( ) ;
98- if ( ! selection . Equals ( default ( QualifiedSelection ) ) )
99- {
100- declaration = _state . AllUserDeclarations
101- . SingleOrDefault ( item => item . QualifiedName . QualifiedModuleName == selection . QualifiedName
102- && ( item . QualifiedSelection . Selection . ContainsFirstCharacter ( selection . Selection )
103- ||
104- item . References . Any ( reference => reference . Selection . ContainsFirstCharacter ( selection . Selection ) ) ) ) ;
105- }
97+ return declaration ;
98+ }
10699
107- if ( declaration == null )
108- {
109- return null ;
110- }
100+ var selection = _vbe . ActiveCodePane . GetSelection ( ) ;
101+ if ( ! selection . Equals ( default ( QualifiedSelection ) ) )
102+ {
103+ declaration = _state . AllDeclarations
104+ . SingleOrDefault ( item =>
105+ IsSelectedDeclaration ( selection , item ) ||
106+ item . References . Any ( reference => IsSelectedReference ( selection , reference ) ) ) ;
111107 }
112108 return declaration ;
113109 }
110+
111+ private static bool IsSelectedDeclaration ( QualifiedSelection selection , Declaration declaration )
112+ {
113+ return declaration . QualifiedSelection . QualifiedName . Equals ( selection . QualifiedName )
114+ && declaration . QualifiedSelection . Selection . ContainsFirstCharacter ( selection . Selection ) ;
115+ }
116+
117+ private static bool IsSelectedReference ( QualifiedSelection selection , IdentifierReference reference )
118+ {
119+ return reference . QualifiedModuleName . Equals ( selection . QualifiedName )
120+ && reference . Selection . ContainsFirstCharacter ( selection . Selection ) ;
121+ }
114122 }
115123}
0 commit comments