Repository navigation
fix(rectangle): snap a dragged corner after applyOptions - #1761
Merged
Merged
Conversation
applyOptions re-bound _handleSnapping with off/on, which moved it behind the corner drag handlers, so the rectangle followed the unsnapped pointer after setGlobalOptions, applyOptions, a snappable toggle or a pinning toggle. Unbind the corner handlers first and bind them after snapping. Amp-Thread-ID: https://ampcode.com/threads/T-4f0176da-b9a1-4ad0-aeca-c1780876e0eb
An unstable_cornerDragHandlers override may return new functions on each call, so applyOptions unbinds what _addMarkerEvents stored instead of a fresh call's result. Amp-Thread-ID: https://ampcode.com/threads/T-4f0176da-b9a1-4ad0-aeca-c1780876e0eb
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.
Fixes the rectangle corner snap in edit mode. After
map.pm.setGlobalOptions(...),layer.pm.applyOptions(), asnappabletoggle or a pinning toggle, a dragged corner marker snapped but the rectangle's corner stayed at the pointer.Cause (confirmed):
EditRectangle.applyOptions()calls_initSnappableMarkers(). That reaches_assignEvents, which doesmarker.off('drag', _handleSnapping)thenmarker.on('drag', _handleSnapping), moving_handleSnappingto the end of each corner'sdraglisteners. The corner handlers (_onMarkerDragand the rest) were bound before it, and_addMarkerEvents()'s secondonis a no-op because Leaflet skips a duplicate listener. So_onMarkerDragresized the rectangle from the unsnapped position, and only then did_handleSnappingmove the marker.setOptionsand a secondenable()don't hit it, becauseenable()rebuilds the markers beforeapplyOptions(). The veto reset in_onMarkerDragEnd(_initMarkers()thenapplyOptions()) doesn't hit it either, since its markers are new. Polygon and Line bind no handlers inapplyOptions.Fix:
_addMarkerEvents()keeps the handlers it bound in_boundCornerHandlers.applyOptions()first unbinds those from the corners (not a freshunstable_cornerDragHandlers()result, since an override may return new functions on each call), then applies snapping, then_addMarkerEvents()binds them after_handleSnapping. The markers are kept rather than rebuilt (unlike Pro 2.x's #65), so marker identity and a drag in progress are unaffected. No exports or private member names change.Tests: a new
Edit Rectangle corner snappingblock incypress/e2e/rectangle.cy.ts. A corner at (300, 300) is dragged to about 4 px from a triangle vertex, and the test asserts that the rectangle's ring corner equals the target and that a corner marker sits there.setGlobalOptions({ continueDrawing: true }),applyOptions(),snappableoff and on,pinningon and off;setOptions, a secondenable();_initMarkers()thenapplyOptions()), then a snapping drag;applyOptions()twice: its drag handler runs once per move and sees the snapped marker (on 90f6729 it ran 6 times for 2 moves);setGlobalOptionsand anapplyOptions, a two-move drag firespm:markerdragtwice andpm:snaponce.On
774ddcc(unchanged) the 4 triggers and the listener-count test fail, with the corner at the pointer (expected 51.49869827721546 to be close to 51.498377681772325). The controls and the veto path pass. With the fix, all 9 pass.Checks: build, typecheck, lint, unit 106/106. Full e2e (Electron): base 486/486 (774ddcc), PR 496/496 (+10).
Review (landing owner and Opus 5.5) at 90f6729: one requested change, unbinding the handlers actually bound; done in the next commit.