mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 09:28:03 +08:00
Fix UI flickering under .net 4.5
1. This is part of .net 4.5 fix, check #393 to see more 2. This bug is introduced since commit df4ca3fecc9784a3b55f93806d8b2a662523056f
This commit is contained in:
parent
4d25d505e0
commit
f9e27ef67c
@ -30,9 +30,9 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
|
||||
var fuzzyMather = FuzzyMatcher.Create(query.Search);
|
||||
var results = programs.Where(o => MatchProgram(o, fuzzyMather)).
|
||||
var results = programs.Where(p => MatchProgram(p, fuzzyMather)).
|
||||
Select(ScoreFilter).
|
||||
OrderByDescending(o => o.Score)
|
||||
OrderByDescending(p => p.Score)
|
||||
.Select(c => new Result()
|
||||
{
|
||||
Title = c.Title,
|
||||
@ -62,8 +62,7 @@ namespace Wox.Plugin.Program
|
||||
{
|
||||
var scores = new List<string> { program.Title, program.PinyinTitle, program.AbbrTitle, program.ExecuteName };
|
||||
program.Score = scores.Select(s => matcher.Evaluate(s ?? string.Empty).Score).Max();
|
||||
if (program.Score > 0) return true;
|
||||
else return false;
|
||||
return program.Score > 0;
|
||||
}
|
||||
|
||||
public void Init(PluginInitContext context)
|
||||
|
@ -48,8 +48,7 @@ namespace Wox.Plugin
|
||||
if (r != null)
|
||||
{
|
||||
var equality = string.Equals(r.Title, Title) &&
|
||||
string.Equals(r.SubTitle, SubTitle) &&
|
||||
r.Score == Score;
|
||||
string.Equals(r.SubTitle, SubTitle);
|
||||
return equality;
|
||||
}
|
||||
else
|
||||
@ -61,8 +60,7 @@ namespace Wox.Plugin
|
||||
public override int GetHashCode()
|
||||
{
|
||||
var hashcode = (Title?.GetHashCode() ?? 0) ^
|
||||
(SubTitle?.GetHashCode() ?? 0) ^
|
||||
(Score.GetHashCode());
|
||||
(SubTitle?.GetHashCode() ?? 0) ;
|
||||
return hashcode;
|
||||
}
|
||||
|
||||
|
@ -58,16 +58,19 @@ namespace Wox
|
||||
|
||||
public void AddResults(List<Result> newResults, string resultId)
|
||||
{
|
||||
// todo check count in the previous call
|
||||
if (newResults.Count == 0) return;
|
||||
lock (_resultsUpdateLock)
|
||||
{
|
||||
var resultCopy = _results.ToList();
|
||||
var oldResults = resultCopy.Where(r => r.PluginID == resultId).ToList();
|
||||
// todo use async to do new result calculation
|
||||
var resultsCopy = _results.ToList();
|
||||
var oldResults = resultsCopy.Where(r => r.PluginID == resultId).ToList();
|
||||
// intersection of A (old results) and B (new newResults)
|
||||
var intersection = oldResults.Intersect(newResults).ToList();
|
||||
// remove result of relative complement of B in A
|
||||
foreach (var result in oldResults.Except(intersection))
|
||||
{
|
||||
resultCopy.Remove(result);
|
||||
resultsCopy.Remove(result);
|
||||
}
|
||||
|
||||
// update scores
|
||||
@ -80,31 +83,31 @@ namespace Wox
|
||||
}
|
||||
|
||||
// update index for result in intersection of A and B
|
||||
foreach (var result in intersection)
|
||||
foreach (var commonResult in intersection)
|
||||
{
|
||||
int oldIndex = resultCopy.IndexOf(result);
|
||||
int oldScore = resultCopy[oldIndex].Score;
|
||||
if (result.Score != oldScore)
|
||||
int oldIndex = resultsCopy.IndexOf(commonResult);
|
||||
int oldScore = resultsCopy[oldIndex].Score;
|
||||
int newScore = newResults[newResults.IndexOf(commonResult)].Score;
|
||||
if (newScore != oldScore)
|
||||
{
|
||||
int newIndex = InsertIndexOf(result.Score, resultCopy);
|
||||
if (newIndex != oldIndex)
|
||||
{
|
||||
var item = resultCopy[oldIndex];
|
||||
resultCopy.RemoveAt(oldIndex);
|
||||
resultCopy.Insert(newIndex, item);
|
||||
}
|
||||
var oldResult = resultsCopy[oldIndex];
|
||||
oldResult.Score = newScore;
|
||||
resultsCopy.RemoveAt(oldIndex);
|
||||
int newIndex = InsertIndexOf(newScore, resultsCopy);
|
||||
resultsCopy.Insert(newIndex, oldResult);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// insert result in relative complement of A in B
|
||||
foreach (var result in newResults.Except(intersection))
|
||||
{
|
||||
int newIndex = InsertIndexOf(result.Score, resultCopy);
|
||||
resultCopy.Insert(newIndex, result);
|
||||
int newIndex = InsertIndexOf(result.Score, resultsCopy);
|
||||
resultsCopy.Insert(newIndex, result);
|
||||
}
|
||||
|
||||
// update UI in one run, so it can avoid UI flickering
|
||||
_results.Update(resultCopy);
|
||||
_results.Update(resultsCopy);
|
||||
|
||||
lbResults.Margin = lbResults.Items.Count > 0 ? new Thickness { Top = 8 } : new Thickness { Top = 0 };
|
||||
SelectFirst();
|
||||
|
Loading…
Reference in New Issue
Block a user