Skip to content

Commit 7a9192a

Browse files
authored
Merge pull request #2036 from Hosch250/Issue1973
Find Symbol bug fixes
2 parents 8c4b06a + 9b01756 commit 7a9192a

File tree

2 files changed

+50
-32
lines changed

2 files changed

+50
-32
lines changed

RetailCoder.VBE/UI/FindSymbol/FindSymbolControl.xaml

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
66
xmlns:local="clr-namespace:Rubberduck.UI.FindSymbol"
77
mc:Ignorable="d"
8-
d:DesignHeight="24" d:DesignWidth="270">
8+
d:DesignHeight="24" d:DesignWidth="270"
9+
d:DataContext="{d:DesignInstance {x:Type local:FindSymbolViewModel}, IsDesignTimeCreatable=False}">
910

1011
<UserControl.CommandBindings>
1112
<CommandBinding Command="local:FindSymbolControl.GoCommand"
@@ -19,22 +20,16 @@
1920
<ColumnDefinition Width="*" />
2021
<ColumnDefinition Width="32" />
2122
</Grid.ColumnDefinitions>
22-
23+
2324
<ComboBox IsEditable="True"
2425
ItemsSource="{Binding MatchResults}"
25-
SelectedItem="{Binding SelectedItem, UpdateSourceTrigger=PropertyChanged}"
26+
SelectedItem="{Binding SelectedItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
2627
IsTextSearchCaseSensitive="False"
2728
IsTextSearchEnabled="True"
28-
TextSearch.Text="{Binding SearchString, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"
29+
Text="{Binding SearchString, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
2930
TextSearch.TextPath="IdentifierName"
3031
PreviewKeyDown="UIElement_OnPreviewKeyDown">
31-
32-
<!--<ComboBox.ItemsPanel>
33-
<ItemsPanelTemplate>
34-
<VirtualizingStackPanel />
35-
</ItemsPanelTemplate>
36-
</ComboBox.ItemsPanel>-->
37-
32+
3833
<ComboBox.ItemTemplate>
3934
<DataTemplate DataType="local:SearchResult">
4035
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
@@ -46,8 +41,7 @@
4641
</ComboBox.ItemTemplate>
4742
</ComboBox>
4843

49-
<Button Grid.Column="1"
50-
Command="local:FindSymbolControl.GoCommand">
44+
<Button Grid.Column="1" Command="local:FindSymbolControl.GoCommand">
5145
<Image Height="16" Source="pack://application:,,,/Rubberduck;component/Resources/arrow.png" />
5246
</Button>
5347

RetailCoder.VBE/UI/FindSymbol/FindSymbolViewModel.cs

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,8 @@ public FindSymbolViewModel(IEnumerable<Declaration> declarations, DeclarationIco
2323
{
2424
_declarations = declarations;
2525
_cache = cache;
26-
var initialResults = _declarations
27-
.Where(declaration => !ExcludedTypes.Contains(declaration.DeclarationType))
28-
.OrderBy(declaration => declaration.IdentifierName.ToLowerInvariant())
29-
.Select(declaration => new SearchResult(declaration, cache[declaration]))
30-
.ToList();
31-
32-
MatchResults = new ObservableCollection<SearchResult>(initialResults);
26+
27+
Search(string.Empty);
3328
}
3429

3530
public event EventHandler<NavigateCodeEventArgs> Navigate;
@@ -59,47 +54,76 @@ public void OnNavigate()
5954

6055
private void Search(string value)
6156
{
57+
if (string.IsNullOrWhiteSpace(value))
58+
{
59+
MatchResults = new ObservableCollection<SearchResult>();
60+
return;
61+
}
62+
6263
var lower = value.ToLowerInvariant();
6364
var results = _declarations
6465
.Where(declaration => !ExcludedTypes.Contains(declaration.DeclarationType)
65-
&& (string.IsNullOrEmpty(value) || declaration.IdentifierName.ToLowerInvariant().Contains(lower)))
66+
&& (string.IsNullOrEmpty(value) || declaration.IdentifierName.ToLowerInvariant().Contains(lower)))
6667
.OrderBy(declaration => declaration.IdentifierName.ToLowerInvariant())
67-
.Select(declaration => new SearchResult(declaration, _cache[declaration]))
68-
.ToList();
68+
.Select(declaration => new SearchResult(declaration, _cache[declaration]));
6969

7070
MatchResults = new ObservableCollection<SearchResult>(results);
7171
}
7272

7373
private string _searchString;
74-
7574
public string SearchString
7675
{
7776
get { return _searchString; }
7877
set
7978
{
80-
_searchString = value;
81-
Search(value);
79+
if (_searchString != value)
80+
{
81+
_searchString = value;
82+
Search(value);
83+
}
8284
}
8385
}
8486

8587
private SearchResult _selectedItem;
86-
8788
public SearchResult SelectedItem
8889
{
8990
get { return _selectedItem; }
9091
set
91-
{
92-
_selectedItem = value;
93-
OnPropertyChanged();
92+
{
93+
if (_selectedItem != value)
94+
{
95+
_selectedItem = value;
96+
OnPropertyChanged();
97+
}
9498
}
9599
}
96100

97101
private ObservableCollection<SearchResult> _matchResults;
98-
99102
public ObservableCollection<SearchResult> MatchResults
100103
{
101104
get { return _matchResults; }
102-
set { _matchResults = value; OnPropertyChanged(); }
105+
set
106+
{
107+
var oldSelectedItem = SelectedItem;
108+
109+
_matchResults = value;
110+
111+
// save the selection when the user clicks on one of the drop-down items and the search results are updated
112+
if (oldSelectedItem != null)
113+
{
114+
var newSelectedItem = value.FirstOrDefault(s => s.Declaration == oldSelectedItem.Declaration);
115+
116+
if (newSelectedItem != null)
117+
{
118+
_selectedItem = newSelectedItem;
119+
_searchString = newSelectedItem.IdentifierName;
120+
121+
OnPropertyChanged("SelectedItem");
122+
}
123+
}
124+
125+
OnPropertyChanged();
126+
}
103127
}
104128

105129
public event PropertyChangedEventHandler PropertyChanged;

0 commit comments

Comments
 (0)