Repository navigation
feat: add EditLine.unstable_addMarkerFilter - #1758
Merged
Merged
Conversation
…ebuilds A Rectangle, the rotate helper and a never-enabled editor have no marker cache, so a caller's applyLimitFilters threw. On a rebuild the filters got a made-up (0, 0) pointer; they now get undefined. Amp-Thread-ID: https://ampcode.com/threads/T-4f0176da-b9a1-4ad0-aeca-c1780876e0eb
mscno
force-pushed
the
feat/marker-filters
branch
from
November 26, 2026 09:05
02a0940 to
d7c0ccb
Compare
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.
Adds
EditLine.unstable_addMarkerFilter(filter)and the typeUnstableMarkerFilterfrom./unstable(hook 2). Pro uses them to narrow the markers an editor shows, such as markers limited to the viewport. They are for@geoman-iopackages and have no semver guarantee.(pm, markers, latlng) => markers. It runs insideapplyLimitFilters, after Free's closest-count pass (limitMarkersToCount), and gets that pass's markers. Several filters chain in the order they were added.latlngis the call's latlng: a pointer move's, or the caller's. It is undefined when the editor rebuilt its markers (on enable, after a reset or an insert), so a filter can tell a rebuild from a real point at 0, 0.markerCacheholds both. The JSDoc says so._initMarkers→filterMarkerGroup→applyLimitFilters({}). They also apply on every pass Free already runs: the throttledpointermovewhenlimitMarkersToCount> -1, and the rebuild onpm:vertexremoved.clickandmoveendhandlers and callspm.applyLimitFilters({ latlng }). That works withlimitMarkersToCount-1, where Free binds nopointermove:filterMarkerGroupstill buildsmarkerCacheand runs the first pass, and the test calls it directly in that mode.applyLimitFiltersnow returns early when the editor has no marker cache: a Rectangle, which keeps its four corners, the rotate helper, or an editor that was never enabled. Before, only Free called it, throughfilterMarkerGroup, so that case was unreachable. A caller looping over edited layers would have thrown "markerCache is not iterable" at the first rectangle.EditLine, a module-level list), like the toolbar'sunstable_add*hooks. There is no remove; Pro adds its filter once.Tests: new
cypress/e2e/markerFilters.cy.ts, 3 tests:limitMarkersToCount-1: the filter applies on enable with no latlng, a pointer move changes nothing because Free binds nothing, and a directapplyLimitFilters({ latlng })re-applies it with that latlng. On a Rectangle the call doesn't throw, doesn't call the filter, and keeps 4 corners;limitMarkersToCount: 5: the filter gets the 5 closest markers and the pointer latlng in the throttled pointermove pass, and what it drops is hidden;Mutants: not calling the filters fails 2 tests. Passing all of
markerCacheinstead of the closest-count result fails 2. Dropping the no-cache return fails 1, and passing (0, 0) on rebuilds fails 1.test/types/unstable.mtsadds anUnstableMarkerFilterthroughEditLine.unstable_addMarkerFilter.Timings, with nothing registered: a 2000-vertex polygon, enable time, then 300 direct
applyLimitFilterscalls at moving latlngs. Electron/Chromium headless, base 0a3186c against head d7c0ccb. Each page records which build it loaded (head hasunstable_addMarkerFilter). 12 alternating rounds per batch; paired is the median of head/base − 1 per round.limitMarkersToCount: 20, batch 1limitMarkersToCount: 20, batch 2limitMarkersToCount: -1That is noise. Batch 1's enable median comes from slow outlier runs: its 12 head enables span 35–92 ms and base's 33–126 ms, and batch 2 shows no difference. One enable is a single cold measurement. A pass costs about 6 ms with a limit, almost all of it Free's distance sort of 4000 markers, and 0.8 ms at -1; the change adds one check and one empty loop. Earlier batches on the pre-rebase head against 807c4f6 gave +2.3% and +0.7% for passes.
Checks: build, typecheck, lint, unit 103/103. Full e2e (Electron): base 483/483 (0a3186c), PR 486/486 (+3).
Independent review (Opus 5.5) at 02a0940: one Medium (the throw on editors without a cache) and one Low (the made-up (0, 0) on rebuilds). Both are fixed in d7c0ccb, which is rebased onto 0a3186c (#1757).