Skip to content

Toggle the fold under the right-click, not at the caret - #3814

Merged
siegfriedpammer merged 1 commit into
masterfrom
fix-folding-context-menu-uses-caret
Jun 24, 2026
Merged

Toggle the fold under the right-click, not at the caret#3814
siegfriedpammer merged 1 commit into
masterfrom
fix-folding-context-menu-uses-caret

Conversation

@siegfriedpammer

Copy link
Copy Markdown
Member

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 TextViewContext as TextLocation; the folding entry acts on that offset, falling back to the caret only when no click position was recorded (the keyboard Ctrl+M path). ToggleFoldingAtCaret() is now a thin wrapper over a positional ToggleFoldingAt(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_Caret parks 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). Full ILSpy.Tests suite passes (884).

This PR was prepared with the assistance of an AI agent.

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
@siegfriedpammer
siegfriedpammer merged commit be3044d into master Jun 24, 2026
13 checks passed
@siegfriedpammer
siegfriedpammer deleted the fix-folding-context-menu-uses-caret branch June 27, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant