From f5e81fe8cd2e8b47ae4fe84f26ba4c48972ca468 Mon Sep 17 00:00:00 2001 From: lwouis Date: Mon, 23 Feb 2026 15:31:24 +0100 Subject: [PATCH] fix: fade-out speed could show wrong value in rare cases --- src/ui/settings-window/SettingsWindow.swift | 25 ++++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/ui/settings-window/SettingsWindow.swift b/src/ui/settings-window/SettingsWindow.swift index 2a228527..d7d77710 100644 --- a/src/ui/settings-window/SettingsWindow.swift +++ b/src/ui/settings-window/SettingsWindow.swift @@ -854,22 +854,35 @@ class SettingsWindow: NSWindow { } private func highlightTarget(_ textField: NSTextField) -> SettingsSearchHighlightTarget? { - let text = textField.stringValue - guard !text.isEmpty else { return nil } - let baseAttributedString = textField.attributedStringValue + guard !textField.stringValue.isEmpty else { return nil } + var baseAttributedString: NSAttributedString? + var highlightedText = "" + var isHighlighted = false return SettingsSearchHighlightTarget({ query in - SettingsSearch.match(query, in: text)?.ranges ?? [] + SettingsSearch.match(query, in: textField.stringValue)?.ranges ?? [] }, { ranges in - let mutable = NSMutableAttributedString(attributedString: baseAttributedString) + let text = textField.stringValue + if !isHighlighted || highlightedText != text { + baseAttributedString = textField.attributedStringValue + highlightedText = text + } + let mutable = NSMutableAttributedString(attributedString: baseAttributedString ?? textField.attributedStringValue) let nsRanges = ranges.compactMap { SettingsWindow.characterRangeToNSRange($0, in: text) } nsRanges.forEach { mutable.addAttribute(.foregroundColor, value: Appearance.searchMatchForegroundColor, range: $0) } textField.attributedStringValue = mutable SettingsWindow.applyRoundedHighlights(to: textField, attributedString: mutable, ranges: nsRanges) + isHighlighted = true }, { - textField.attributedStringValue = baseAttributedString + guard isHighlighted else { return } + if let baseAttributedString { + textField.attributedStringValue = baseAttributedString + } SettingsWindow.clearRoundedHighlights(from: textField) + baseAttributedString = nil + highlightedText = "" + isHighlighted = false }) }