Fix: restore token highlighting in Quick Add field (regression)
A fast-path early-return added in the voice-binding fix
(`if tv.textColor == .label && tv.text == text && editing { return }`) skipped
rebuilding the attributed text while editing — so token highlights never
reapplied as the parser updated highlightRanges on each keystroke. Removed it so
highlights always render. Also switched the highlight tint from systemBlue to the
app accent (orange) to match the established design.
Verified on simulator: "Remind me to pray everyday" → "Remind me to" + "everyday"
highlighted in accent orange; chips Today / Daily.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1778,18 +1778,18 @@ struct NLTaskField: UIViewRepresentable {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Avoid clobbering the live UITextView (and the cursor) when the displayed
|
// Always rebuild the attributed text so token highlights stay live as the
|
||||||
// text already matches the binding.
|
// parser updates highlightRanges on each keystroke. (A fast-path early-return
|
||||||
if tv.textColor == .label && tv.text == text && editing { return }
|
// here previously suppressed highlighting while editing.)
|
||||||
|
|
||||||
let sel = tv.selectedRange
|
let sel = tv.selectedRange
|
||||||
let attr = NSMutableAttributedString(string: text)
|
let attr = NSMutableAttributedString(string: text)
|
||||||
let full = NSRange(location: 0, length: attr.length)
|
let full = NSRange(location: 0, length: attr.length)
|
||||||
attr.addAttributes([.font: UIFont.systemFont(ofSize: 18), .foregroundColor: UIColor.label], range: full)
|
attr.addAttributes([.font: UIFont.systemFont(ofSize: 18), .foregroundColor: UIColor.label], range: full)
|
||||||
|
let highlight = UIColor(AppColors.accent)
|
||||||
for r in highlightRanges where r.location + r.length <= attr.length {
|
for r in highlightRanges where r.location + r.length <= attr.length {
|
||||||
attr.addAttributes([
|
attr.addAttributes([
|
||||||
.backgroundColor: UIColor.systemBlue.withAlphaComponent(0.13),
|
.backgroundColor: highlight.withAlphaComponent(0.18),
|
||||||
.foregroundColor: UIColor.systemBlue,
|
.foregroundColor: highlight,
|
||||||
], range: r)
|
], range: r)
|
||||||
}
|
}
|
||||||
tv.attributedText = attr
|
tv.attributedText = attr
|
||||||
|
|||||||
Reference in New Issue
Block a user