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