@@ -139,39 +139,9 @@ public void KeepResultsExcept(PluginMetadata metadata)
139
139
/// </summary>
140
140
public void AddResults ( List < Result > newRawResults , string resultId )
141
141
{
142
- lock ( _collectionLock )
143
- {
144
- var newResults = NewResults ( newRawResults , resultId ) ;
145
-
146
- // https://social.msdn.microsoft.com/Forums/vstudio/en-US/5ff71969-f183-4744-909d-50f7cd414954/binding-a-tabcontrols-selectedindex-not-working?forum=wpf
147
- // fix selected index flow
148
- var updateTask = Task . Run ( ( ) =>
149
- {
150
- // update UI in one run, so it can avoid UI flickering
151
-
152
- Results . Update ( newResults ) ;
153
- if ( Results . Any ( ) )
154
- SelectedItem = Results [ 0 ] ;
155
- } ) ;
156
- if ( ! updateTask . Wait ( 300 ) )
157
- {
158
- updateTask . Dispose ( ) ;
159
- throw new TimeoutException ( "Update result use too much time." ) ;
160
- }
142
+ var newResults = NewResults ( newRawResults , resultId ) ;
161
143
162
- }
163
-
164
- if ( Visbility != Visibility . Visible && Results . Count > 0 )
165
- {
166
- Margin = new Thickness { Top = 8 } ;
167
- SelectedIndex = 0 ;
168
- Visbility = Visibility . Visible ;
169
- }
170
- else
171
- {
172
- Margin = new Thickness { Top = 0 } ;
173
- Visbility = Visibility . Collapsed ;
174
- }
144
+ UpdateResults ( newResults ) ;
175
145
}
176
146
/// <summary>
177
147
/// To avoid deadlock, this method should not called from main thread
@@ -181,10 +151,15 @@ public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, Cancella
181
151
var newResults = NewResults ( resultsForUpdates ) ;
182
152
if ( token . IsCancellationRequested )
183
153
return ;
154
+ UpdateResults ( newResults , token ) ;
155
+
156
+ }
157
+
158
+ private void UpdateResults ( List < ResultViewModel > newResults , CancellationToken token = default )
159
+ {
184
160
lock ( _collectionLock )
185
161
{
186
162
// update UI in one run, so it can avoid UI flickering
187
-
188
163
Results . Update ( newResults , token ) ;
189
164
if ( Results . Any ( ) )
190
165
SelectedItem = Results [ 0 ] ;
@@ -202,7 +177,6 @@ public void AddResults(IEnumerable<ResultsForUpdate> resultsForUpdates, Cancella
202
177
Visbility = Visibility . Collapsed ;
203
178
break ;
204
179
}
205
-
206
180
}
207
181
208
182
private List < ResultViewModel > NewResults ( List < Result > newRawResults , string resultId )
@@ -212,10 +186,10 @@ private List<ResultViewModel> NewResults(List<Result> newRawResults, string resu
212
186
213
187
var results = Results as IEnumerable < ResultViewModel > ;
214
188
215
- var newResults = newRawResults . Select ( r => new ResultViewModel ( r , _settings ) ) . ToList ( ) ;
189
+ var newResults = newRawResults . Select ( r => new ResultViewModel ( r , _settings ) ) ;
216
190
217
191
return results . Where ( r => r . Result . PluginID != resultId )
218
- . Concat ( results . Intersect ( newResults ) . Union ( newResults ) )
192
+ . Concat ( newResults )
219
193
. OrderByDescending ( r => r . Result . Score )
220
194
. ToList ( ) ;
221
195
}
@@ -228,8 +202,7 @@ private List<ResultViewModel> NewResults(IEnumerable<ResultsForUpdate> resultsFo
228
202
var results = Results as IEnumerable < ResultViewModel > ;
229
203
230
204
return results . Where ( r => r != null && ! resultsForUpdates . Any ( u => u . Metadata . ID == r . Result . PluginID ) )
231
- . Concat (
232
- resultsForUpdates . SelectMany ( u => u . Results , ( u , r ) => new ResultViewModel ( r , _settings ) ) )
205
+ . Concat ( resultsForUpdates . SelectMany ( u => u . Results , ( u , r ) => new ResultViewModel ( r , _settings ) ) )
233
206
. OrderByDescending ( rv => rv . Result . Score )
234
207
. ToList ( ) ;
235
208
}
0 commit comments