From f5b8a87de490c26fe2ebf9b4e6b4d093a747129a Mon Sep 17 00:00:00 2001 From: Jack251970 <1160210343@qq.com> Date: Tue, 3 Mar 2026 16:31:27 +0800 Subject: [PATCH] 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. --- Flow.Launcher.Core/Resource/Theme.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher.Core/Resource/Theme.cs b/Flow.Launcher.Core/Resource/Theme.cs index 3d1e89a11..7e9c3bf11 100644 --- a/Flow.Launcher.Core/Resource/Theme.cs +++ b/Flow.Launcher.Core/Resource/Theme.cs @@ -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().Where(x => x.Property == TextBoxBase.CaretBrushProperty).ToList(); + var caretBrushPropertyExist = style.Setters.OfType().Any(x => x.Property == TextBoxBase.CaretBrushProperty); var foregroundPropertyValue = style.Setters.OfType().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)); } }