fix: Simplify list and text WHERE validation #8575
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The basics
The details
Resolves
Fixes #8556
Proposed Changes
I modified the following block type definitions:
lists_getIndex
lists_setIndex
lists_getSublist
text_getSubstring
Each of these had an input called
AT
with an attached field calledWHERE
. The input and its attached field were sometimes removed and recreated in response to the field's validator. This PR instead attaches the field to a separate dummy input, such that the field does not need to be recreated every time the input is recreated.Reason for Changes
Edits to the field did not always fire a BlockChange event. In particular, if the user is trying to change the field's value to its default value, but the field gets recreated, then the recreated field will already have the default value and thus no change is detected.
Test Coverage
All existing tests pass. Manual testing confirms that BlockChange events are fired as expected.
Additional Information
I can't prove that nobody is depending on the specific hierarchy of inputs and fields in these blocks, although I preserved the existing names of the inputs and fields. I also added new names for new dummy inputs in some cases (so that other inputs could be moved adjacent to them). Should this be considered a breaking change?
Also, there's a bug when undoing/redoing edits to the
WHERE
field while a child block is already attached to theAT
input. Changing the field's value can replace theAT
input with a dummy input, which forcibly detaches the child block, but this is not properly recorded in undo history. In particular, if you edited the field and then made additional changes, then undid all those changes and tried to redo them, the additional changes are lost. A similar bug existed before this PR, but I don't think this PR makes the bug any worse, and I suspect this PR is a prerequisite to properly fixing the bug. Possibly related to: #7950