Skip to content

Support mo.ui.matplotlib selections from code mode#9195

Merged
manzt merged 2 commits intomainfrom
push-tyrmmozvnwpq
Apr 15, 2026
Merged

Support mo.ui.matplotlib selections from code mode#9195
manzt merged 2 commits intomainfrom
push-tyrmmozvnwpq

Conversation

@manzt
Copy link
Copy Markdown
Collaborator

@manzt manzt commented Apr 14, 2026

Selections set via the kernel (e.g. through ctx.set_ui_value()) were invisible because #restoreSelection() was only called at init, never on subsequent value updates. Adds a guarded value-change check in update() that restores the selection when the user isn't actively interacting with the canvas.

Selections set via the kernel (e.g. through `ctx.set_ui_value()`) were
invisible because `#restoreSelection()` was only called at init, never
on subsequent value updates. Adds a guarded value-change check in
`update()` that restores the selection when the user isn't actively
interacting with the canvas.
Copilot AI review requested due to automatic review settings April 14, 2026 20:10
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 14, 2026 8:18pm

Request Review

@manzt manzt changed the title Support mo.ui.matplotlib selections set from Python (code mode) Support mo.ui.matplotlib selections from code mode Apr 14, 2026
@manzt manzt added the bug Something isn't working label Apr 14, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes mo.ui.matplotlib selection overlays not reflecting selection values set from Python/kernel updates by re-applying (#restoreSelection) when the plugin value changes, while avoiding overwriting active pointer interactions.

Changes:

  • In MatplotlibRenderer.update(), detect value changes and call #restoreSelection() when the user is not actively interacting.
  • In #restoreSelection(), ensure clearing a selection (has_selection: false) resets interaction state and triggers a redraw.

Comment on lines +383 to +393
// Restore selection from backend when the value changed and the user
// is not actively drawing/dragging/resizing. During active interactions
// the renderer owns the interaction state — overwriting it would fight
// the user's pointer.
const isUserInteracting =
this.#interaction.type !== "idle" && this.#interaction.action !== null;
if (state.value !== prev.value && !isUserInteracting) {
this.#restoreSelection(state.value);
// #restoreSelection already schedules a redraw
return;
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new update() behavior (restoring selection when state.value changes and the user isn’t interacting) isn’t covered by tests. Since this plugin already has a Vitest suite, please add coverage for (1) restoring a backend-provided selection into #interaction, (2) ignoring value changes during active pointer actions, and (3) clearing selection when has_selection becomes false.

Copilot uses AI. Check for mistakes.
Comment thread frontend/src/plugins/impl/matplotlib/matplotlib-renderer.ts Outdated
Copy link
Copy Markdown
Member

@kirangadhave kirangadhave left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@manzt manzt merged commit 4b98fe9 into main Apr 15, 2026
29 checks passed
@manzt manzt deleted the push-tyrmmozvnwpq branch April 15, 2026 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants