fix: defer clearSelection after copy to prevent broken subsequent selections#14416
Open
EliasHanken wants to merge 1 commit intoanomalyco:devfrom
Open
fix: defer clearSelection after copy to prevent broken subsequent selections#14416EliasHanken wants to merge 1 commit intoanomalyco:devfrom
EliasHanken wants to merge 1 commit intoanomalyco:devfrom
Conversation
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
…ections When copy-on-select triggers on mouseup, Selection.copy() was calling renderer.clearSelection() synchronously inside the onMouseUp handler. This runs during @OpenTui's processMouseEvent bubbling, BEFORE finishSelection() executes. By nullifying currentSelection prematurely, finishSelection() becomes a no-op and cannot properly set isDragging=false or emit the 'selection' event, leaving internal renderer state stale. This caused subsequent text selection attempts to fail intermittently until the stale state was incidentally cleared (e.g. by a resize). Fix: use queueMicrotask() to defer clearSelection() so that @OpenTui's handleMouseData can complete its full selection lifecycle first.
91f5841 to
b606e3f
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.
Issue for this PR
Fixes #14420
Type of change
What does this PR do?
When copy-on-select triggers on mouseup,
Selection.copy()callsrenderer.clearSelection()synchronously inside theonMouseUphandler. This runs during@opentui'sprocessMouseEventbubbling, beforefinishSelection()gets to execute. NullifyingcurrentSelectionmid-event means the renderer can't finish its selection lifecycle (isDragging=false, emitselectionevent), leaving stale internal state that blocks subsequent text selections.Fix: wrap
clearSelection()inqueueMicrotask()so the renderer'shandleMouseDatacompletes its full pipeline first. The microtask runs before the next mouse event arrives, so cleanup is still prompt.How did you verify your code works?
bun dev .from repo root, rapidly select-and-copy text multiple times -- selections now work consistently on every attemptScreenshots / recordings
Not a UI change -- behavior fix only.
Checklist