fix: Use dominant axis for keyboard move direction#10030
Open
microbit-robert wants to merge 1 commit into
Open
fix: Use dominant axis for keyboard move direction#10030microbit-robert wants to merge 1 commit into
microbit-robert wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
In keyboard move mode, getDirectionToNewLocation decided the move direction by testing the horizontal delta before the vertical one and treating any non-zero x as a sideways move. The move delta is round-tripped through pixels (KeyboardMover scales up by the workspace scale, Dragger scales back down), and at any zoom other than 100% that conversion leaves ~1e-14 of floating-point residue on the axis that should be exactly zero. In real terms,
xcould be 0.0...01 andycould be ~20, but because we checkedxfirst, it was interpreted as a horizontal move rather than vertical. At a scale of 1, the conversions are exact, so there is no floating point result.Fixes #10029
Proposed Changes
Choose the axis with the larger absolute delta instead, so the genuine movement always wins and sub-pixel rounding noise can't flip the direction. Behaviour at scale 1 is unchanged.
Reason for Changes
This addresses unexpected keyboard move behaviour raised in #10029
Test Coverage
This could do with a test case or two, but it's not straight forward to reproduce so would need quite a complicated test setup
Documentation
N/A
Additional Information
Behaviour after change:
https://github.com/user-attachments/assets/e3a12b98-5651-4f4a-9bd1-7f727fcb078b