Toggle the fold under the right-click, not at the caret - #3814
Merged
Conversation
The "Toggle folding" context-menu entry folded the block at the caret, so right-clicking a fold on a different line than the caret toggled the wrong block. Record the document offset under the pointer when the text-view menu opens and expose it on TextViewContext as TextLocation; the folding entry acts on that offset (falling back to the caret only when no click position was recorded). The pointer handler now records the offset before the reference lookup, so a document with foldings but no clickable references still gets a position. Assisted-by: Claude:claude-opus-4-8:Claude Code
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 decompiled-view "Toggle folding" context-menu entry folded the block at the caret, so right-clicking a fold on a different line than the caret toggled the wrong block.
Fix
Record the document offset under the pointer when the text-view menu opens and expose it on
TextViewContextasTextLocation; the folding entry acts on that offset, falling back to the caret only when no click position was recorded (the keyboardCtrl+Mpath).ToggleFoldingAtCaret()is now a thin wrapper over a positionalToggleFoldingAt(int offset).The pointer handler now records the offset before the reference lookup, which also fixes a latent bug: a document with foldings but no clickable references previously recorded no position at all.
Test
New headless
Toggle_Folding_Entry_Acts_On_The_Right_Clicked_Line_Not_The_Caretparks the caret at offset 0, right-clicks a collapsed method fold elsewhere, and asserts that fold expands while an unrelated fold stays collapsed (verified red before the fix, green after). FullILSpy.Testssuite passes (884).This PR was prepared with the assistance of an AI agent.