mirror of
https://github.com/awizemann/scarf.git
synced 2026-05-10 10:36:35 +00:00
a41c81c048
Typing in the chat composer became unusably laggy because `updateMenuState()` ran on every keystroke and unconditionally wrote both `showMenu` and `selectedIndex`. Two state writes inside one `onChange(of: text)` handler tripped SwiftUI's "action tried to update multiple times per frame" warning, and each redundant write forced a full body re-eval — visible as the slow-HID stalls and the main-thread layout churn the reporter captured in sampling. Two changes: - Compute the new selection up front and write only the deltas. Same semantics; no spurious mutations. - Short-circuit the whole handler when the user is composing normal text (no `/` prefix) and the menu is already hidden — the common case. Stops paying for `SlashCommandMenu.filter` on every keystroke of regular prose. - Replace `.onChange(of: commands.map(\.id))` with `.onChange(of: commands.count)`. The mapped form allocated a fresh `[String]` on every body re-eval; counting is one int read. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>