Skip to content

Commit 2ffe170

Browse files
committed
Use deep clone for result updating
1 parent 4f41be6 commit 2ffe170

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ private void RegisterResultsUpdatedEvent()
231231

232232
var token = e.Token == default ? _updateToken : e.Token;
233233

234-
// make a copy of results to avoid plugin change the result when updating view model
235-
var resultsCopy = e.Results.ToList();
234+
// make a clone to avoid possible issue that plugin will also change the list and items when updating view model
235+
var resultsCopy = DeepCloneResults(e.Results, token);
236236

237237
PluginManager.UpdatePluginMetadata(resultsCopy, pair.Metadata, e.Query);
238238
if (!_resultsUpdateChannelWriter.TryWrite(new ResultsForUpdate(resultsCopy, pair.Metadata, e.Query,
@@ -414,6 +414,22 @@ private async Task OpenResultAsync(string index)
414414
}
415415
}
416416

417+
private static IReadOnlyList<Result> DeepCloneResults(IReadOnlyList<Result> results, CancellationToken token = default)
418+
{
419+
var resultsCopy = new List<Result>();
420+
foreach (var result in results.ToList())
421+
{
422+
if (token.IsCancellationRequested)
423+
{
424+
break;
425+
}
426+
427+
var resultCopy = result.Clone();
428+
resultsCopy.Add(resultCopy);
429+
}
430+
return resultsCopy;
431+
}
432+
417433
#endregion
418434

419435
#region BasicCommands
@@ -1469,9 +1485,9 @@ public void UpdateResultView(ICollection<ResultsForUpdate> resultsForUpdates)
14691485
{
14701486
if (_topMostRecord.IsTopMost(result))
14711487
{
1472-
result.Score = Result.MaxScore;
1488+
result.Score = 100000; //Result.MaxScore;
14731489
}
1474-
else if (result.Score != Result.MaxScore)
1490+
else
14751491
{
14761492
var priorityScore = metaResults.Metadata.Priority * 150;
14771493
result.Score += result.AddSelectedCount ?

0 commit comments

Comments
 (0)