Skip to content

fix: preserve dropdown values that are not in the current options list - #3548

Merged
cwillisf merged 1 commit into
developfrom
fix/dropdown-preserve-out-of-options-value
Apr 16, 2026
Merged

fix: preserve dropdown values that are not in the current options list#3548
cwillisf merged 1 commit into
developfrom
fix/dropdown-preserve-out-of-options-value

Conversation

@cwillisf

Copy link
Copy Markdown
Contributor

Resolves

Proposed Changes

Scratch's sprite-targeting menus (motion_goto_menu, motion_pointtowards_menu, sensing_touchingobject_menu, and similar) are populated at runtime from the project's sprite list, with the currently editing sprite deliberately excluded. When a block is copied from another sprite into the sprite it now targets, the stored field value is absent from the option list for that editing context. Blockly's default FieldDropdown validator rejects such values, so the field silently reverts to the first option — the displayed text shows the default even though scratch-vm runs the block against the real stored value.

Override doClassValidation_ so ScratchFieldDropdown accepts any string, and override getText_ so the display falls back to the raw value when no option matches. Matched-option cases still delegate to the base, so image and HTMLElement option types render correctly.

Test Coverage

Tests added

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes Scratch sprite-targeting dropdowns so they preserve and display stored values even when those values aren’t present in the current runtime-generated options list (e.g., when the currently edited sprite is excluded).

Changes:

  • Override ScratchFieldDropdown.doClassValidation_ to accept any string value (even if not in current options).
  • Override ScratchFieldDropdown.getText_ to display the raw stored value when no option matches.
  • Add browser regression tests covering out-of-options persistence/display and in-options “happy path” rendering.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/fields/scratch_field_dropdown.ts Relaxes dropdown validation and adds fallback display behavior for unmatched stored values.
tests/browser/scratch_field_dropdown.test.ts Adds browser-level regression coverage for preserving/displaying values absent from the current option list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/browser/scratch_field_dropdown.test.ts
@rosics-code

Copy link
Copy Markdown

@cwillisf
IMG_6157
Values in dropdown menus look really bad right now.

@cwillisf

Copy link
Copy Markdown
Contributor Author

Values in dropdown menus look really bad right now.

...oof. Yep, that's pretty bad! :(

Looks like that overlaps with the last item over here: scratchfoundation/scratch-editor#533

I'm focusing on functionality and data loss issues first; I might not be able to get to cosmetic issues like that one until next week. Sorry!

@cwillisf
cwillisf force-pushed the fix/dropdown-preserve-out-of-options-value branch from 3e6771a to 33a2d8c Compare April 16, 2026 20:40
@cwillisf
cwillisf requested a review from Copilot April 16, 2026 20:40
@rosics-code

rosics-code commented Apr 16, 2026

Copy link
Copy Markdown

I'm focusing on functionality and data loss issues first; I might not be able to get to cosmetic issues like that one until next week. Sorry!

@cwillisf
Unreleased to this sorry but when you do get to looks next week, I think comments should be colored to each block category when adding a comment to a block.

And for functionality maybe double click a comment to jump to a block? And maybe on the note of drop downs right now, when you right click a variable, you can switch it so maybe you can switch like a looks reporter or switch a block with the right click!

I like this update, just buggy.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/fields/scratch_field_dropdown.ts
Scratch's sprite-targeting menus (motion_goto_menu,
motion_pointtowards_menu, sensing_touchingobject_menu, and similar) are
populated at runtime from the project's sprite list, with the currently
editing sprite deliberately excluded. When a block is copied from another
sprite into the sprite it now targets, the stored field value is absent
from the option list for that editing context. Blockly's default
FieldDropdown validator rejects such values, so the field silently
reverts to the first option — the displayed text shows the default even
though scratch-vm runs the block against the real stored value.

Override doClassValidation_ so ScratchFieldDropdown accepts any string,
and override getText_ so the display falls back to the raw value when
no option matches. Matched-option cases still delegate to the base so
image and HTMLElement option types render correctly.

Fixes https://scratch.mit.edu/discuss/topic/878311/
@redspacecat

Copy link
Copy Markdown

I'm focusing on functionality and data loss issues first; I might not be able to get to cosmetic issues like that one until next week. Sorry!

Are you the only dev working on this? 😬

@rosics-code

Copy link
Copy Markdown

I'm focusing on functionality and data loss issues first; I might not be able to get to cosmetic issues like that one until next week. Sorry!

Are you the only dev working on this? 😬

I’ve noticed there is different devs for each respiratory like WWW, GUI, Blocks

@rosics-code

Copy link
Copy Markdown

I'm focusing on functionality and data loss issues first; I might not be able to get to cosmetic issues like that one until next week. Sorry!

I would make a PR to fix it but I have no idea if this repo uses CSS (Im not a very big person in JS and TS..)

@cwillisf

Copy link
Copy Markdown
Contributor Author

We tend to divide work by topic rather than repository. Some topics tend to be mostly in one repository, while other topics span across multiple repositories.

@rosics-code

Copy link
Copy Markdown

We tend to divide work by topic rather than repository. Some topics tend to be mostly in one repository, while other topics span across multiple repositories.

Oh? That's interesting work flow.

@cwillisf
cwillisf force-pushed the fix/dropdown-preserve-out-of-options-value branch from 33a2d8c to 5314b87 Compare April 16, 2026 20:55
@cwillisf
cwillisf requested a review from Copilot April 16, 2026 20:55
@rosics-code

Copy link
Copy Markdown

So what would this do if I can ask.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/fields/scratch_field_dropdown.ts
@cwillisf

Copy link
Copy Markdown
Contributor Author

So what would this do if I can ask.

This avoids dropdown menus being reset when you drag a block from one sprite to another. It's "light" data loss, but it's still data loss.

@cwillisf
cwillisf merged commit 5c70a47 into develop Apr 16, 2026
8 checks passed
@cwillisf
cwillisf deleted the fix/dropdown-preserve-out-of-options-value branch April 16, 2026 21:06
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants