Skip to content

fix: clear previous provider highlight on new selection#60

Open
Pavankumar07s wants to merge 1 commit intomofa-org:mainfrom
Pavankumar07s:fix-provider-selection-highlight
Open

fix: clear previous provider highlight on new selection#60
Pavankumar07s wants to merge 1 commit intomofa-org:mainfrom
Pavankumar07s:fix-provider-selection-highlight

Conversation

@Pavankumar07s
Copy link
Copy Markdown

📋 Summary

Fix the "sticky highlights" bug in the providers panel where clicking multiple provider items (e.g., OpenAI → DeepSeek → NVIDIA) accumulated highlight states instead of showing only the currently selected provider. The root cause was that select_provider_internal() and update_dark_mode() were not setting the shader's instance selected variable, which the ProviderItem pixel shader reads to render the selected background color. This PR adds selected: 0.0 / selected: 1.0 to the relevant apply_over() calls, ensuring only one provider is visually highlighted at a time.

🔗 Related Issues

Closes #58

Related to #58


🧠 Context

The ProviderItem widget uses a custom Makepad shader with instance selected, instance hover, and instance dark_mode variables. The shader's pixel() function computes the background color from these instance variables:

fn pixel(self) -> vec4 {
    let base = mix(normal, hover_color, self.hover);
    return mix(base, selected_color, self.selected);
}

However, select_provider_internal() was only setting draw_bg: { color: (...) } — a property the shader never reads. This meant the shader's selected instance variable was never cleared on previously-selected items, causing all clicked items to stay highlighted. Custom provider items were already correctly using selected: 0.0/1.0, so only the four built-in providers (OpenAI, DeepSeek, Alibaba Cloud, NVIDIA) were affected.

🛠️ Changes

-Added selected: 0.0, hover: 0.0 to the reset loop in select_provider_internal() so all built-in items have their shader state cleared before the new selection
-Added selected: 1.0 to each built-in provider's selection branch so the shader renders the selected background
-Added selected: (selected_val) to the update_dark_mode() loop so dark mode toggling preserves correct selection state
-Added 3 unit tests for the ProvidersPanelAction enum (follows existing #[cfg(test)] module pattern)


🧪 How you Tested

  1. cargo check -p mofa-settings — compiles with no new warnings
  2. cargo test -p mofa-settings — 27 tests pass, 0 failures
  3. cargo clippy -p mofa-settings — no new warnings (all pre-existing)
  4. Manual testing: cargo run --bin mofa-studio → Settings → Providers panel:
    Click OpenAI → only OpenAI highlights
    Click DeepSeek → only DeepSeek highlights, OpenAI clears
    Click NVIDIA → only NVIDIA highlights, DeepSeek clears
    Toggle dark mode → selected provider stays correctly highlighted

📸 Screenshots / Logs (if applicable)

Screencast.From.2026-03-05.00-25-45.webm

⚠️ Breaking Changes

  • No breaking changes
  • Breaking change (describe below)

If breaking:


🧹 Checklist

Code Quality

  • Code follows Rust idioms and project conventions
  • cargo fmt run
  • cargo clippy passes without warnings

Testing

  • Tests added/updated
  • cargo test passes locally without any error

Documentation

  • Public APIs documented
  • README / docs updated (if needed)

PR Hygiene

  • PR is small and focused (one logical change)
  • Branch is up to date with main
  • No unrelated commits
  • Commit messages explain why, not only what

🚀 Deployment Notes (if applicable)

No migrations, config changes, or environment variable changes required. Drop-in fix.


🧩 Additional Notes for Reviewers

The fix preserves all existing color logic (color: (normal_color) / color: (selected_color)) exactly as-is. The only additions are the selected and hover instance variables in the same apply_over() calls, which the shader's pixel() function actually reads. This is the minimal change needed to fix the glitch without altering any design decisions around colors or theming.

@Pavankumar07s
Copy link
Copy Markdown
Author

@BH3GEI please take a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[UI Bug] Provider selection in Settings does not clear previous highlight

1 participant