Support mo.ui.matplotlib selections from code mode#9195
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
mo.ui.matplotlib selections set from Python (code mode)mo.ui.matplotlib selections from code mode
There was a problem hiding this comment.
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(), detectvaluechanges 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.
| // 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; | ||
| } |
There was a problem hiding this comment.
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.
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 inupdate()that restores the selection when the user isn't actively interacting with the canvas.