Repository navigation
fix: always complete mouse presses and handle in-progress selections on render - #2951
Merged
Merged
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.
Note
AI-authored disclosure (
alphatab-ai-authored-v1)Portions of this content were authored by an AI agent. The agent has read
AGENTS.md and the human submitter accepts responsibility for
compliance with the rules in that document.
Issues
Fixes #2949
Proposed changes
The TypeError in #2949 is a symptom. Two separate defects cause it, so guarding
_selectionEndat the crash site is not enough.1. Platform layer: a press could start and never end.
No
IContainerimplementation guaranteed that a press started on the control ends with amouseUp:mouseupwas only observed on the element itself, so a release outside the surface was lost.MouseUp.ACTION_CANCELwas ignored.The API then kept
_isBeatMouseDown = trueindefinitely. Besides the crash, this disabled auto-scroll during playback (shouldScroll && !this._isBeatMouseDown) and made plain hovering over beats extend the selection.IContainer.mouseUp/mouseMovenow document the contract: every press started on the control ends with exactly onemouseUp, and moves during an active press are reported even outside the control. Each platform implements it:HtmlElementContainer):mousemove/mouseupare observed on the owner document.(buttons & 1) === 0ends a press whose release was never observed, e.g. one released outside the window.MouseUp, andLostMouseCaptureduring a press raisesMouseUp.MouseCaptureChangedduring a press raisesMouseUp. This is deferred, so a regular release does not report twice.ACTION_CANCELis handled likeACTION_UP, andactionMaskedis used.Native listeners are attached on first subscription.
offon the mouse emitters now works; before, it did nothing.2. Core: the selection was redrawn twice after a render, and one of the two paths was wrong.
_setupClickHandlingreused cachedSelectionInfo.boundsfrom the previous layout._onPostRenderFinished(added in fix: update selection highlight on re-render #2646) assumed_selectionEndis always set.A start without an end is a legitimate state: the button is still held on one beat, or the user clicked with
resetPlaybackRangeOnClick = false. That last case crashed on the next render even with perfect mouse handling.Both paths are replaced by one
_refreshSelectionHighlight()that:Highlights set through
highlightPlaybackRangewithout range selection are still redrawn after a re-render (#2646).In addition, a new press resets the beat and note press state left over from the previous one. The
mouseUppath clears it in afinally, so a throwingbeatMouseUplistener can no longer leave the press active.Checklist
New tests are in
test/AlphaTabApiMouse.test.ts: render during a held press, render after a click without range reset, rebuilt bounds after re-render, API highlight without range selection, and a release outside beats ending the press. They pass on TypeScript, C# and Kotlin. Without the core change, the first three fail with the TypeError from the issue.AI authorship disclosure
(
alphatab-ai-authored-v1) is present at the top of this body, and I havepersonally reviewed every change and can explain each one
Further details