Fix CaretBrush setter logic in theme styles

Fixed the logic for setting the CaretBrush property in styles to only add the setter if it does not already exist and a Foreground value is present. This removes unnecessary checks and setter removals, making the code more efficient and easier to maintain.
This commit is contained in:
Jack251970 2026-03-03 16:31:27 +08:00
parent 1dcaf3d359
commit f5b8a87de4

View file

@ -218,15 +218,11 @@ namespace Flow.Launcher.Core.Resource
style.Setters.Add(new Setter(Control.FontStretchProperty, fontStretch));
// Set caret brush (retain existing logic)
var caretBrushPropertySetters = style.Setters.OfType<Setter>().Where(x => x.Property == TextBoxBase.CaretBrushProperty).ToList();
var caretBrushPropertyExist = style.Setters.OfType<Setter>().Any(x => x.Property == TextBoxBase.CaretBrushProperty);
var foregroundPropertyValue = style.Setters.OfType<Setter>().Where(x => x.Property == Control.ForegroundProperty)
.Select(x => x.Value).FirstOrDefault();
if (caretBrushPropertySetters.Count > 0 && foregroundPropertyValue != null)
if (!caretBrushPropertyExist && foregroundPropertyValue != null)
{
foreach (var setter in caretBrushPropertySetters)
{
style.Setters.Remove(setter);
}
style.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue));
}
}